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
April 2014
- 5 participants
- 162 discussions
Jenkins build is back to normal : wao-nightly » Wao :: Web #25
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
04 Apr '14
Jenkins build is back to normal : wao-nightly » Wao :: Persistence #25
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
04 Apr '14
Jenkins build is back to normal : wao-nightly » Wao :: Services #25
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
04 Apr '14
Jenkins build is back to normal : wao-nightly » Wao #25
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
by admin+ci-codelutin.com@codelutin.com 04 Apr '14
04 Apr '14
r1838 - in trunk/wao-services/src/main: java/fr/ifremer/wao/services/service java/fr/ifremer/wao/services/service/administration java/fr/ifremer/wao/services/service/csv java/fr/ifremer/wao/services/service/csv/operations resources/i18n
by tchemit@users.forge.codelutin.com 04 Apr '14
by tchemit@users.forge.codelutin.com 04 Apr '14
04 Apr '14
Author: tchemit
Date: 2014-04-04 18:15:57 +0200 (Fri, 04 Apr 2014)
New Revision: 1838
Url: http://forge.codelutin.com/projects/wao/repository/revisions/1838
Log:
refs #4482 i18n csv import, refs #3387, refs #4483
Modified:
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatGroupImportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatImportExportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactStateMotivesImportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/FishingZoneImportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsDebSamplingPlanImportExportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/RawObsDebCodesImportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialDivisionImportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialLocationImportModel.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatImmatriculationParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/CompanyParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ContactStateMotivesParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DCF5CodesParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/FishingZonesParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LatitudeParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocationTypeParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LongitudeParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ObsDebCodeParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/PortParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionsParser.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowCodeParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UserParserFormatter.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UsersParserFormatter.java
trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties
trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -7,6 +7,7 @@
import org.apache.commons.mail.SimpleEmail;
/**
+ * //TODO remove this and use the {@link fr.ifremer.wao.services.service.mail.EmailService}.
* Created on 4/4/14.
*
* @author Tony Chemit <chemit(a)codelutin.com>
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -122,7 +122,7 @@
List<Boat> sampleRows = dao.findAll(filter);
ExportModel<Boat> exportModel =
- new BoatImportExportModel();
+ new BoatImportExportModel(getLocale());
Export<Boat> export = Export.newExport(exportModel, sampleRows);
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -153,7 +153,8 @@
List<Contact> contacts = dao.findAll(filter);
- ExportModel<Contact> exportModel = ObsMerContactImportExportModel.forExport(filter.getSampleRowFilter().getObsProgram());
+ ExportModel<Contact> exportModel = ObsMerContactImportExportModel.forExport(getLocale(),
+ filter.getSampleRowFilter().getObsProgram());
Export<Contact> export = Export.newExport(exportModel, contacts);
@@ -182,7 +183,8 @@
List<ContactStateMotif> motives = getContactStateMotifDao().findAll();
ImportModel<Contact> contactImportModel =
- ObsMerContactImportExportModel.forImport(obsProgram,
+ ObsMerContactImportExportModel.forImport(getLocale(),
+ obsProgram,
waoUsers,
sampleRows,
boats,
@@ -386,6 +388,7 @@
log.debug("notification will be sent to " + waoUsers.size() + " users");
}
+ //TODO remove this and use the {@link fr.ifremer.wao.services.service.mail.EmailService}.
// sending the same e-mail to all of them
for (WaoUser waoUser : waoUsers) {
String userLogin = waoUser.getLogin();
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -557,8 +557,12 @@
ReferentialService referentialService = getReferentialService();
ImportModel<SampleRow> samplingPlanImportModel =
- new ObsMerObsVenteSamplingPlanImportExportModel(obsProgram,
- activeCompanies, fishingZones, terrestrialDistricts, referentialService);
+ new ObsMerObsVenteSamplingPlanImportExportModel(getLocale(),
+ obsProgram,
+ activeCompanies,
+ fishingZones,
+ terrestrialDistricts,
+ referentialService);
return samplingPlanImportModel;
@@ -578,6 +582,7 @@
ExportModel<SampleRow> exportModel =
new ObsMerObsVenteSamplingPlanImportExportModel(
+ getLocale(),
filter.getPeriodFrom(),
filter.getPeriodTo(),
ObsProgram.OBSMER);
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -188,7 +188,8 @@
*/
public void importFishingZones(InputStream input) throws ImportErrorException {
- FishingZoneImportModel model = new FishingZoneImportModel();
+ FishingZoneImportModel model = new FishingZoneImportModel(getLocale());
+
Import<FishingZone> fishingZoneImport = Import.newImport(model, input);
FishingZoneTopiaDao dao = getPersistenceContext().getFishingZoneDao();
@@ -243,7 +244,7 @@
// if yes, some attribute may have change, so we use a binder to copy all field
// if no, add the new location in database
- ImportModel<TerrestrialLocation> model = new TerrestrialLocationImportModel();
+ ImportModel<TerrestrialLocation> model = new TerrestrialLocationImportModel(getLocale());
Import<TerrestrialLocation> terrestrialLocationImport = Import.newImport(model, input);
// we will need a binder, to copy location for an update
@@ -451,7 +452,7 @@
public void importContactStateMotives(InputStream input) throws ImportErrorException {
- ImportModel<ContactStateMotif> model = new ContactStateMotivesImportModel();
+ ImportModel<ContactStateMotif> model = new ContactStateMotivesImportModel(getLocale());
Import<ContactStateMotif> motivesImport = Import.newImport(model, input);
ContactStateMotifTopiaDao dao = getPersistenceContext().getContactStateMotifDao();
@@ -491,7 +492,7 @@
}
// the import itself
- ImportModel<TerrestrialDivision> importModel = new TerrestrialDivisionImportModel(ports, regions);
+ ImportModel<TerrestrialDivision> importModel = new TerrestrialDivisionImportModel(getLocale(), ports, regions);
Import<TerrestrialDivision> terrestrialDivisionImport = Import.newImport(importModel, input);
TerrestrialDivisionTopiaDao dao = getPersistenceContext().getTerrestrialDivisionDao();
@@ -601,7 +602,7 @@
ObsDebCodeTopiaDao dao = getPersistenceContext().getObsDebCodeDao();
ObsDebCodeDetailsTopiaDao obsDebCodeDetailsDAO = getPersistenceContext().getObsDebCodeDetailsDao();
- ImportModel<RawObsDebCode> model = new RawObsDebCodesImportModel(allRegions);
+ ImportModel<RawObsDebCode> model = new RawObsDebCodesImportModel(getLocale(), allRegions);
Import<RawObsDebCode> rawObsDebCodeImport = Import.newImport(model, input);
// start reading the CSV file line by line
@@ -869,7 +870,7 @@
List<TerrestrialLocation> districts = terrestrialLocationDao.forLocationTypeEquals(LocationType.DISTRICT).findAll();
// Building the model, providing ports
- BoatImportExportModel model = new BoatImportExportModel(ports, districts);
+ BoatImportExportModel model = new BoatImportExportModel(getLocale(), ports, districts);
Import<Boat> boatImport = Import.newImport(model, input);
// Getting some DAOs
@@ -947,7 +948,7 @@
public void importBoatGroups(InputStream input) throws ImportErrorException {
// Building the model, providing ports
- BoatGroupImportModel model = new BoatGroupImportModel();
+ BoatGroupImportModel model = new BoatGroupImportModel(getLocale());
Import<Boat> boatImport = Import.newImport(model, input);
// Getting some DAOs
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatGroupImportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatGroupImportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatGroupImportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -34,17 +34,24 @@
import org.nuiton.csv.ValueGetterSetter;
import java.util.List;
+import java.util.Locale;
public class BoatGroupImportModel implements ImportModel<Boat> {
protected ModelBuilder<Boat> modelBuilder;
+ protected final Locale locale;
+
+ public BoatGroupImportModel(Locale locale) {
+ this.locale = locale;
+ }
+
protected void buildModel() {
modelBuilder = new ModelBuilder<>();
modelBuilder.newColumnForImportExport(
"NAVIRE_IMMATRICULATION",
Boat.PROPERTY_IMMATRICULATION,
- new BoatImmatriculationParserFormatter());
+ new BoatImmatriculationParserFormatter(locale));
// boat group
modelBuilder.newColumnForImportExport(
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatImportExportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatImportExportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatImportExportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -40,6 +40,7 @@
import org.nuiton.csv.ValueGetterSetter;
import java.util.List;
+import java.util.Locale;
/**
*
@@ -49,20 +50,29 @@
protected ModelBuilder<Boat> modelBuilder;
+ protected final Locale locale;
+
protected List<TerrestrialLocation> ports;
protected List<TerrestrialLocation> districts;
- /** Constructor for export. */
- public BoatImportExportModel() {
+ /**
+ * Constructor for export.
+ *
+ * @param locale
+ */
+ public BoatImportExportModel(Locale locale) {
+ this.locale = locale;
}
/**
* Constructor for import.
- *
- * @param ports ports that can be used by boats as port of registry
+ *
+ * @param locale
+ * @param ports ports that can be used by boats as port of registry
*/
- public BoatImportExportModel(List<TerrestrialLocation> ports, List<TerrestrialLocation> districts) {
+ public BoatImportExportModel(Locale locale, List<TerrestrialLocation> ports, List<TerrestrialLocation> districts) {
+ this.locale = locale;
this.ports = ports;
this.districts = districts;
}
@@ -72,7 +82,7 @@
modelBuilder.newColumnForImportExport(
"NAVIRE_IMMATRICULATION",
Boat.PROPERTY_IMMATRICULATION,
- new BoatImmatriculationParserFormatter());
+ new BoatImmatriculationParserFormatter(locale));
modelBuilder.newColumnForImportExport(
"NAVIRE_NOM",
Boat.PROPERTY_NAME);
@@ -131,12 +141,12 @@
// boat district
modelBuilder.newColumnForImportExport("QUARTIER_CODE",
Boat.PROPERTY_DISTRICT,
- new DistrictParserFormatter(districts));
+ new DistrictParserFormatter(locale, districts));
// port of registry
modelBuilder.newColumnForImportExport("PORT_CODE",
Boat.PROPERTY_PORT_OF_REGISTRY,
- new PortParserFormatter(ports, true));
+ new PortParserFormatter(locale, ports, true));
// fleet
modelBuilder.newColumnForImportExport(
@@ -157,7 +167,8 @@
boat.getFleet().setCode(code);
}
}
- });
+ }
+ );
modelBuilder.newColumnForImportExport(
"FLOTILLE_NOM",
@@ -177,7 +188,8 @@
boat.getFleet().setFleetName(name);
}
}
- });
+ }
+ );
modelBuilder.newColumnForImportExport(
"SOUS_FLOTILLE_NOM",
@@ -195,7 +207,8 @@
public void set(Boat boat, String subFleetName) throws Exception {
boat.getFleet().setSubFleetName(subFleetName);
}
- });
+ }
+ );
modelBuilder.newColumnForImportExport(
"SOUS_SOUS_FLOTILLE_NOM",
@@ -214,7 +227,8 @@
public void set(Boat boat, String subSubFleetName) throws Exception {
boat.getFleet().setSubSubFleetName(subSubFleetName);
}
- });
+ }
+ );
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -62,6 +62,7 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
public class ContactImportExportModel implements ImportExportModel<Contact> {
@@ -125,6 +126,8 @@
}
}
+ protected final Locale locale;
+
protected ObsProgram obsProgram;
protected List<WaoUser> waoUsers;
@@ -140,15 +143,17 @@
protected List<ContactStateMotif> motives;
/** for export */
- public ContactImportExportModel(ObsProgram obsProgram) {
+ public ContactImportExportModel(Locale locale, ObsProgram obsProgram) {
+ this.locale = locale;
this.obsProgram = obsProgram;
}
/** for import */
- public ContactImportExportModel(ObsProgram obsProgram, List<WaoUser> waoUsers,
+ public ContactImportExportModel(Locale locale, ObsProgram obsProgram, List<WaoUser> waoUsers,
List<TerrestrialLocation> terrestrialLocations,
List<SampleRow> sampleRows, List<Boat> boats,
List<ObsDebCode> obsDebCodes, List<ContactStateMotif> motives) {
+ this.locale = locale;
this.obsProgram = obsProgram;
this.waoUsers = waoUsers;
this.terrestrialLocations = terrestrialLocations;
@@ -179,8 +184,8 @@
ModelBuilder<Contact> modelBuilder = new ModelBuilder<>();
modelBuilder.newColumnForImportExport("CONTACT_ID", Contact.TOPIA_ID);
modelBuilder.newColumnForImportExport("CONTACT_DATE_CREATION", Contact.PROPERTY_CREATION_DATE, Common.DAY_TIME);
- modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEUR_PRINCIPAL", Contact.PROPERTY_MAIN_OBSERVER, new UserParserFormatter(waoUsers));
- modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(waoUsers));
+ modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEUR_PRINCIPAL", Contact.PROPERTY_MAIN_OBSERVER, new UserParserFormatter(locale, waoUsers));
+ modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(locale, waoUsers));
modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_NOMS");
modelBuilder.newColumnForExport(
"CONTACT_OBSERVATEURS_NOMS",
@@ -194,7 +199,8 @@
}
return StringUtils.join(fullNames, ", ");
}
- });
+ }
+ );
modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_SOCIETE");
modelBuilder.newColumnForExport(
"CONTACT_OBSERVATEURS_SOCIETE",
@@ -204,7 +210,8 @@
return contact.getMainObserver().getCompany();
}
},
- new CompanyParserFormatter(null));
+ new CompanyParserFormatter(locale, null)
+ );
modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new Common.ToStringParserFormatter(ContactState.getAllowedStates(obsProgram)));
modelBuilder.newColumnForImportExport("CONTACT_DEBUT_OBSERVATION", Contact.PROPERTY_OBSERVATION_BEGIN_DATE, Common.DAY_TIME);
modelBuilder.newColumnForImportExport("CONTACT_FIN_OBSERVATION", Contact.PROPERTY_OBSERVATION_END_DATE, Common.DAY_TIME);
@@ -213,7 +220,7 @@
modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_COORDINATEUR", Contact.PROPERTY_COMMENT_COORDINATOR);
modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_PROGRAMME", Contact.PROPERTY_COMMENT_ADMIN);
- modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats));
+ modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats, locale));
modelBuilder.newIgnoredColumn("NAVIRE_NOM");
modelBuilder.newColumnForExport("NAVIRE_NOM", new ValueGetter<Contact, String>() {
@Override
@@ -224,7 +231,7 @@
modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_SOCIETE", Contact.PROPERTY_VALIDATION_COMPANY, Common.BOOLEAN);
modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_PROGRAMME", Contact.PROPERTY_VALIDATION_PROGRAM, Common.BOOLEAN);
- modelBuilder.newColumnForImportExport("PLAN_CODE", Contact.PROPERTY_SAMPLE_ROW, new SampleRowParserFormatter(sampleRows));
+ modelBuilder.newColumnForImportExport("PLAN_CODE", Contact.PROPERTY_SAMPLE_ROW, new SampleRowParserFormatter(locale, sampleRows));
if (obsProgram == ObsProgram.OBSMER) {
modelBuilder.newColumnForImportExport("CONTACT_QUALITE_DONNEE", "dataReliability",
@@ -233,7 +240,7 @@
modelBuilder.newColumnForImportExport("CONTACT_CAPTURE_ACCIDENTELLE", Contact.PROPERTY_MAMMALS_CAPTURE, Common.BOOLEAN);
modelBuilder.newIgnoredColumn("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS");
modelBuilder.newColumnForExport("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS", Contact.PROPERTY_MAMMALS_INFO);
- modelBuilder.newColumnForImportExport("CONTACT_ETAT_MOTIF_CODE", Contact.PROPERTY_CONTACT_STATE_MOTIF, new ContactStateMotivesParserFormatter(motives));
+ modelBuilder.newColumnForImportExport("CONTACT_ETAT_MOTIF_CODE", Contact.PROPERTY_CONTACT_STATE_MOTIF, new ContactStateMotivesParserFormatter(locale, motives));
modelBuilder.newIgnoredColumn("CONTACT_ETAT_MOTIF_NOM");
modelBuilder.newColumnForExport("CONTACT_ETAT_MOTIF_NOM", new ValueGetter<Contact, String>() {
@Override
@@ -252,7 +259,7 @@
// terrestrial location for both ObsVente and ObsDeb
ValueGetterSetter<Contact, LocationType> locationTypeGetter = new Common.ValueSaver<>();
- LocationTypeParserFormatter locationTypeParserFormatter = new LocationTypeParserFormatter();
+ LocationTypeParserFormatter locationTypeParserFormatter = new LocationTypeParserFormatter(locale);
modelBuilder.newMandatoryColumn(
"CONTACT_LIEU_TYPE",
locationTypeParserFormatter,
@@ -297,7 +304,7 @@
if (obsProgram == ObsProgram.OBSDEB) {
modelBuilder.newColumnForImportExport("CONTACT_DATE_DEBARQUEMENT", Contact.PROPERTY_LANDING_DATE, Common.DAY_TIME);
modelBuilder.newColumnForImportExport("CONTACT_TYPE_OBSERVATION", "observationType", new Common.ToStringParserFormatter(ObservationType.values()));
- modelBuilder.newColumnForImportExport("CONTACT_METIER", Contact.PROPERTY_OBS_DEB_CODE, new ObsDebCodeParserFormatter(obsDebCodes));
+ modelBuilder.newColumnForImportExport("CONTACT_METIER", Contact.PROPERTY_OBS_DEB_CODE, new ObsDebCodeParserFormatter(locale, obsDebCodes));
}
return modelBuilder;
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactStateMotivesImportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactStateMotivesImportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactStateMotivesImportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -34,11 +34,18 @@
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
public class ContactStateMotivesImportModel implements ImportModel<ContactStateMotif> {
protected ModelBuilder<ContactStateMotif> modelBuilder;
+ protected final Locale locale;
+
+ public ContactStateMotivesImportModel(Locale locale) {
+ this.locale = locale;
+ }
+
@Override
public char getSeparator() {
return ';';
@@ -67,7 +74,7 @@
@Override
public String parse(String value) throws ParseException {
if (value.length() != 6) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongColor", value));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.wrongColor", value));
}
return value.trim();
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/FishingZoneImportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/FishingZoneImportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/FishingZoneImportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -33,13 +33,19 @@
import java.util.Collection;
import java.util.List;
+import java.util.Locale;
/**
* Modèle permettant l'import des zones de pêches.
- *
*/
public class FishingZoneImportModel implements ImportModel<FishingZone> {
+ protected final Locale locale;
+
+ public FishingZoneImportModel(Locale locale) {
+ this.locale = locale;
+ }
+
@Override
public char getSeparator() {
return ';';
@@ -61,8 +67,8 @@
modelBuilder.newMandatoryColumn("PECHE_DIVISION", FishingZone.PROPERTY_DISTRICT_CODE);
modelBuilder.newMandatoryColumn("PECHE_ZONE", FishingZone.PROPERTY_SECTOR_NAME);
modelBuilder.newMandatoryColumn("PECHE_FACADE", FishingZone.PROPERTY_FACADE_NAME);
- modelBuilder.newMandatoryColumn("PECHE_LATITUDE", FishingZone.PROPERTY_LATITUDE, new LatitudeParserFormatter(true));
- modelBuilder.newMandatoryColumn("PECHE_LONGITUDE", FishingZone.PROPERTY_LONGITUDE, new LongitudeParserFormatter(true));
+ modelBuilder.newMandatoryColumn("PECHE_LATITUDE", FishingZone.PROPERTY_LATITUDE, new LatitudeParserFormatter(locale, true));
+ modelBuilder.newMandatoryColumn("PECHE_LONGITUDE", FishingZone.PROPERTY_LONGITUDE, new LongitudeParserFormatter(locale, true));
return (Collection) modelBuilder.getColumnsForImport();
}
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsDebSamplingPlanImportExportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsDebSamplingPlanImportExportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsDebSamplingPlanImportExportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -48,6 +48,7 @@
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
/**
@@ -62,6 +63,8 @@
protected static final String OBSERVATION_UNIT_HEADER_NAME = "UNITE_OBSERVATION_COD";
+ protected final Locale locale;
+
protected List<TerrestrialDivision> observationUnits;
protected List<WaoUser> allWaoUsers;
@@ -81,12 +84,14 @@
protected ObservationType observationType;
/** Constructor used for import */
- public ObsDebSamplingPlanImportExportModel(boolean admin,
+ public ObsDebSamplingPlanImportExportModel(Locale locale,
+ boolean admin,
List<TerrestrialDivision> observationUnits,
List<WaoUser> allWaoUsers,
List<Company> allCompanies,
List<Boat> allActiveBoats,
List<TerrestrialLocation> allRegions) {
+ this.locale = locale;
this.admin = admin;
this.allWaoUsers = allWaoUsers;
this.observationUnits = observationUnits;
@@ -96,7 +101,8 @@
}
/** Constructor used for export */
- public ObsDebSamplingPlanImportExportModel(boolean admin, ObservationType observationType) {
+ public ObsDebSamplingPlanImportExportModel(Locale locale, boolean admin, ObservationType observationType) {
+ this.locale = locale;
this.admin = admin;
this.observationType = observationType;
}
@@ -132,12 +138,12 @@
modelBuilder.newColumnForImportExport(
"PLAN_CODE",
SampleRow.PROPERTY_CODE,
- new SampleRowCodeParserFormatter(ObsProgram.OBSDEB));
+ new SampleRowCodeParserFormatter(locale, ObsProgram.OBSDEB));
if (admin) {
modelBuilder.newColumnForImportExport(
"SOCIETE",
SampleRow.PROPERTY_COMPANY,
- new CompanyParserFormatter(allCompanies));
+ new CompanyParserFormatter(locale, allCompanies));
}
modelBuilder.newColumnForImportExport(
"OBSERVATEUR_COD",
@@ -145,7 +151,7 @@
modelBuilder.newColumnForImportExport(
"OBSERVATEURS",
SampleRow.PROPERTY_OBSERVERS,
- new UsersParserFormatter(allWaoUsers));
+ new UsersParserFormatter(locale, allWaoUsers));
if (observationType == ObservationType.FIELD_WORK_OBSERVATION) {
modelBuilder.newColumnForImportExport(
"OBSERVATION_DATE",
@@ -170,7 +176,7 @@
modelBuilder.newColumnForImportExport(
"REGION_IFREMER",
"terrestrialLocation",
- new RegionParserFormatter(allRegions));
+ new RegionParserFormatter(locale, allRegions));
modelBuilder.newColumnForImportExport(
"OBSERVATION_DATE",
SampleRow.PROPERTY_EXPECTED_DATE,
@@ -178,7 +184,7 @@
modelBuilder.newColumnForImportExport(
BOAT_HEADER_NAME,
SampleRow.PROPERTY_BOAT,
- new BoatParserFormatter(allActiveBoats));
+ new BoatParserFormatter(allActiveBoats, locale));
}
if (log.isDebugEnabled()) {
log.debug("model built : " + modelBuilder.getColumnsForImport());
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -52,9 +52,12 @@
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
public class ObsMerContactImportExportModel implements ImportExportModel<Contact> {
+ protected final Locale locale;
+
protected ObsProgram obsProgram;
protected List<WaoUser> waoUsers;
@@ -65,11 +68,13 @@
protected List<ContactStateMotif> motives;
- public static ObsMerContactImportExportModel forExport(ObsProgram obsProgram) {
- return new ObsMerContactImportExportModel(obsProgram, null, null, null, null);
+ public static ObsMerContactImportExportModel forExport(Locale locale,
+ ObsProgram obsProgram) {
+ return new ObsMerContactImportExportModel(locale, obsProgram, null, null, null, null);
}
- public static ObsMerContactImportExportModel forImport(ObsProgram obsProgram,
+ public static ObsMerContactImportExportModel forImport(Locale locale,
+ ObsProgram obsProgram,
List<WaoUser> waoUsers,
List<SampleRow> sampleRows,
List<Boat> boats,
@@ -79,14 +84,16 @@
Preconditions.checkState(boats != null, "To import must have boats");
Preconditions.checkState(sampleRows != null, "To import must have sampleRows");
Preconditions.checkState(motives != null, "To import must have motives");
- return new ObsMerContactImportExportModel(obsProgram, waoUsers, sampleRows, boats, motives);
+ return new ObsMerContactImportExportModel(locale, obsProgram, waoUsers, sampleRows, boats, motives);
}
- protected ObsMerContactImportExportModel(ObsProgram obsProgram,
+ protected ObsMerContactImportExportModel(Locale locale,
+ ObsProgram obsProgram,
List<WaoUser> waoUsers,
List<SampleRow> sampleRows,
List<Boat> boats,
List<ContactStateMotif> motives) {
+ this.locale = locale;
this.obsProgram = obsProgram;
this.waoUsers = waoUsers;
this.sampleRows = sampleRows;
@@ -128,8 +135,8 @@
modelBuilder.newColumnForImportExport("CONTACT_ID", Contact.PROPERTY_TOPIA_ID);
modelBuilder.newColumnForImportExport("CONTACT_DATE_CREATION", Contact.PROPERTY_CREATION_DATE, Common.DAY_TIME);
if (waoUsers != null) {
- modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEUR_PRINCIPAL", Contact.PROPERTY_MAIN_OBSERVER, new UserParserFormatter(waoUsers));
- modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(waoUsers));
+ modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEUR_PRINCIPAL", Contact.PROPERTY_MAIN_OBSERVER, new UserParserFormatter(locale, waoUsers));
+ modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(locale, waoUsers));
}
modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_NOMS");
@@ -156,7 +163,7 @@
return contact.getMainObserver().getCompany();
}
},
- new CompanyParserFormatter(null)
+ new CompanyParserFormatter(locale, null)
);
modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new Common.ToStringParserFormatter(ContactState.getAllowedStates(obsProgram)));
modelBuilder.newColumnForImportExport("CONTACT_DEBUT_OBSERVATION", Contact.PROPERTY_OBSERVATION_BEGIN_DATE, Common.DAY_TIME);
@@ -167,7 +174,7 @@
modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_PROGRAMME", Contact.PROPERTY_COMMENT_ADMIN);
if (boats != null) {
- modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats));
+ modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats, locale));
}
modelBuilder.newIgnoredColumn("NAVIRE_NOM");
modelBuilder.newColumnForExport("NAVIRE_NOM", new ValueGetter<Contact, String>() {
@@ -180,7 +187,7 @@
modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_PROGRAMME", Contact.PROPERTY_VALIDATION_PROGRAM, Common.BOOLEAN);
if (sampleRows != null) {
- modelBuilder.newColumnForImportExport("PLAN_CODE", Contact.PROPERTY_SAMPLE_ROW, new SampleRowParserFormatter(sampleRows));
+ modelBuilder.newColumnForImportExport("PLAN_CODE", Contact.PROPERTY_SAMPLE_ROW, new SampleRowParserFormatter(locale, sampleRows));
}
modelBuilder.newColumnForImportExport("CONTACT_QUALITE_DONNEE", "dataReliability",
@@ -190,7 +197,7 @@
modelBuilder.newIgnoredColumn("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS");
modelBuilder.newColumnForExport("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS", Contact.PROPERTY_MAMMALS_INFO);
if (motives != null) {
- modelBuilder.newColumnForImportExport("CONTACT_ETAT_MOTIF_CODE", Contact.PROPERTY_CONTACT_STATE_MOTIF, new ContactStateMotivesParserFormatter(motives));
+ modelBuilder.newColumnForImportExport("CONTACT_ETAT_MOTIF_CODE", Contact.PROPERTY_CONTACT_STATE_MOTIF, new ContactStateMotivesParserFormatter(locale, motives));
}
modelBuilder.newIgnoredColumn("CONTACT_ETAT_MOTIF_NOM");
modelBuilder.newColumnForExport("CONTACT_ETAT_MOTIF_NOM", new ValueGetter<Contact, String>() {
@@ -211,12 +218,12 @@
@Override
public Iterable<ExportableColumn<Contact, Object>> getColumnsForExport() {
- return (Iterable) getModel().getColumnsForExport();
+ return (Iterable) getExportModel().getColumnsForExport();
}
@Override
public Iterable<ImportableColumn<Contact, Object>> getColumnsForImport() {
- return (Iterable) getModel().getColumnsForImport();
+ return (Iterable) getImportModel().getColumnsForImport();
}
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -54,6 +54,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.regex.Pattern;
/**
@@ -106,6 +107,8 @@
protected static final ValueParserFormatter<Date> MONTH_YEAR_PARSER_FORMATTER = new Common.DateValue("MM/yyyy");
+ protected final Locale locale;
+
protected ObsProgram obsProgram;
protected List<Company> companies;
@@ -121,16 +124,18 @@
protected PeriodDates periodDates;
/** Pour l'export */
- public ObsMerObsVenteSamplingPlanImportExportModel(Date fromMonth, Date toMonth, ObsProgram obsProgram) {
+ public ObsMerObsVenteSamplingPlanImportExportModel(Locale locale, Date fromMonth, Date toMonth, ObsProgram obsProgram) {
+ this.locale = locale;
this.periodDates = new PeriodDates(fromMonth, toMonth);
this.obsProgram = obsProgram;
}
/** Pour l'import */
- public ObsMerObsVenteSamplingPlanImportExportModel(ObsProgram obsProgram,
- List<Company> companies, List<FishingZone> fishingZones,
- List<TerrestrialLocation> terrestrialDistricts,
- ReferentialService referentialService) {
+ public ObsMerObsVenteSamplingPlanImportExportModel(Locale locale, ObsProgram obsProgram,
+ List<Company> companies, List<FishingZone> fishingZones,
+ List<TerrestrialLocation> terrestrialDistricts,
+ ReferentialService referentialService) {
+ this.locale = locale;
this.obsProgram = obsProgram;
this.companies = companies;
this.fishingZones = fishingZones;
@@ -184,8 +189,8 @@
modelBuilder = new ModelBuilder<>();
- modelBuilder.newColumnForImportExport("PLAN_CODE", SampleRow.PROPERTY_CODE, new SampleRowCodeParserFormatter(obsProgram));
- modelBuilder.newColumnForImportExport("SOCIETE_NOM", SampleRow.PROPERTY_COMPANY, new CompanyParserFormatter(companies));
+ modelBuilder.newColumnForImportExport("PLAN_CODE", SampleRow.PROPERTY_CODE, new SampleRowCodeParserFormatter(locale, obsProgram));
+ modelBuilder.newColumnForImportExport("SOCIETE_NOM", SampleRow.PROPERTY_COMPANY, new CompanyParserFormatter(locale, companies));
modelBuilder.newColumnForExport("PECHE_FACADE", "facade");
modelBuilder.newIgnoredColumn("PECHE_FACADE");
@@ -193,9 +198,9 @@
modelBuilder.newColumnForExport("PECHE_ZONE", "sectors");
modelBuilder.newIgnoredColumn("PECHE_ZONE");
- modelBuilder.newColumnForImportExport("PECHE_DIVISION", SampleRow.PROPERTY_FISHING_ZONE, new FishingZonesParserFormatter(fishingZones));
+ modelBuilder.newColumnForImportExport("PECHE_DIVISION", SampleRow.PROPERTY_FISHING_ZONE, new FishingZonesParserFormatter(locale, fishingZones));
modelBuilder.newColumnForImportExport("PECHE_AUTRE", SampleRow.PROPERTY_FISHING_ZONES_INFOS);
- modelBuilder.newColumnForImportExport("METIER_CODE_DCF5", SampleRow.PROPERTY_D_CF5_CODE, new DCF5CodesParserFormatter(referentialService));
+ modelBuilder.newColumnForImportExport("METIER_CODE_DCF5", SampleRow.PROPERTY_D_CF5_CODE, new DCF5CodesParserFormatter(locale, referentialService));
modelBuilder.newColumnForImportExport("METIER_MAILLAGE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_MESH_SIZE);
modelBuilder.newColumnForImportExport("METIER_TAILLE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_SIZE);
modelBuilder.newColumnForImportExport("METIER_AUTRE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_OTHER);
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/RawObsDebCodesImportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/RawObsDebCodesImportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/RawObsDebCodesImportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -31,15 +31,19 @@
import org.nuiton.csv.ModelBuilder;
import java.util.List;
+import java.util.Locale;
public class RawObsDebCodesImportModel implements ImportModel<RawObsDebCode> {
+ protected final Locale locale;
+
protected ModelBuilder<RawObsDebCode> modelBuilder;
protected RegionParserFormatter regionParser;
- public RawObsDebCodesImportModel(List<TerrestrialLocation> allRegions) {
- regionParser = new RegionParserFormatter(allRegions);
+ public RawObsDebCodesImportModel(Locale locale, List<TerrestrialLocation> allRegions) {
+ this.locale = locale;
+ regionParser = new RegionParserFormatter(this.locale, allRegions);
}
@Override
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialDivisionImportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialDivisionImportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialDivisionImportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -35,9 +35,11 @@
import org.nuiton.csv.ValueParser;
import java.util.List;
+import java.util.Locale;
public class TerrestrialDivisionImportModel implements ImportModel<TerrestrialDivision> {
+ protected final Locale locale;
/** all valid {@link fr.ifremer.wao.entity.TerrestrialLocation#getRegionIfremerCode()} values.
* for validation purpose only */
@@ -45,8 +47,9 @@
protected List<TerrestrialLocation> ports;
- public TerrestrialDivisionImportModel(List<TerrestrialLocation> ports,
+ public TerrestrialDivisionImportModel(Locale locale, List<TerrestrialLocation> ports,
List<TerrestrialLocation> regions) {
+ this.locale = locale;
this.ports = ports;
this.regions = regions;
}
@@ -87,7 +90,7 @@
modelBuilder.newMandatoryColumn(
"REGION_IFREMER_COD",
TerrestrialDivision.PROPERTY_REGION_IFREMER,
- new RegionParserFormatter(regions));
+ new RegionParserFormatter(locale, regions));
modelBuilder.newIgnoredColumn("REGION_IFREMER_LIB");
modelBuilder.newMandatoryColumn("ZONE_COMPETENCE_COD", TerrestrialDivision.PROPERTY_SKILL_ZONE_CODE);
modelBuilder.newMandatoryColumn("ZONE_COMPETENCE_LIB", TerrestrialDivision.PROPERTY_SKILL_ZONE_NAME);
@@ -99,7 +102,7 @@
"LIEU_OBSERVATION_COD",
TerrestrialDivision.PROPERTY_PORT,
// the value given is a code of a port, let's find and associate
- new PortParserFormatter(ports, false));
+ new PortParserFormatter(locale, ports, false));
modelBuilder.newIgnoredColumn("LIEU_OBSERVATION_LIB");
modelBuilder.newIgnoredColumn("DATE_DEBUT");
modelBuilder.newIgnoredColumn("DATE_FIN");
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialLocationImportModel.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialLocationImportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/TerrestrialLocationImportModel.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -34,9 +34,16 @@
import org.nuiton.csv.ValueSetter;
import java.util.List;
+import java.util.Locale;
public class TerrestrialLocationImportModel implements ImportModel<TerrestrialLocation> {
+ protected final Locale locale;
+
+ public TerrestrialLocationImportModel(Locale locale) {
+ this.locale = locale;
+ }
+
@Override
public char getSeparator() {
return ';';
@@ -191,20 +198,20 @@
modelBuilder.newMandatoryColumn(
"QUARTIER_LATITUDE",
TerrestrialLocation.PROPERTY_DISTRICT_LATITUDE,
- new LatitudeParserFormatter(true));
+ new LatitudeParserFormatter(locale, true));
modelBuilder.newMandatoryColumn(
"QUARTIER_LONGITUDE",
TerrestrialLocation.PROPERTY_DISTRICT_LONGITUDE,
- new LongitudeParserFormatter(true));
+ new LongitudeParserFormatter(locale, true));
modelBuilder.newMandatoryColumn(
"FACADE_LATITUDE",
TerrestrialLocation.PROPERTY_SEABOARD_LATITUDE,
- new LatitudeParserFormatter(true));
+ new LatitudeParserFormatter(locale, true));
modelBuilder.newMandatoryColumn(
"FACADE_LONGITUDE",
TerrestrialLocation.PROPERTY_SEABOARD_LONGITUDE,
- new LongitudeParserFormatter(true));
+ new LongitudeParserFormatter(locale, true));
return (Iterable) modelBuilder.getColumnsForImport();
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatImmatriculationParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatImmatriculationParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatImmatriculationParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -27,6 +27,7 @@
import org.nuiton.i18n.I18n;
import java.text.ParseException;
+import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -42,9 +43,15 @@
*/
public class BoatImmatriculationParserFormatter implements ValueParserFormatter<Integer> {
+ protected final Locale locale;
+
/** Exactly 6 digits */
protected Pattern pattern = Pattern.compile("\\d{6}");
+ public BoatImmatriculationParserFormatter(Locale locale) {
+ this.locale = locale;
+ }
+
@Override
public String format(Integer immatriculation) {
return String.valueOf(immatriculation);
@@ -60,7 +67,7 @@
public Integer parse(String imma) throws ParseException {
Matcher matcher = pattern.matcher(imma);
if (!matcher.find()) {
- throw new IllegalArgumentException(I18n.t("wao.business.boat.validation.immatriculation.wrongFormat"));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.business.boat.validation.immatriculation.wrongFormat"));
}
Integer immatriculation = Integer.parseInt(imma);
return immatriculation;
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/BoatParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -32,13 +32,17 @@
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
/** Parse a boat (identification based on the immatriculation) */
public class BoatParserFormatter implements ValueParserFormatter<Boat> {
+ protected final Locale locale;
+
protected ImmutableMap<Integer, Boat> indexedBoats;
- public BoatParserFormatter(List<Boat> boats) {
+ public BoatParserFormatter(List<Boat> boats, Locale locale) {
+ this.locale = locale;
indexedBoats = Maps.uniqueIndex(boats, Boats.getImmatriculation());
}
@@ -51,12 +55,12 @@
public Boat parse(String value) throws ParseException {
String trimmedValue = value.trim();
if (trimmedValue.isEmpty()) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.boatMissing"));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.boatMissing"));
}
Integer key = Integer.valueOf(trimmedValue);
Boat boat = indexedBoats.get(key);
if (boat == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongBoat", value));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.wrongBoat", value));
}
return boat;
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/CompanyParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/CompanyParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/CompanyParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -29,18 +29,23 @@
import fr.ifremer.wao.entity.Company;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.csv.ValueParserFormatter;
+import org.nuiton.i18n.I18n;
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
/** Parse a company according to it's name. */
public class CompanyParserFormatter implements ValueParserFormatter<Company> {
+ protected final Locale locale;
+
protected List<Company> companies;
protected ImmutableMap<String, Company> indexedCompanies;
- public CompanyParserFormatter(List<Company> companies) {
+ public CompanyParserFormatter(Locale locale, List<Company> companies) {
+ this.locale = locale;
this.companies = companies;
}
@@ -62,8 +67,7 @@
if (StringUtils.isNotBlank(companyName)) {
company = indexedCompanies.get(companyName.trim());
if (company == null) {
- throw new IllegalArgumentException("Il n'y a pas de société ayant pour nom '"
- + companyName + "'");
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.unkwonCompany", companyName));
}
}
return company;
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ContactStateMotivesParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ContactStateMotivesParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ContactStateMotivesParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -33,14 +33,18 @@
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
public class ContactStateMotivesParserFormatter implements ValueParserFormatter<ContactStateMotif> {
+ protected final Locale locale;
+
protected List<ContactStateMotif> motives;
protected ImmutableMap<String, ContactStateMotif> indexedMotives;
- public ContactStateMotivesParserFormatter(List<ContactStateMotif> motives) {
+ public ContactStateMotivesParserFormatter(Locale locale, List<ContactStateMotif> motives) {
+ this.locale = locale;
this.motives = motives;
}
@@ -64,7 +68,7 @@
} else {
contactStateMotif = indexedMotives.get(code.trim());
if (contactStateMotif == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongContactStateMotifCode", code));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.wrongContactStateMotifCode", code));
}
}
return contactStateMotif;
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DCF5CodesParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DCF5CodesParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DCF5CodesParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -36,16 +36,22 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Locale;
public class DCF5CodesParserFormatter implements ValueParserFormatter<List<DCF5Code>> {
protected static final String DCF5_CODES_SEPARATOR = ",";
+ protected final Locale locale;
+
protected ReferentialService referentialService;
- public DCF5CodesParserFormatter() {}
+ public DCF5CodesParserFormatter(Locale locale) {
+ this.locale = locale;
+ }
- public DCF5CodesParserFormatter(ReferentialService referentialService) {
+ public DCF5CodesParserFormatter(Locale locale, ReferentialService referentialService) {
+ this.locale = locale;
this.referentialService = referentialService;
}
@@ -62,9 +68,9 @@
List<DCF5Code> value = new ArrayList<>(dcf5Codes);
return value;
} catch (UnknownFishingGearDcfCodeException e) {
- throw new IllegalArgumentException(I18n.t("wao.import.sampleRow.failure.unknownFishingGearDcfCode", e.getCode()), e);
+ throw new IllegalArgumentException(I18n.l(locale,"wao.import.sampleRow.failure.unknownFishingGearDcfCode", e.getCode()), e);
} catch (UnknownTargetSpeciesDcfCodeException e) {
- throw new IllegalArgumentException(I18n.t("wao.import.sampleRow.failure.unknownTargetSpeciesDcfCode", e.getCode()), e);
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.sampleRow.failure.unknownTargetSpeciesDcfCode", e.getCode()), e);
}
}
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -32,13 +32,17 @@
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
public class DistrictParserFormatter implements ValueParserFormatter<TerrestrialLocation> {
+ protected final Locale locale;
+
protected Map<String, TerrestrialLocation> indexedDistricts;
- public DistrictParserFormatter(List<TerrestrialLocation> districts) {
+ public DistrictParserFormatter(Locale locale, List<TerrestrialLocation> districts) {
+ this.locale = locale;
if (districts != null) {
indexedDistricts = new HashMap<>();
for (TerrestrialLocation district : districts) {
@@ -64,11 +68,11 @@
public TerrestrialLocation parse(String value) throws ParseException {
String trimmedValue = value.trim();
if (trimmedValue.isEmpty()) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.districtMissing"));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.districtMissing"));
}
TerrestrialLocation district = indexedDistricts.get(trimmedValue);
if (district == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongDistrict", value));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.wrongDistrict", value));
}
return district;
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -33,13 +33,17 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
public class DistrictsParserFormatter implements ValueParserFormatter<Collection<TerrestrialLocation>> {
+ protected final Locale locale;
+
protected Map<String, TerrestrialLocation> indexedDistricts;
- public DistrictsParserFormatter(List<TerrestrialLocation> districts) {
+ public DistrictsParserFormatter(Locale locale, List<TerrestrialLocation> districts) {
+ this.locale = locale;
indexedDistricts = new HashMap<>();
for (TerrestrialLocation district : districts) {
if ( ! district.isDistrict()) {
@@ -65,14 +69,14 @@
@Override
public Collection<TerrestrialLocation> parse(String value) throws ParseException {
if (StringUtils.isBlank(value)) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.districtMissing"));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.districtMissing"));
}
String[] districtCodes = StringUtils.split(value, ',');
Collection<TerrestrialLocation> districts = new LinkedList<>();
for (String districtCode : districtCodes) {
TerrestrialLocation district = indexedDistricts.get(districtCode.trim());
if (district == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongDistrict", value));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.wrongDistrict", value));
}
districts.add(district);
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/FishingZonesParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/FishingZonesParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/FishingZonesParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -34,17 +34,21 @@
import java.text.ParseException;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
/**
* Consiste en plusieurs codes de zones de pêches séparés par des " / ".
*/
public class FishingZonesParserFormatter implements ValueParserFormatter<List<FishingZone>> {
+ protected final Locale locale;
+
protected ImmutableMap<String, FishingZone> indexedFishingZones;
protected List<FishingZone> fishingZones;
- public FishingZonesParserFormatter(List<FishingZone> fishingZones) {
+ public FishingZonesParserFormatter(Locale locale, List<FishingZone> fishingZones) {
+ this.locale = locale;
this.fishingZones = fishingZones;
}
@@ -64,13 +68,13 @@
}
List<FishingZone> fishingZones = new LinkedList<>();
if (StringUtils.isBlank(districtCodes)) {
- throw new IllegalArgumentException(I18n.t("wao.import.sampleRow.failure.fishingZoneMissing"));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.sampleRow.failure.fishingZoneMissing"));
} else {
String[] codes = districtCodes.split(",");
for (String code : codes) {
FishingZone fishingZone = indexedFishingZones.get(code.trim());
if (fishingZone == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.sampleRow.failure.wrongFishingZone", code.trim()));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.sampleRow.failure.wrongFishingZone", code.trim()));
}
fishingZones.add(fishingZone);
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LatitudeParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LatitudeParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LatitudeParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -25,23 +25,29 @@
import org.apache.commons.lang3.Range;
import org.nuiton.csv.Common;
+import org.nuiton.i18n.I18n;
+import java.util.Locale;
+
public class LatitudeParserFormatter extends Common.DoubleParserFormatter {
protected static final Range<Double> VALID_LATITUDES = Range.between(-90., 90.);
- public LatitudeParserFormatter(boolean nullAllowed) {
+ protected final Locale locale;
+
+ public LatitudeParserFormatter(Locale locale, boolean nullAllowed) {
super(null, nullAllowed);
+ this.locale = locale;
}
@Override
protected Double parseNoneEmptyValue(String value) {
Double latitude = super.parseNoneEmptyValue(value);
- if ( ! VALID_LATITUDES.contains(latitude)) {
+ if (!VALID_LATITUDES.contains(latitude)) {
+
throw new IllegalArgumentException(
- "a latitude must be contained in range " + VALID_LATITUDES +
- ". ('" + latitude + "' argument given)");
+ I18n.l(locale, "wao.import.invalid.latitude", VALID_LATITUDES, latitude));
}
return latitude;
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocationTypeParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocationTypeParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocationTypeParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -30,11 +30,18 @@
import java.text.ParseException;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
/** Parse a location type (PORT or AUCTION only) */
public class LocationTypeParserFormatter implements ValueParserFormatter<LocationType> {
+ protected final Locale locale;
+
+ public LocationTypeParserFormatter(Locale locale) {
+ this.locale = locale;
+ }
+
@Override
public String format(LocationType locationType) {
String value = "";
@@ -58,7 +65,7 @@
locationType = fromStrings.get(value.trim());
if (locationType == null) {
throw new IllegalArgumentException(
- I18n.t("wao.import.failure.wrongLocationType",
+ I18n.l(locale, "wao.import.failure.wrongLocationType",
value, fromStrings.keySet()));
}
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LongitudeParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LongitudeParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LongitudeParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -25,23 +25,28 @@
import org.apache.commons.lang3.Range;
import org.nuiton.csv.Common;
+import org.nuiton.i18n.I18n;
+import java.util.Locale;
+
public class LongitudeParserFormatter extends Common.DoubleParserFormatter {
protected static final Range<Double> VALID_LONGITUDES = Range.between(-180., 180.);
- public LongitudeParserFormatter(boolean nullAllowed) {
+ protected final Locale locale;
+
+ public LongitudeParserFormatter(Locale locale, boolean nullAllowed) {
super(null, nullAllowed);
+ this.locale = locale;
}
@Override
protected Double parseNoneEmptyValue(String value) {
Double longitude = super.parseNoneEmptyValue(value);
- if ( ! VALID_LONGITUDES.contains(longitude)) {
+ if (!VALID_LONGITUDES.contains(longitude)) {
throw new IllegalArgumentException(
- "a longitude must be contained in range " + VALID_LONGITUDES +
- ". ('" + longitude + "' argument given)");
+ I18n.l(locale, "wao.import.invalid.longitude", VALID_LONGITUDES, longitude));
}
return longitude;
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ObsDebCodeParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ObsDebCodeParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ObsDebCodeParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -33,14 +33,18 @@
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
public class ObsDebCodeParserFormatter implements ValueParserFormatter<ObsDebCode> {
+ protected final Locale locale;
+
protected ImmutableMap<String, ObsDebCode> indexedObsDebCodes;
protected List<ObsDebCode> obsDebCodes;
- public ObsDebCodeParserFormatter(List<ObsDebCode> obsDebCodes) {
+ public ObsDebCodeParserFormatter(Locale locale, List<ObsDebCode> obsDebCodes) {
+ this.locale = locale;
this.obsDebCodes = obsDebCodes;
}
@@ -63,7 +67,7 @@
obsDebCode = indexedObsDebCodes.get(code);
if (obsDebCode == null) {
throw new IllegalArgumentException
- (I18n.t("wao.import.failure.wrongObsDebCode", code));
+ (I18n.l(locale, "wao.import.failure.wrongObsDebCode", code));
}
}
return obsDebCode;
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/PortParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/PortParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/PortParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -29,12 +29,17 @@
import fr.ifremer.wao.entity.TerrestrialLocations;
import org.apache.commons.lang3.StringUtils;
import org.nuiton.csv.ValueParserFormatter;
+import org.nuiton.i18n.I18n;
import java.util.List;
+import java.util.Locale;
public class PortParserFormatter implements ValueParserFormatter<TerrestrialLocation> {
- /** Existing ports
+ protected final Locale locale;
+
+ /**
+ * Existing ports
* key should be an terrestrial location id {@link fr.ifremer.wao.entity.TerrestrialLocation#getCode()}
* and all the values must have {@link fr.ifremer.wao.entity.TerrestrialLocation#getLocationType()} at
* {@link fr.ifremer.wao.entity.LocationType#PORT}.
@@ -43,7 +48,8 @@
protected boolean allowNullValue;
- public PortParserFormatter(List<TerrestrialLocation> ports, boolean allowNullValue) {
+ public PortParserFormatter(Locale locale, List<TerrestrialLocation> ports, boolean allowNullValue) {
+ this.locale = locale;
this.allowNullValue = allowNullValue;
if (ports != null) {
this.ports = Maps.uniqueIndex(ports, TerrestrialLocations.getCode());
@@ -57,12 +63,14 @@
if (allowNullValue) {
port = null;
} else {
- throw new IllegalArgumentException("Il faut préciser un port");
+ throw new IllegalArgumentException(
+ I18n.l(locale, "wao.import.boat.failure.missing.port"));
}
} else {
port = ports.get(locationCode);
if (port == null) {
- throw new IllegalArgumentException("Le code '" + locationCode + "' n'est pas un code de lieu valide");
+ throw new IllegalArgumentException(
+ I18n.l(locale, "wao.import.boat.failure.invalid.locationCode", locationCode));
}
}
return port;
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -28,17 +28,22 @@
import fr.ifremer.wao.entity.TerrestrialLocation;
import fr.ifremer.wao.entity.TerrestrialLocations;
import org.nuiton.csv.ValueParserFormatter;
+import org.nuiton.i18n.I18n;
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
public class RegionParserFormatter implements ValueParserFormatter<TerrestrialLocation> {
+ protected final Locale locale;
+
protected List<TerrestrialLocation> regions;
protected ImmutableMap<String, TerrestrialLocation> indexedRegions;
- public RegionParserFormatter(List<TerrestrialLocation> regions) {
+ public RegionParserFormatter(Locale locale, List<TerrestrialLocation> regions) {
+ this.locale = locale;
this.regions = regions;
}
@@ -59,10 +64,10 @@
}
TerrestrialLocation terrestrialLocation =
- indexedRegions.get(regionCode.trim());
+ indexedRegions.get(regionCode.trim());
if (terrestrialLocation == null) {
- throw new IllegalArgumentException("Le code '" + regionCode +
- "' n'est pas un code de région valide");
+ throw new IllegalArgumentException(
+ I18n.l(locale, "wao.import.failure.invalid.regionCode", regionCode));
}
return terrestrialLocation;
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionsParser.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionsParser.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/RegionsParser.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -28,18 +28,23 @@
import fr.ifremer.wao.entity.TerrestrialLocation;
import fr.ifremer.wao.entity.TerrestrialLocations;
import org.nuiton.csv.ValueParser;
+import org.nuiton.i18n.I18n;
import java.text.ParseException;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
public class RegionsParser implements ValueParser<List<TerrestrialLocation>> {
+ protected final Locale locale;
+
protected List<TerrestrialLocation> regions;
protected ImmutableMap<String, TerrestrialLocation> indexedRegions;
- public RegionsParser(List<TerrestrialLocation> regions) {
+ public RegionsParser(Locale locale, List<TerrestrialLocation> regions) {
+ this.locale = locale;
this.regions = regions;
}
@@ -57,8 +62,8 @@
TerrestrialLocation region =
indexedRegions.get(regionCode.trim());
if (region == null) {
- throw new IllegalArgumentException("Le code '" + regionCode +
- "' n'est pas un code de région valide");
+ throw new IllegalArgumentException(
+ I18n.l(locale, "wao.import.failure.invalid.regionCode", regionCode));
}
regions.add(region);
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowCodeParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowCodeParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowCodeParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -30,13 +30,17 @@
import org.nuiton.i18n.I18n;
import java.text.ParseException;
+import java.util.Locale;
import java.util.regex.Pattern;
public class SampleRowCodeParserFormatter implements ValueParserFormatter<String> {
+ protected final Locale locale;
+
protected Pattern sampleRowCodePattern;
- public SampleRowCodeParserFormatter(ObsProgram obsProgram) {
+ public SampleRowCodeParserFormatter(Locale locale, ObsProgram obsProgram) {
+ this.locale = locale;
sampleRowCodePattern = WaoUtils.getSampleRowCodePattern(obsProgram);
}
@@ -49,12 +53,12 @@
public String parse(String value) throws ParseException {
String sampleRowCode;
if (StringUtils.isBlank(value)) {
- throw new IllegalArgumentException(I18n.t("wao.import.sampleRow.failure.missingSampleRowCode"));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.sampleRow.failure.missingSampleRowCode"));
} else {
if (sampleRowCodePattern.matcher(value).matches()) {
sampleRowCode = value;
} else {
- throw new IllegalArgumentException(I18n.t("wao.import.sampleRow.failure.wrongSampleRowCodeFormat", value.trim()));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.sampleRow.failure.wrongSampleRowCodeFormat", value.trim()));
}
}
return sampleRowCode;
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SampleRowParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -33,12 +33,16 @@
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
public class SampleRowParserFormatter implements ValueParserFormatter<SampleRow> {
+ protected final Locale locale;
+
protected ImmutableMap<String, SampleRow> indexedSampleRows;
- public SampleRowParserFormatter(List<SampleRow> sampleRows) {
+ public SampleRowParserFormatter(Locale locale, List<SampleRow> sampleRows) {
+ this.locale = locale;
indexedSampleRows = Maps.uniqueIndex(sampleRows, SampleRows.getCode());
}
@@ -51,11 +55,11 @@
public SampleRow parse(String sampleRowCode) throws ParseException {
String trimmedCode = sampleRowCode.trim();
if (StringUtils.isEmpty(trimmedCode)) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.sampleRowCodeMissing"));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.sampleRowCodeMissing"));
}
SampleRow sampleRow = indexedSampleRows.get(sampleRowCode);
if (sampleRow == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongSampleRowCode", sampleRowCode));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.wrongSampleRowCode", sampleRowCode));
}
return sampleRow;
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UserParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UserParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UserParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -33,13 +33,17 @@
import java.text.ParseException;
import java.util.List;
+import java.util.Locale;
public class UserParserFormatter implements ValueParserFormatter<WaoUser> {
+ protected final Locale locale;
+
/** all waoUsers in the database when import was started, indexed by logins */
protected ImmutableMap<String, WaoUser> indexedWaoUsers;
- public UserParserFormatter(List<WaoUser> waoUsers) {
+ public UserParserFormatter(Locale locale, List<WaoUser> waoUsers) {
+ this.locale = locale;
this.indexedWaoUsers = Maps.uniqueIndex(waoUsers, WaoUsers.getLogin());
}
@@ -53,7 +57,7 @@
public WaoUser parse(String login) throws ParseException {
WaoUser user = indexedWaoUsers.get(login.trim());
if (user == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.failure.wrongUser", login));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.failure.wrongUser", login));
}
return user;
}
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UsersParserFormatter.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UsersParserFormatter.java 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/UsersParserFormatter.java 2014-04-04 16:15:57 UTC (rev 1838)
@@ -35,15 +35,19 @@
import java.text.ParseException;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
public class UsersParserFormatter implements ValueParserFormatter<List<WaoUser>> {
protected static final String SEPARATOR = ",";
+ protected final Locale locale;
+
/** all waoUsers in the database when import was started, indexed by logins */
protected ImmutableMap<String, WaoUser> indexedWaoUsers;
- public UsersParserFormatter(List<WaoUser> waoUsers) {
+ public UsersParserFormatter(Locale locale, List<WaoUser> waoUsers) {
+ this.locale = locale;
this.indexedWaoUsers = Maps.uniqueIndex(waoUsers, WaoUsers.getLogin());
}
@@ -62,7 +66,7 @@
String trimmedLogin = login.trim();
WaoUser user = indexedWaoUsers.get(trimmedLogin);
if (user == null) {
- throw new IllegalArgumentException(I18n.t("wao.import.failure.wrongUser", login));
+ throw new IllegalArgumentException(I18n.l(locale, "wao.import.failure.wrongUser", login));
}
users.add(user);
}
Modified: trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties
===================================================================
--- trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-04-04 16:15:57 UTC (rev 1838)
@@ -32,6 +32,8 @@
wao.business.validationState.validated=validate
wao.export.ical.desc=wtih %s
wao.export.ical.title=ObsDeb Observation
+wao.import.boat.failure.invalid.locationCode=The code '%s' is not a valid location code
+wao.import.boat.failure.missing.port=The port is required
wao.import.contact.failure.boatMissing=You need to precise the plate number of the boat associated to the contact
wao.import.contact.failure.districtMissing=You need to precise the boat district
wao.import.contact.failure.invalid.company.for.observer=L'observateur %s n'est pas membre de la société %s
@@ -52,6 +54,7 @@
wao.import.contact.failure.missing.trip.beginDate=La date de début de marée est obligatoire pour l'état '%s'
wao.import.contact.failure.sampleRowCodeMissing=The code of the sample row line is missing
wao.import.contact.failure.terrestrialLocationMissing=The code of the terrestrial location is missing
+wao.import.contact.failure.unkwonCompany=Company named '%s' does not exist
wao.import.contact.failure.wrongBoat=There is no boat with plate number '%s'
wao.import.contact.failure.wrongColor=The color '%s' is not a valid color. It must be composed of 6 characters without the hash (\#), see http\://en.wikipedia.org/wiki/Web_colors
wao.import.contact.failure.wrongContactStateMotifCode=The code '%s' is not a valid code
@@ -59,9 +62,12 @@
wao.import.contact.failure.wrongSampleRowCode=The is no sample row with code '%s'
wao.import.contact.failure.wrongTerrestrialLocation=There is no location of type '%s' with code '%s'
wao.import.failure=Import fail.
+wao.import.failure.invalid.regionCode=The code '%s' is not a valid region code
wao.import.failure.wrongLocationType='%s' is not a valid location type, allowed values are %s
wao.import.failure.wrongObsDebCode=There is no profession code having code '%s'
wao.import.failure.wrongUser=There is no user with login '%s'
+wao.import.invalid.latitude=a latitude must be contained in range %s. ('%s' argument given)
+wao.import.invalid.longitude=a longitude must be contained in range %s. ('%s' argument given)
wao.import.sampleRow.failure.fishingZoneMissing=You must precise at least one fishing zone
wao.import.sampleRow.failure.missingSampleRowCode=You must precise a code for the sample row
wao.import.sampleRow.failure.unknownFishingGearDcfCode=Unknown fishing gear code\: %s
Modified: trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties
===================================================================
--- trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-04-04 15:37:35 UTC (rev 1837)
+++ trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-04-04 16:15:57 UTC (rev 1838)
@@ -31,6 +31,8 @@
wao.business.validationState.validated=Validé
wao.export.ical.desc=avec %s
wao.export.ical.title=Observation ObsDeb
+wao.import.boat.failure.invalid.locationCode=Le code '%s' n'est pas un code de lieu valide
+wao.import.boat.failure.missing.port=Il faut préciser un port
wao.import.contact.failure.boatMissing=Il faut préciser l'immatriculation du navire associé au contact
wao.import.contact.failure.districtMissing=Il faut préciser le code d'un quartier maritime
wao.import.contact.failure.invalid.company.for.observer=L'observateur %s n'est pas membre de la société %s
@@ -51,6 +53,7 @@
wao.import.contact.failure.missing.trip.beginDate=La date de début de marée est obligatoire pour l'état '%s'
wao.import.contact.failure.sampleRowCodeMissing=Il manque le code de la ligne de plan associée
wao.import.contact.failure.terrestrialLocationMissing=Il manque le code du lieu
+wao.import.contact.failure.unkwonCompany=Il n'y a pas de société ayant pour nom '%s'
wao.import.contact.failure.wrongBoat=Il n'y a pas de navire avec l'immatriculation '%s'
wao.import.contact.failure.wrongColor=Le code couleur '%s' n'est pas valide, il doit être composé de six caractères sans dièze voir http\://fr.wikipedia.org/wiki/Couleurs_du_Web
wao.import.contact.failure.wrongContactStateMotifCode=Le code '%s' n'est pas un code de motif de refus valide
@@ -58,9 +61,12 @@
wao.import.contact.failure.wrongSampleRowCode=Il n'y a pas de ligne du plan avec le code '%s'
wao.import.contact.failure.wrongTerrestrialLocation=Il n'y a pas de lieu de type '%s' ayant pour code '%s'
wao.import.failure=Une erreur est survenue lors de l'import.
+wao.import.failure.invalid.regionCode=Le code '%s' n'est pas un code de région valide
wao.import.failure.wrongLocationType='%s' n'est pas un type de lieu valide, les valeurs admises sont %s
wao.import.failure.wrongObsDebCode=Il n'y a pas de code métier ayant pour code '%s'
wao.import.failure.wrongUser=Il n'y a pas d'utilisateur ayant pour identifiant '%s'
+wao.import.invalid.latitude=La latitude doit être dans l'intervalle %s (valeur actuelle %s)
+wao.import.invalid.longitude=La longitude doit être dans l'intervalle %s (valeur actuelle %s)
wao.import.sampleRow.failure.fishingZoneMissing=Il faut préciser au moins une zone de pêche
wao.import.sampleRow.failure.missingSampleRowCode=Il faut préciser un code pour a ligne du plan
wao.import.sampleRow.failure.unknownFishingGearDcfCode=Le code engin %s est inconnu du référentiel
1
0
r1837 - in trunk: wao-persistence/src/main/java/fr/ifremer/wao/entity wao-services/src/main/java/fr/ifremer/wao/services/service wao-services/src/main/java/fr/ifremer/wao/services/service/csv wao-services/src/main/resources/i18n wao-services/src/test/java/fr/ifremer/wao/services/service wao-web/src/main/webapp/WEB-INF/content/obsmer
by tchemit@users.forge.codelutin.com 04 Apr '14
by tchemit@users.forge.codelutin.com 04 Apr '14
04 Apr '14
Author: tchemit
Date: 2014-04-04 17:37:35 +0200 (Fri, 04 Apr 2014)
New Revision: 1837
Url: http://forge.codelutin.com/projects/wao/repository/revisions/1837
Log:
refs #4487 import + save contacts
Added:
trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ElligibleBoatTopiaDao.java
trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonthTopiaDao.java
trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactNotValidException.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactStatus.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/NullSampleMonthException.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java
trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp
Removed:
trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts.jsp
Modified:
trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ImportErrorException.java
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java
trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties
trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties
trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java
trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp
Added: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ElligibleBoatTopiaDao.java
===================================================================
--- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ElligibleBoatTopiaDao.java (rev 0)
+++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ElligibleBoatTopiaDao.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,19 @@
+package fr.ifremer.wao.entity;
+
+public class ElligibleBoatTopiaDao extends AbstractElligibleBoatTopiaDao<ElligibleBoat> {
+
+ public ElligibleBoat findUniqueOrNull(Contact contact) {
+ ElligibleBoat elligible =
+ forProperties(
+ ElligibleBoat.PROPERTY_BOAT, contact.getBoat(),
+ ElligibleBoat.PROPERTY_SAMPLE_ROW, contact.getSampleRow()).findUniqueOrNull();
+ return elligible;
+ }
+
+ public ElligibleBoat create(Contact contact) {
+ ElligibleBoat elligibleBoat = create(
+ ElligibleBoat.PROPERTY_BOAT, contact.getBoat(),
+ ElligibleBoat.PROPERTY_SAMPLE_ROW, contact.getSampleRow());
+ return elligibleBoat;
+ }
+}
Property changes on: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ElligibleBoatTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonthTopiaDao.java
===================================================================
--- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonthTopiaDao.java (rev 0)
+++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonthTopiaDao.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,27 @@
+package fr.ifremer.wao.entity;
+
+import com.google.common.collect.ImmutableMap;
+import org.nuiton.topia.persistence.HqlAndParametersBuilder;
+import org.nuiton.topia.persistence.TopiaNoResultException;
+import org.nuiton.util.PeriodDates;
+
+import java.util.Date;
+
+public class SampleMonthTopiaDao extends AbstractSampleMonthTopiaDao<SampleMonth> {
+
+ public SampleMonth getExistingSampleMonth(SampleRow sampleRow, Date tideBeginDate) throws TopiaNoResultException {
+
+ PeriodDates period = new PeriodDates(tideBeginDate, tideBeginDate);
+ period.initDayOfMonthExtremities();
+
+ HqlAndParametersBuilder<SampleMonth> query = newHqlAndParametersBuilder();
+ query.addEquals(SampleMonth.PROPERTY_SAMPLE_ROW, sampleRow);
+ query.addWhereClause(SampleMonth.PROPERTY_PERIOD_DATE + " >= :beforeDate", ImmutableMap.of("beforeDate", (Object) period.getFromDate()));
+ query.addWhereClause(SampleMonth.PROPERTY_PERIOD_DATE + " <= :endDate", ImmutableMap.of("endDate", (Object) period.getThruDate()));
+
+
+ SampleMonth result = findUnique(query.getHql(), query.getHqlParameters());
+ return result;
+ }
+
+}
Property changes on: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonthTopiaDao.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java
===================================================================
--- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java (rev 0)
+++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,49 @@
+package fr.ifremer.wao.entity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Created on 4/4/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 4.0
+ */
+public class SampleMonths {
+
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(SampleMonths.class);
+
+ /**
+ * Method could be use to add some time for realTidesValue or
+ * remove time with a negative nbDays.
+ * If nbDays is negative and superior to the current value,
+ * the real tides value will be set to 0.
+ *
+ * @param nbDays to add or remove (if negative)
+ */
+ public static void addRealTideTime(SampleMonth sampleMonth, int nbDays) {
+ int result = sampleMonth.getRealTidesValue() + nbDays;
+ if (result < 0) {
+ result = 0;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Change realTides : " + sampleMonth.getRealTidesValue() +
+ " -> " + result + " _ date = " + sampleMonth.getPeriodDate());
+ }
+ sampleMonth.setRealTidesValue(result);
+ }
+
+ public static void addEstimatedTideTime(SampleMonth sampleMonth, int nbDays) {
+ int result = sampleMonth.getEstimatedTidesValue() + nbDays;
+ if (result < 0) {
+ result = 0;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Change estimatedTides : " + sampleMonth.getEstimatedTidesValue() +
+ " -> " + result + " _ date = " + sampleMonth.getPeriodDate());
+ }
+ sampleMonth.setEstimatedTidesValue(result);
+ }
+}
Property changes on: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleMonths.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java
===================================================================
--- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -25,6 +25,7 @@
package fr.ifremer.wao.entity;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@@ -36,7 +37,7 @@
/**
* SampleRowImpl
- *
+ * <p/>
* Created: 30 nov. 2009
*
* @author fdesbois <fdesbois(a)codelutin.com>
@@ -109,7 +110,7 @@
/**
* Used to get a list of boat's immatriculations linked with the sampleRow.
- *
+ *
* @return a simple String which contains immatriculations separate by
* a space
*/
@@ -126,10 +127,10 @@
}
/**
- * Check if SampleMonth of the SampleRow has already realTidesValue set
+ * Check if SampleMonth of the SampleRow has already realTidesValue set
* (different from 0). It means the SampleRow could'nt be deleted and
* have some modification constraints.
- *
+ *
* @return true if a SampleMonth have realTidesValue, false otherwise
*/
@Override
@@ -144,7 +145,8 @@
@Override
public String getProfessionDescription() {
- String code = StringUtils.join(getdCF5Code(), ", ");
+ String code = isdCF5CodeEmpty() ? "" :
+ StringUtils.join(Iterables.transform(getdCF5Code(), DCF5Codes.getCode()), ", ");
code += getProfessionDescriptionWithoutDCF5();
return code;
}
@@ -245,9 +247,8 @@
@Override
public TerrestrialLocation getTerrestrialLocation() {
TerrestrialLocation terrestrialLocation = null;
- if ( ! isTerrestrialLocationsEmpty()) {
- terrestrialLocation = (TerrestrialLocation)
- CollectionUtils.get(getTerrestrialLocations(), 0);
+ if (!isTerrestrialLocationsEmpty()) {
+ terrestrialLocation = CollectionUtils.get(getTerrestrialLocations(), 0);
}
return terrestrialLocation;
}
@@ -255,7 +256,7 @@
@Override
public SampleMonth getSampleMonth(Date date) {
Preconditions.checkState(
- ! getObsProgram().equals(ObsProgram.OBSDEB),
+ !getObsProgram().equals(ObsProgram.OBSDEB),
"opération non prévue pour ObsDeb");
if (CollectionUtils.isNotEmpty(getSampleMonth())) {
for (SampleMonth sampleMonth : getSampleMonth()) {
Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactNotValidException.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactNotValidException.java (rev 0)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactNotValidException.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,20 @@
+package fr.ifremer.wao.services.service;
+
+import fr.ifremer.wao.WaoException;
+
+/**
+ * Quand un contact n'est pas valide (lors d'une création ou d'un import).
+ * <p/>
+ * Created on 4/4/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 4.0
+ */
+public class ContactNotValidException extends WaoException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ContactNotValidException(String message) {
+ super(message);
+ }
+}
Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactNotValidException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactStatus.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactStatus.java (rev 0)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactStatus.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,350 @@
+/*
+ * #%L
+ * Wao :: Business
+ * *
+ * $Id$
+ * $HeadURL: https://svn.codelutin.com/wao/tags/wao-3.4.1/wao-business/src/main/java/fr/… $
+ * %%
+ * Copyright (C) 2009 - 2010 Ifremer
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+
+package fr.ifremer.wao.services.service;
+
+import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.ContactState;
+import fr.ifremer.wao.entity.SampleMonth;
+import fr.ifremer.wao.entity.SampleMonthTopiaDao;
+import fr.ifremer.wao.entity.SampleRow;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.persistence.TopiaNoResultException;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * //FIXME a revoir...
+ * This class is used to know status changed between an old contact and a new
+ * one (new change to apply). There is three different cases for constructor
+ * parameters :
+ * <ul>
+ * <li>CREATE : olContact is null and newContact is defined</li>
+ * <li>UPDATE : both oldContact and newContact are defined</li>
+ * <li>DELETE : oldContact is defined and newContact is null</li>
+ * </ul>
+ * Three fields of contact are considered to be changed for sampleMonth calcul
+ * on tides value :
+ * <ul>
+ * <li>
+ * STATE : check the change on {@link ContactState#OBSERVATION_DONE} state.
+ * Use {@link #isContactDoneChanged() } method to check the change.
+ * This change is important to manage estimated tides value on sampleMonth
+ * referenced by the contact retrieve with {@link #getSampleMonth()}
+ * </li>
+ * <li>
+ * VALIDATION : check the change on validationCompany and validationProgram.
+ * Use {@link #isContactValidateChanged() } method to check the change.
+ * This change is important to manage real tides value on sampleMonth
+ * referenced by the contact retrieve with {@link #getSampleMonth()}
+ * </li>
+ * <li>
+ * TIDE BEGIN DATE : check the change on tideBeginDate month.
+ * Use {@link #isTideBeginDateMonthChanged() } method to check the change.
+ * This change is important to manage both estimated and real tides value on
+ * the old sampleMonth referenced by the old contact retrieve with
+ * {@link #getOldSampleMonth()}
+ * </ul>
+ * <p/>
+ * <p/>
+ * Created: 19 avr. 2010
+ *
+ * @author fdesbois
+ */
+public class ContactStatus {
+
+ /** Logger. */
+ private static final Log logger = LogFactory.getLog(ContactStatus.class);
+
+ protected Contact oldContact;
+
+ protected Contact newContact;
+
+ protected SampleRow sampleRow;
+
+ protected SampleMonth oldSampleMonth;
+
+ protected SampleMonth sampleMonth;
+
+ protected final SampleMonthTopiaDao dao;
+
+ public ContactStatus(SampleMonthTopiaDao dao,
+ Contact old,
+ Contact contact) {
+ this.dao = dao;
+ this.oldContact = old;
+ this.newContact = contact;
+ this.sampleRow = contact != null ?
+ newContact.getSampleRow() : oldContact.getSampleRow();
+ }
+
+ public boolean isOldContactValidate() {
+ return isContactValidate(Context.OLD);
+ }
+
+ public boolean isNewContactValidate() {
+ return isContactValidate(Context.NEW);
+ }
+
+ /**
+ * Return true if oldContact validate is not the same as newContact
+ * validate.
+ *
+ * @return true if contact validate has changed.
+ * @see #isContactValidate(Context)
+ */
+ public boolean isContactValidateChanged() {
+ return isOldContactValidate() != isNewContactValidate();
+ }
+
+ public boolean isOldContactDone() {
+ return isContactDone(Context.OLD);
+ }
+
+ public boolean isNewContactDone() {
+ return isContactDone(Context.NEW);
+ }
+
+ /**
+ * Return true if oldContact state is not the same as newContact state.
+ * Check only for {@link ContactState#OBSERVATION_DONE} changed.
+ *
+ * @return true if contact state has changed.
+ * @see #isContactDone(Context)
+ */
+ public boolean isContactDoneChanged() {
+ return isOldContactDone() != isNewContactDone();
+ }
+
+ /**
+ * Return true if tideBeginDate has changed its month between oldContact
+ * and newContact. The both oldContact and newContact dates must be not
+ * null.
+ *
+ * @return true if tideBeginDate status changed
+ */
+ public boolean isTideBeginDateMonthChanged() {
+
+ if (oldContact == null || newContact == null) {
+ return false;
+ }
+ DateFormat dateFormat = new SimpleDateFormat("MM/yyyy");
+ Date oldTideBeginDate = oldContact.getObservationBeginDate();
+ Date newTideBeginDate = newContact.getObservationBeginDate();
+
+ logger.debug("old : " + oldTideBeginDate + ", new : " + newTideBeginDate);
+
+ // Only if old not null and new not null
+ if (oldTideBeginDate != null && newTideBeginDate != null) {
+ String oldTideBeginStr = dateFormat.format(oldTideBeginDate);
+ String newTideBeginStr = dateFormat.format(newTideBeginDate);
+ return !oldTideBeginStr.equals(newTideBeginStr);
+ }
+ return false;
+ }
+
+ public SampleRow getSampleRow() {
+ return sampleRow;
+ }
+
+ /**
+ * Retrive the old SampleMonth referenced by the tideBeginDate of the
+ * old contact.
+ *
+ * @return the sampleMonth found or throw NullSampleMonthException
+ * @throws NullSampleMonthException
+ */
+ public SampleMonth getOldSampleMonth()
+ throws NullSampleMonthException {
+ if (oldSampleMonth == null) {
+ oldSampleMonth = getExistingSampleMonth(Context.OLD);
+ }
+ return oldSampleMonth;
+ }
+
+ /**
+ * Retrive the SampleMonth referenced by the tideBeginDate of the
+ * new contact.
+ *
+ * @return the sampleMonth found or throw NullSampleMonthException
+ * @throws NullSampleMonthException
+ */
+ public SampleMonth getSampleMonth()
+ throws NullSampleMonthException {
+ if (sampleMonth == null) {
+ sampleMonth = getExistingSampleMonth(Context.NEW);
+ }
+ return sampleMonth;
+ }
+
+ protected enum Context {
+ OLD, NEW
+ }
+
+ /**
+ * Retrieve existing sampleMonth corresponding to the contact. The
+ * sampleMonth must match with contact sampleRow, also the tideBeginDate
+ * (day) of the contact must match the sampleMonth periodDate (month).
+ *
+ * @param context OLD or NEW
+ * @return the sampleMonth found if exists, or NullSampleMonthException
+ * will be thrown
+ * @throws NullSampleMonthException if month was not found
+ */
+ protected SampleMonth getExistingSampleMonth(Context context) throws NullSampleMonthException {
+
+ // Reference date for query
+ Date tideBeginDate = null;
+
+ switch (context) {
+ case OLD:
+ tideBeginDate = oldContact.getObservationBeginDate();
+ break;
+ // newContact may be null in CREATE case, so we use the previous
+ // one
+ case NEW:
+ if (newContact != null &&
+ newContact.getObservationBeginDate() != null) {
+ tideBeginDate = newContact.getObservationBeginDate();
+ } else {
+ tideBeginDate = oldContact.getObservationBeginDate();
+ }
+ }
+
+ SampleMonth result;
+ try {
+ result = dao.getExistingSampleMonth(sampleRow, tideBeginDate);
+ } catch (TopiaNoResultException e) {
+ throw new NullSampleMonthException(
+ "Aucun mois correspondant pour" +
+ " la ligne du plan d'échantillonnage " +
+ sampleRow.getCode() +
+ " et la date de début de marée du contact " +
+ tideBeginDate
+ );
+ }
+ return result;
+ }
+
+ /**
+ * Return true if contact is validate depends on {@code context}. The
+ * oldContact validation will be tested for an {@link Context#OLD} context
+ * and the newContact will be tested for a {@link Context#NEW} context.
+ * The validation is tested as validationCompany must be TRUE and
+ * validationProgram must be not FALSE (otherwise TRUE or NULL).
+ *
+ * @param context to check the good contact
+ * @return true depends on validationCompany and validationProgram of
+ * the contact (oldContact or newContact depends on context in argument).
+ */
+ protected boolean isContactValidate(Context context) {
+ Contact contact = context == Context.OLD ? oldContact : newContact;
+
+ Boolean validationCompany = contact != null ?
+ contact.getValidationCompany() : null;
+ Boolean validationProgram = contact != null ?
+ contact.getValidationProgram() : null;
+
+ if (logger.isTraceEnabled()) {
+ logger.trace(context + " validation company = " + validationCompany
+ + " _ validation program = " + validationProgram);
+ }
+
+ boolean contactValidate =
+ BooleanUtils.isTrue(validationCompany) &&
+ BooleanUtils.isNotFalse(validationProgram);
+ return contactValidate;
+ }
+
+ public boolean isRefused() {
+ Boolean oldValidationProgram = oldContact != null ?
+ oldContact.getValidationProgram() : null;
+ Boolean newValidationProgram = newContact != null ?
+ newContact.getValidationProgram() : null;
+
+ return BooleanUtils.isNotFalse(oldValidationProgram) &&
+ BooleanUtils.isFalse(newValidationProgram);
+ }
+
+ public boolean isNoMoreRefused() {
+ Boolean oldValidationProgram = oldContact != null ?
+ oldContact.getValidationProgram() : null;
+ Boolean newValidationProgram = newContact != null ?
+ newContact.getValidationProgram() : null;
+
+ return BooleanUtils.isFalse(oldValidationProgram) &&
+ BooleanUtils.isNotFalse(newValidationProgram);
+ }
+
+ /**
+ * Return true if contact state is {@link ContactState#OBSERVATION_DONE}
+ * depends on {@code context}. To check oldContact state, use
+ * {@link Context#OLD} and to check newContact state, use
+ * {@link Context#NEW}. A null contact will return false.
+ *
+ * @param context to check the good contact
+ * @return true if the contact state is {@link ContactState#OBSERVATION_DONE}
+ */
+ protected boolean isContactDone(Context context) {
+ Contact contact = context == Context.OLD ? oldContact : newContact;
+ ContactState contactState = contact != null ?
+ contact.getContactState() : null;
+
+ if (logger.isTraceEnabled()) {
+ logger.trace(context + " contact state = " + contactState);
+ }
+ boolean contactDone = ContactState.OBSERVATION_DONE.equals(contactState);
+ return contactDone;
+ }
+
+ @Override
+ public String toString() {
+ DateFormat dateFormat = new SimpleDateFormat("MM/yyyy");
+ String oldMonth = oldContact != null &&
+ oldContact.getObservationBeginDate() != null ?
+ dateFormat.format(oldContact.getObservationBeginDate()) : "";
+
+ String newMonth = newContact != null &&
+ newContact.getObservationBeginDate() != null ?
+ dateFormat.format(newContact.getObservationBeginDate()) : "";
+
+ StringBuilder builder =
+ new StringBuilder("\nContactStatus : VALIDATE :: ").
+ append("oldValidate = ").append(isOldContactValidate()).
+ append(" _ newValidate = ").append(isNewContactValidate()).
+ append("\nContactStatus : CONTACT_STATE :: ").
+ append("oldDone = ").append(isOldContactDone()).
+ append(" _ newDone = ").append(isNewContactDone()).
+ append("\nContactStatus : TIDE_BEGIN_DATE :: ").
+ append("oldMonth = ").append(oldMonth).
+ append(" _ newMonth = ").append(newMonth).
+ append(" _ changed = ").append(isTideBeginDateMonthChanged());
+
+ return builder.toString();
+ }
+}
Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactStatus.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java (rev 0)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,50 @@
+package fr.ifremer.wao.services.service;
+
+import com.google.common.base.Charsets;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.mail.EmailException;
+import org.apache.commons.mail.SimpleEmail;
+
+/**
+ * Created on 4/4/14.
+ *
+ * @author Tony Chemit <chemit(a)codelutin.com>
+ * @since 4.0
+ */
+public class EmailService extends WaoServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(EmailService.class);
+
+ public void sendEmail(String to, String subject, String msg)
+ throws EmailException {
+ if (log.isInfoEnabled()) {
+ log.info("Send an email to " + to + " : " + subject);
+ }
+ SimpleEmail email = prepareEmail(to, subject, msg);
+ if (getApplicationConfig().isDevMode()) {
+ log.debug("send email to " + to + " subject " + subject + " msg " + msg);
+ } else {
+ email.send();
+ }
+ }
+
+ public SimpleEmail prepareEmail(String to, String subject, String msg)
+ throws EmailException {
+
+ String smtpFrom = getApplicationConfig().getSmtpFrom();
+ int smtpPort = getApplicationConfig().getSmtpPort();
+ String smtpHost = getApplicationConfig().getSmtpHost();
+
+ SimpleEmail email = new SimpleEmail();
+ email.setHostName(smtpHost);
+ email.setSmtpPort(smtpPort);
+ email.setFrom(smtpFrom);
+ email.addTo(to);
+ email.setSubject(subject);
+ email.setMsg(msg);
+ email.setCharset(Charsets.UTF_8.toString());
+ return email;
+ }
+}
Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/EmailService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ImportErrorException.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ImportErrorException.java 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ImportErrorException.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -30,12 +30,23 @@
*/
public class ImportErrorException extends WaoException {
+ private static final long serialVersionUID = 1L;
+
+ //FIXME ? Why?
protected static final String MESSAGE = I18n.t("wao.import.failure");
public ImportErrorException(ImportRuntimeException e) {
super(e);
}
+ public ImportErrorException(ContactNotValidException e) {
+ super(e);
+ }
+
+ public ImportErrorException(NullSampleMonthException e) {
+ super(e);
+ }
+
@Override
public String getMessage() {
return MESSAGE + " " + getCause().getMessage();
Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/NullSampleMonthException.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/NullSampleMonthException.java (rev 0)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/NullSampleMonthException.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,16 @@
+package fr.ifremer.wao.services.service;
+
+import fr.ifremer.wao.WaoException;
+
+/**
+ * This exception is used to indicate that a problem is occured during
+ * retrieving sampleMonth corresponding to a contact.
+ */
+public final class NullSampleMonthException extends WaoException {
+
+ private static final long serialVersionUID = 1L;
+
+ public NullSampleMonthException(String message) {
+ super(message);
+ }
+}
Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/NullSampleMonthException.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -4,29 +4,56 @@
import com.google.common.collect.ImmutableSet;
import fr.ifremer.wao.ContactsFilter;
import fr.ifremer.wao.WaoTechnicalException;
+import fr.ifremer.wao.WaoUtils;
+import fr.ifremer.wao.entity.Boat;
import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.ContactState;
+import fr.ifremer.wao.entity.ContactStateMotif;
import fr.ifremer.wao.entity.ContactTopiaDao;
+import fr.ifremer.wao.entity.DataReliability;
+import fr.ifremer.wao.entity.ElligibleBoat;
+import fr.ifremer.wao.entity.ElligibleBoatTopiaDao;
+import fr.ifremer.wao.entity.FishingZone;
+import fr.ifremer.wao.entity.ObsProgram;
+import fr.ifremer.wao.entity.ObservedDataControl;
+import fr.ifremer.wao.entity.SampleMonth;
+import fr.ifremer.wao.entity.SampleMonths;
+import fr.ifremer.wao.entity.SampleRow;
+import fr.ifremer.wao.entity.WaoUser;
+import fr.ifremer.wao.entity.WaoUserTopiaDao;
import fr.ifremer.wao.services.AuthenticatedWaoUser;
-import fr.ifremer.wao.services.service.csv.ContactImportExportModel;
+import fr.ifremer.wao.services.service.csv.ObsMerContactImportExportModel;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.mail.EmailException;
import org.nuiton.csv.Export;
import org.nuiton.csv.ExportModel;
import org.nuiton.csv.Import;
import org.nuiton.csv.ImportModel;
import org.nuiton.csv.ImportRuntimeException;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
+import org.nuiton.util.DateUtil;
+import org.nuiton.util.StringUtil;
+import org.nuiton.util.beans.Binder;
+import org.nuiton.util.beans.BinderFactory;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
+import static org.nuiton.i18n.I18n.l;
+
public class ObsMerContactsService extends WaoServiceSupport {
private static final Log log = LogFactory.getLog(ObsMerContactsService.class);
@@ -124,12 +151,11 @@
public InputStream exportContacts(ContactsFilter filter) {
ContactTopiaDao dao = getContactDao();
- List<Contact> sampleRows = dao.findAll(filter);
+ List<Contact> contacts = dao.findAll(filter);
- ExportModel<Contact> exportModel =
- new ContactImportExportModel(filter.getSampleRowFilter().getObsProgram());
+ ExportModel<Contact> exportModel = ObsMerContactImportExportModel.forExport(filter.getSampleRowFilter().getObsProgram());
- Export<Contact> export = Export.newExport(exportModel, sampleRows);
+ Export<Contact> export = Export.newExport(exportModel, contacts);
try {
@@ -144,56 +170,558 @@
}
}
- public void importContacts(AuthenticatedWaoUser authenticatedWaoUser, InputStream csv) throws ImportErrorException {
- ImportModel<Contact> contactImportModel = newContactsImportModel(authenticatedWaoUser);
+ public void importContacts(AuthenticatedWaoUser authenticatedWaoUser,
+ InputStream csv) throws ImportErrorException {
+ ObsProgram obsProgram = authenticatedWaoUser.getObsProgram();
+
+ List<SampleRow> sampleRows =
+ getSampleRowDao().forObsProgramOrdinalEquals(obsProgram.ordinal()).findAll();
+ List<WaoUser> waoUsers = getWaoUserDao().findAll();
+ List<Boat> boats = getBoatDao().findAll();
+ List<ContactStateMotif> motives = getContactStateMotifDao().findAll();
+
+ ImportModel<Contact> contactImportModel =
+ ObsMerContactImportExportModel.forImport(obsProgram,
+ waoUsers,
+ sampleRows,
+ boats,
+ motives);
+
Import<Contact> contactImport = Import.newImport(contactImportModel, csv);
- ContactTopiaDao dao = getContactDao();
-
try {
for (Contact contact : contactImport) {
- //FIXME
- dao.create(contact);
-
+ createOrUpdateContact(authenticatedWaoUser, contact);
}
} catch (ImportRuntimeException e) {
throw new ImportErrorException(e);
+ } catch (ContactNotValidException e) {
+ throw new ImportErrorException(e);
+ } catch (NullSampleMonthException e) {
+ throw new ImportErrorException(e);
}
commit();
}
- //FIXME
- protected ImportModel<Contact> newContactsImportModel(AuthenticatedWaoUser authenticatedWaoUser) {
+ public void save(AuthenticatedWaoUser authenticatedWaoUser, Contact contact)
+ throws EmailException, ContactNotValidException, NullSampleMonthException {
-// ObsProgram obsProgram = authenticatedWaoUser.getObsProgram();
-//
-// CompanyTopiaDao companyDao = getCompanyDao();
-// List<Company> activeCompanies = companyDao.forActiveEquals(true).findAll();
-//
-// TerrestrialLocationTopiaDao terrestrialLocationDao = getTerrestrialLocationDao();
-// List<TerrestrialLocation> terrestrialDistricts =
-// terrestrialLocationDao.forLocationTypeEquals(LocationType.DISTRICT).findAll();
-//
-// FishingZoneTopiaDao fishingZoneDao = getFishingZoneDao();
-// List<FishingZone> fishingZones = fishingZoneDao.findAll();
-//
-// ReferentialService referentialService = getReferentialService();
+ ContactTopiaDao dao = getContactDao();
+ Contact contactFound = dao.findByTopiaId(contact.getTopiaId());
-// ImportModel<Contact> samplingPlanImportModel =
-// new ContactImportExportModel(obsProgram,
-// null,
-// activeCompanies,
-// fishingZones,
-// terrestrialDistricts,
-// referentialService);
-//
-// return samplingPlanImportModel;
- return null;
+ notifyUsersForMammalsObservation(contactFound, contact);
+ // createOrUpdateContact(transaction, contactFound, contact, true);
+ createOrUpdateContact(authenticatedWaoUser, contact);
+
+ commit();
}
+
+ public void delete(Contact contact) throws NullSampleMonthException {
+
+ ContactTopiaDao dao = getContactDao();
+ Contact contactFound = dao.findByTopiaId(contact.getTopiaId());
+
+ // Need to decrement estimated value if contactFound has
+ // OBSERVATION_DONE state and may be real value (normally not allowed)
+ updateSampleMonthTidesValue(contactFound, null, true);
+
+ // Execute delete
+ dao.delete(contactFound);
+
+ commit();
+ }
+
+ /**
+ * The goal of this method is to put in common code that will be executed
+ * while updating a single contact (from UI) and while updating multiple
+ * contacts (from import).
+ *
+ * @param connectedUser user who is modifying the contact
+ * @param contact the contact to save or create
+ * @return true if the contact was successfully updated, false if contact
+ * was not updated due to insufficient right (modifying data as
+ * observer after a validation by administrator)
+ */
+ protected boolean createOrUpdateContact(AuthenticatedWaoUser connectedUser,
+ Contact contact) throws ContactNotValidException, NullSampleMonthException {
+
+ validateContact(contact);
+
+ ContactTopiaDao dao = getContactDao();
+ Contact contactFound = null;
+ if (contact.getTopiaId() != null) {
+ contactFound = dao.findByTopiaId(contact.getTopiaId());
+ }
+
+ // Prevent that someone who is not admin change data that only admin
+ // must be able to modify
+ if (!connectedUser.isAdmin()) {
+ if (contactFound == null) {
+ contact.setCommentAdmin(null);
+ contact.setValidationProgram(null);
+ contact.setDataReliability(DataReliability.UNKNOWN);
+ } else {
+ contact.setCommentAdmin(contactFound.getCommentAdmin());
+ contact.setValidationProgram(contactFound.getValidationProgram());
+ contact.setDataReliability(contactFound.getDataReliability());
+ }
+ }
+
+ boolean contactCanBeUpdated = true;
+ if (contactFound != null && connectedUser.isCoordinatorOrObserver()) {
+ contactCanBeUpdated = contactFound.getValidationProgram() == null;
+ }
+
+ if (contactCanBeUpdated) {
+
+ updateElligibleBoatForContact(contact);
+ updateSampleMonthTidesValue(contactFound, contact, true);
+
+ if (contactFound == null) {
+ if (contact.getCreationDate() == null) {
+ contact.setCreationDate(serviceContext.getNow());
+ }
+ dao.create(contact);
+ } else {
+ Binder<Contact, Contact> contactBinder = BinderFactory.newBinder(Contact.class);
+ contactBinder.copyExcluding(contact, contactFound,
+ Contact.PROPERTY_TOPIA_ID,
+ Contact.PROPERTY_TOPIA_VERSION,
+ Contact.PROPERTY_TOPIA_CREATE_DATE,
+ Contact.PROPERTY_SAMPLE_ROW);
+// contactFound.clearSecondaryObservers();
+// if (contact.getSecondaryObservers() != null) {
+// contactFound.addAllSecondaryObservers(contact.getSecondaryObservers());
+// }
+ dao.update(contactFound);
+ }
+ }
+ return contactCanBeUpdated;
+ }
+
+
+ protected void notifyUsersForMammalsObservation(Contact contactFound, Contact contact) {
+
+ boolean sendNotification = false;
+
+ // we send notifications if there is mammals Capture and
+ // we prevent re-send of multiple identical messages
+ if (contact.isMammalsCapture()) {
+ String oldMessage = null;
+ if (contactFound != null) {
+ oldMessage = contactFound.getMammalsInfo();
+ }
+ boolean messageChanged = ObjectUtils.notEqual(contact.getMammalsInfo(), oldMessage);
+ if (messageChanged) {
+ sendNotification = true;
+ }
+ }
+
+ if (sendNotification) {
+
+ // we will send a mail with a body like
+ //Bonjour,
+ //
+ //Un observateur du programme Obsmer a renseigné dans WAO l'information suivante :
+ //
+ //Marée : 25/10/2010 00:00 - 26/10/2010 00:00
+ //Métier : 2010_0037 Manche Ouest (Manche, Mer du Nord) Secteur Brest Granville centré autour de St malo OTB_DEF 80-90 Chalutage de fond côtier sole, seiche
+ //
+ //Capture accidentelle :
+ //deux tritons et une sirène
+ //
+ //Cordialement,
+ //
+ //Le programme Obsmer
+ //http://www.ifremer.fr/wao
+
+ Locale locale = serviceContext.getLocale();
+
+ String object = l(locale, "wao.business.mammalsCapture.mail.subject");
+
+ // building 2 string, components of the body
+
+ // the time of the capture (it's between tide begin and end)
+ String time = "";
+ if (contact.getObservationBeginDate() != null) {
+ time = WaoUtils.formatDateTime(locale, contact.getObservationBeginDate()) + " ";
+ }
+ if (contact.getObservationEndDate() != null) {
+ time += WaoUtils.formatDateTime(locale, contact.getObservationEndDate());
+ }
+
+ // some details from the sample row, facade, etc.
+ SampleRow sampleRow = contact.getSampleRow();
+ List<String> facadesNames = new ArrayList<String>();
+ for (FishingZone fishingZone : sampleRow.getFishingZone()) {
+ facadesNames.add(fishingZone.getSectorName() + " (" + fishingZone.getFacadeName() + ")");
+ }
+ String profession = sampleRow.getCode() + " "
+ + " " + StringUtil.join(facadesNames, ", ", true)
+ + " " + sampleRow.getFishingZonesInfos()
+ + " " + sampleRow.getProfessionDescription()
+ + " " + sampleRow.getProfession().getLibelle()
+ + " " + sampleRow.getProfession().getSpecies();
+
+ // constructing the whole mail
+ String body = l(locale, "wao.business.mammalsCapture.mail.message",
+ time, profession, contact.getMammalsInfo());
+
+ if (log.isInfoEnabled()) {
+ log.info("will send email with object '" + object + "' and body \n" + body);
+ }
+
+ // now trying to find to what user we need to send the mail
+ WaoUserTopiaDao userDao = getWaoUserDao();
+ // users contains all the user we need to notify for the capture
+ List<WaoUser> waoUsers = userDao.forMammalsNotificationsEquals(true).findAll();
+
+ if (log.isDebugEnabled()) {
+ log.debug("notification will be sent to " + waoUsers.size() + " users");
+ }
+
+ // sending the same e-mail to all of them
+ for (WaoUser waoUser : waoUsers) {
+ String userLogin = waoUser.getLogin();
+ if (StringUtil.isEmail(userLogin)) {
+ try {
+ EmailService emailService = newService(EmailService.class);
+ emailService.sendEmail(userLogin, object, body);
+ if (log.isInfoEnabled()) {
+ log.info("email sent to " + userLogin);
+ }
+ } catch (EmailException e) {
+ if (log.isErrorEnabled()) {
+ log.error("unable to send email to " + userLogin, e);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Update the SampleMonth data for tidesValue (estimated and real) from
+ * {@code contact} compared to its old state {@code oldContact}. The
+ * estimated is update when contact state {@link ContactState#OBSERVATION_DONE}
+ * is changed. The real is update when contact validationCompany is changed.
+ * The {@code calculateReal} flag determines if the real tides has to be
+ * calculated or not. Three cases :
+ * <ul>
+ * <li>CREATE : {@code oldContact} = null and {@code contact} is defined</li>
+ * <li>UPDATE : both {@code oldContact} and {@code contact} are defined</li>
+ * <li>DELETE : {@code oldContact} is defined and {@code contact} = null</li>
+ * </ul>
+ * <p>
+ * <strong>Estimated Tides value</strong> = nbContacts with OBSERVATION_DONE
+ * state and not refused by program (validationProgram != FALSE)
+ * </p>
+ * <p>
+ * <strong>Real Tides value</strong> = nbContacts accepted by company
+ * (validationCompany = TRUE) and not refused by program
+ * (validationProgram != FALSE)
+ * </p>
+ *
+ * @param oldContact old state of the contact
+ * @param contact changed can be null for delete case
+ * @param calculateReal to calculate real tides value
+ * @throws NullSampleMonthException if SampleMonth can't be found
+ */
+ protected void updateSampleMonthTidesValue(Contact oldContact,
+ Contact contact,
+ boolean calculateReal) throws NullSampleMonthException {
+
+ if (oldContact == null && contact == null) {
+ throw new IllegalArgumentException("Both contact and oldContact" +
+ " can't be null to update sampleMonth tides value");
+ }
+
+ // Instantiate contact status which provide status on oldContact and
+ // contact changes
+ ContactStatus status = new ContactStatus(getSampleMonthDao(), oldContact, contact);
+
+ if (log.isDebugEnabled()) {
+ log.debug(status.toString());
+ }
+
+ // Month of TideBeginDate has changed, must decrement values on
+ // old sampleMonth
+ boolean tideBeginDateChanged = false;
+ if (oldContact != null && contact != null &&
+ status.isTideBeginDateMonthChanged()) {
+
+ tideBeginDateChanged = status.isTideBeginDateMonthChanged();
+
+ // Retrieve oldMonth from status
+ try {
+ SampleMonth oldMonth = status.getOldSampleMonth();
+
+ // Apply changes on oldMonth
+ if (status.isOldContactValidate()) {
+ // decrement real tides
+ SampleMonths.addRealTideTime(oldMonth, -1);
+ }
+ // Decrement estimated only if old state is OBSERVATION_DONE
+ // and old validationProgram is NOT FALSE
+ // the estimated value has already been decremented during
+ // refused
+ if (status.isOldContactDone() && BooleanUtils.isNotFalse(
+ oldContact.getValidationProgram())) {
+ // decrement estimated tides
+ SampleMonths.addEstimatedTideTime(oldMonth, -1);
+ }
+
+ // Catch the null exception, only a warning if the oldSampleMonth is
+ // not found
+ } catch (NullSampleMonthException eee) {
+ if (log.isWarnEnabled()) {
+ log.warn("Error on retrieve old sampleMonth", eee);
+ }
+ }
+ }
+
+ ContactState currentState = contact != null ?
+ contact.getContactState() : oldContact.getContactState();
+
+ // Validation of contact has changed in status, modify realTides
+ // Only calculate real for a currentState equals to OBSERVATION_DONE
+ if (calculateReal && ContactState.OBSERVATION_DONE.equals(currentState) &&
+ (status.isContactValidateChanged() || tideBeginDateChanged)) {
+
+ SampleMonth sampleMonth = status.getSampleMonth();
+
+ if (status.isNewContactValidate()) {
+ // increment real tides
+ SampleMonths.addRealTideTime(sampleMonth, 1);
+ // validationProgram becomes not FALSE, estimatedTides must be
+ // incremented
+ if (status.isNoMoreRefused()) {
+ SampleMonths.addEstimatedTideTime(sampleMonth, 1);
+ }
+ // never decrement if tideBeginDate has changed
+ } else if (status.isOldContactValidate() && !tideBeginDateChanged) {
+ // decrement real tides
+ SampleMonths.addRealTideTime(sampleMonth, -1);
+ // validationProgram becomes FALSE, estimatedTides must be
+ // decremented
+ if (status.isRefused()) {
+ SampleMonths.addEstimatedTideTime(sampleMonth, -1);
+ }
+ }
+ }
+
+ // ContactState of contact has changed in status, modify estimatedTides
+ if (status.isContactDoneChanged() || tideBeginDateChanged) {
+
+ SampleMonth sampleMonth = status.getSampleMonth();
+
+ if (status.isNewContactDone()) {
+ // increment estimated tides
+ SampleMonths.addEstimatedTideTime(sampleMonth, 1);
+ // never decrement if tideBeginDate has changed
+ } else if (status.isOldContactDone() && !tideBeginDateChanged) {
+ // decrement estimated tides
+ SampleMonths.addEstimatedTideTime(sampleMonth, -1);
+ }
+ }
+ }
+
+ protected void validateContact(Contact contact) throws ContactNotValidException {
+
+ Locale l = serviceContext.getLocale();
+
+ Contact oldContact = null;
+ if (contact.getTopiaId() != null) {
+ oldContact = getContactDao().findByTopiaId(contact.getTopiaId());
+ }
+
+ // S'il s'agit de dé-valider pour le coordinateur ou l'administrateur
+ // on ne fait aucun contrôle
+ boolean skip = oldContact != null
+ && oldContact.getValidationProgram() != null &&
+ contact.getValidationProgram() == null;
+
+ if (skip) {
+ return;
+ }
+
+ if (contact.getMainObserver() == null) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.missing.main.observer"));
+ }
+
+ if (contact.getSecondaryObservers() != null &&
+ contact.getSecondaryObservers().contains(contact.getMainObserver())) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.mainObserver.cant.be.secondaryObserver"));
+ }
+
+ for (WaoUser observer : contact.getAllObservers()) {
+ boolean observerWorksForCompanyInSampleRow = observer.getCompany().equals(contact.getSampleRow().getCompany());
+ if (!observerWorksForCompanyInSampleRow) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.company.for.observer",
+ observer.getLogin(), contact.getSampleRow().getCompany().getName()));
+ }
+ }
+
+ // Validation for saving contact depends on contactState
+ ContactState contactState = contact.getContactState();
+ Date observationBeginDate = contact.getObservationBeginDate();
+ if (log.isDebugEnabled()) {
+ log.debug("For state : " + contactState + " and observation begin date " + observationBeginDate);
+ }
+
+ // need the sample months to be loaded, it's never the case :-(
+ // boolean operationBeginDateIsValid = contact.getSampleRow().isValid(observationBeginDate);
+
+ String sampleRowCode = contact.getSampleRow().getCode();
+ SampleRow sampleRow = getSampleRowDao().forCodeEquals(sampleRowCode).findAny();
+
+ SampleMonth month = sampleRow.getSampleMonth(observationBeginDate);
+ boolean operationBeginDateIsValid = month != null;
+
+ if (log.isDebugEnabled()) {
+ log.debug("operation begin data is valid : " + operationBeginDateIsValid);
+ }
+
+ if (observationBeginDate != null && !operationBeginDateIsValid) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.trip.beginDate",
+ contact.getSampleRow().getCode()));
+ }
+
+ Date observationEndDate = contact.getObservationEndDate();
+ if (observationBeginDate != null && observationEndDate != null
+ && observationEndDate.before(observationBeginDate)) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.observation.endDate"));
+ }
+
+ Date dataInputDate = contact.getDataInputDate();
+ // Here, we check that the date input date is after the end of the
+ // observation. Since the first is a day (at 00:00) and the second
+ // is date-time, there may be a bug if the data input day is the same
+ // as the end of observation
+ boolean observationEndDateIsBeforeDataInputDate =
+ observationEndDate == null
+ || dataInputDate == null
+ || observationEndDate.before(DateUtil.setMaxTimeOfDay(dataInputDate));
+
+ if (log.isDebugEnabled()) {
+ log.debug("observationEndDate = " + observationEndDate +
+ ", dateInputDate = " + dataInputDate + ", observationEndDateIsBeforeDataInputDate = "
+ + observationEndDateIsBeforeDataInputDate);
+ }
+ if (!observationEndDateIsBeforeDataInputDate) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.observation.end"));
+ }
+
+ Date currentDate = serviceContext.getNow();
+ if (observationEndDate != null && observationEndDate.after(currentDate)) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.trip.endDate"));
+ }
+
+ if (dataInputDate != null && dataInputDate.after(currentDate)) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.observation.end2"));
+ }
+
+ // Non abouti
+ if (contactState == ContactState.OBSERVATION_CANCELLED && StringUtils.isBlank(contact.getComment())) {
+ throw new ContactNotValidException(l(l, "wao.business.contact.validation.commentMissingForState",
+ contact.getContactState().toString()));
+ // Observation réalisée
+ } else if (contactState.equals(ContactState.OBSERVATION_DONE)) {
+
+ if (observationBeginDate == null) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.missing.trip.beginDate", contactState));
+ }
+ if (observationEndDate == null) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.missing.observation.endDate", contactState));
+ }
+ if (contact.getNbObservants() == 0) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.observer.state", contactState));
+ }
+ if (contact.getObsProgram() == ObsProgram.OBSVENTE) {
+ if (contact.getTerrestrialLocation() == null) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.missing.observationArea"));
+ }
+ }
+ }
+
+ // Ici, les contrôle spécifique à ObsMer
+ if (contact.getObsProgram() == ObsProgram.OBSMER) {
+
+ boolean contactMustHaveAMotif = contact.getObsProgram() == ObsProgram.OBSMER
+ && (contactState == ContactState.CONTACT_REFUSED
+ || contactState == ContactState.CONTACT_DEFINITELY_REFUSED);
+ if (contactMustHaveAMotif && contact.getContactStateMotif() == null) {
+ throw new ContactNotValidException(l(l, "wao.business.contact.validation.contactStateMotifMissing"));
+ }
+
+ if (!contactMustHaveAMotif && contact.getContactStateMotif() != null) {
+ throw new ContactNotValidException(l(l, "wao.business.contact.validation.contactStateMotifUnwanted"));
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("validationProgram = " + contact.getValidationProgram());
+ }
+
+ if (BooleanUtils.isTrue(contact.getValidationCompany())) {
+ // Pour valider un contact société, il faut que le contact aie une date de transmission
+ if (contact.getContactState() == ContactState.OBSERVATION_DONE && contact.getObservedDataControl() == null) {
+ throw new ContactNotValidException(l(l, "wao.business.contact.validation.observedDataControlMissingForValidation"));
+ }
+ if (contact.getObservedDataControl() == ObservedDataControl.ACCEPTED && contact.getRestitution() == null) {
+ throw new ContactNotValidException(l(l, "wao.business.contact.validation.restitutionMissingForValidation"));
+ }
+ if (contact.getDataInputDate() == null && contact.getRestitution() != null) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.missing.observationDate"));
+ }
+ if (contact.getDataInputDate() != null && contact.getRestitution() != null && contact.getRestitution().before(contact.getDataInputDate())) {
+ throw new ContactNotValidException(l(l, "wao.import.contact.failure.invalid.transmissionDate"));
+ }
+ }
+
+ if (BooleanUtils.isTrue(contact.getValidationProgram())) {
+ // it's an admin validation, data-reliability field must be filled
+ if (log.isDebugEnabled()) {
+ log.debug("field data reliability is " + contact.getDataReliability());
+ }
+
+ if (contact.getDataReliability() == null ||
+ contact.getDataReliability() == DataReliability.UNKNOWN) {
+ throw new ContactNotValidException(l(l, "wao.business.contact.validation.dataReliabilityMissingForValidation"));
+ } else if (contact.getDataReliability() != DataReliability.RELIABLE
+ && StringUtils.isEmpty(contact.getCommentAdmin())) {
+ throw new ContactNotValidException(l(l, "wao.business.contact.validation.commentAdminNecessaryForDataReliability",
+ contact.getDataReliability().toString()));
+ }
+ }
+ }
+ }
+
+ /**
+ * Update the elligible boat depends on contact creation. The
+ * {@code contact} reference can only be created for a sampleRow and a
+ * boat if both are linked with an elligibleBoat. So this method is
+ * used to create the link if needed during contacts import. This
+ * elligibleBoat is needed for the contact owned by a company, so
+ * the companyActive property of ElligibleBoat will be set to TRUE. No
+ * admin has decided to explicitly create this link.
+ *
+ * @param contact which contains sampleRow and boat to link
+ */
+ protected void updateElligibleBoatForContact(Contact contact) {
+
+ ElligibleBoatTopiaDao elligibleDAO = getElligibleBoatDao();
+ ElligibleBoat elligible = elligibleDAO.findUniqueOrNull(contact);
+
+ if (elligible == null) {
+ // Create new elligible boat not active in a global way
+ elligible = elligibleDAO.create(contact);
+ }
+ elligible.setCompanyActive(Boolean.TRUE);
+ }
}
Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java (from rev 1830, trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java)
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java (rev 0)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,222 @@
+/*
+ * #%L
+ * Wao :: Business
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2009 - 2011 Ifremer
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.wao.services.service.csv;
+
+import com.google.common.base.Preconditions;
+import fr.ifremer.wao.entity.Boat;
+import fr.ifremer.wao.entity.Company;
+import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.ContactImpl;
+import fr.ifremer.wao.entity.ContactState;
+import fr.ifremer.wao.entity.ContactStateMotif;
+import fr.ifremer.wao.entity.DataReliability;
+import fr.ifremer.wao.entity.ObsProgram;
+import fr.ifremer.wao.entity.SampleRow;
+import fr.ifremer.wao.entity.WaoUser;
+import fr.ifremer.wao.services.service.csv.operations.BoatParserFormatter;
+import fr.ifremer.wao.services.service.csv.operations.CompanyParserFormatter;
+import fr.ifremer.wao.services.service.csv.operations.ContactStateMotivesParserFormatter;
+import fr.ifremer.wao.services.service.csv.operations.ObservedDataControlParserFormatter;
+import fr.ifremer.wao.services.service.csv.operations.SampleRowParserFormatter;
+import fr.ifremer.wao.services.service.csv.operations.UserParserFormatter;
+import fr.ifremer.wao.services.service.csv.operations.UsersParserFormatter;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.csv.Common;
+import org.nuiton.csv.ExportableColumn;
+import org.nuiton.csv.ImportExportModel;
+import org.nuiton.csv.ImportableColumn;
+import org.nuiton.csv.ModelBuilder;
+import org.nuiton.csv.ValueFormatter;
+import org.nuiton.csv.ValueGetter;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class ObsMerContactImportExportModel implements ImportExportModel<Contact> {
+
+ protected ObsProgram obsProgram;
+
+ protected List<WaoUser> waoUsers;
+
+ protected List<SampleRow> sampleRows;
+
+ protected List<Boat> boats;
+
+ protected List<ContactStateMotif> motives;
+
+ public static ObsMerContactImportExportModel forExport(ObsProgram obsProgram) {
+ return new ObsMerContactImportExportModel(obsProgram, null, null, null, null);
+ }
+
+ public static ObsMerContactImportExportModel forImport(ObsProgram obsProgram,
+ List<WaoUser> waoUsers,
+ List<SampleRow> sampleRows,
+ List<Boat> boats,
+ List<ContactStateMotif> motives) {
+
+ Preconditions.checkState(waoUsers != null, "To import must have waoUsers");
+ Preconditions.checkState(boats != null, "To import must have boats");
+ Preconditions.checkState(sampleRows != null, "To import must have sampleRows");
+ Preconditions.checkState(motives != null, "To import must have motives");
+ return new ObsMerContactImportExportModel(obsProgram, waoUsers, sampleRows, boats, motives);
+ }
+
+ protected ObsMerContactImportExportModel(ObsProgram obsProgram,
+ List<WaoUser> waoUsers,
+ List<SampleRow> sampleRows,
+ List<Boat> boats,
+ List<ContactStateMotif> motives) {
+ this.obsProgram = obsProgram;
+ this.waoUsers = waoUsers;
+ this.sampleRows = sampleRows;
+ this.boats = boats;
+ this.motives = motives;
+ }
+
+ @Override
+ public char getSeparator() {
+ return ';';
+ }
+
+ @Override
+ public void pushCsvHeaderNames(List<String> headerNames) {
+ // nothing to do
+ }
+
+ @Override
+ public Contact newEmptyInstance() {
+ Contact newContact = new ContactImpl();
+ newContact.setObsProgram(obsProgram);
+ return newContact;
+ }
+
+ public ModelBuilder<Contact> getExportModel() {
+ return getModel();
+ }
+
+ public ModelBuilder<Contact> getImportModel() {
+ Preconditions.checkState(sampleRows != null, "To import must have sampleRows");
+ Preconditions.checkState(waoUsers != null, "To import must have waoUsers");
+ Preconditions.checkState(boats != null, "To import must have boats");
+ Preconditions.checkState(motives != null, "To import must have motives");
+ return getModel();
+ }
+
+ protected ModelBuilder<Contact> getModel() {
+ ModelBuilder<Contact> modelBuilder = new ModelBuilder<>();
+ modelBuilder.newColumnForImportExport("CONTACT_ID", Contact.PROPERTY_TOPIA_ID);
+ modelBuilder.newColumnForImportExport("CONTACT_DATE_CREATION", Contact.PROPERTY_CREATION_DATE, Common.DAY_TIME);
+ if (waoUsers != null) {
+ modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEUR_PRINCIPAL", Contact.PROPERTY_MAIN_OBSERVER, new UserParserFormatter(waoUsers));
+ modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(waoUsers));
+ }
+
+ modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_NOMS");
+ modelBuilder.newColumnForExport(
+ "CONTACT_OBSERVATEURS_NOMS",
+ "allObservers",
+ new ValueFormatter<List<WaoUser>>() {
+ @Override
+ public String format(List<WaoUser> value) {
+ List<String> fullNames = new LinkedList<>();
+ for (WaoUser waoUser : value) {
+ fullNames.add(waoUser.getFullName());
+ }
+ return StringUtils.join(fullNames, ", ");
+ }
+ }
+ );
+ modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_SOCIETE");
+ modelBuilder.newColumnForExport(
+ "CONTACT_OBSERVATEURS_SOCIETE",
+ new ValueGetter<Contact, Company>() {
+ @Override
+ public Company get(Contact contact) {
+ return contact.getMainObserver().getCompany();
+ }
+ },
+ new CompanyParserFormatter(null)
+ );
+ modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new Common.ToStringParserFormatter(ContactState.getAllowedStates(obsProgram)));
+ modelBuilder.newColumnForImportExport("CONTACT_DEBUT_OBSERVATION", Contact.PROPERTY_OBSERVATION_BEGIN_DATE, Common.DAY_TIME);
+ modelBuilder.newColumnForImportExport("CONTACT_FIN_OBSERVATION", Contact.PROPERTY_OBSERVATION_END_DATE, Common.DAY_TIME);
+ modelBuilder.newColumnForImportExport("CONTACT_SAISIE_DONNEES", Contact.PROPERTY_DATA_INPUT_DATE, Common.DAY);
+ modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_OBSERVATEUR", Contact.PROPERTY_COMMENT);
+ modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_COORDINATEUR", Contact.PROPERTY_COMMENT_COORDINATOR);
+ modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_PROGRAMME", Contact.PROPERTY_COMMENT_ADMIN);
+
+ if (boats != null) {
+ modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats));
+ }
+ modelBuilder.newIgnoredColumn("NAVIRE_NOM");
+ modelBuilder.newColumnForExport("NAVIRE_NOM", new ValueGetter<Contact, String>() {
+ @Override
+ public String get(Contact contact) throws Exception {
+ return contact.getBoat().getName();
+ }
+ });
+ modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_SOCIETE", Contact.PROPERTY_VALIDATION_COMPANY, Common.BOOLEAN);
+ modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_PROGRAMME", Contact.PROPERTY_VALIDATION_PROGRAM, Common.BOOLEAN);
+
+ if (sampleRows != null) {
+ modelBuilder.newColumnForImportExport("PLAN_CODE", Contact.PROPERTY_SAMPLE_ROW, new SampleRowParserFormatter(sampleRows));
+ }
+
+ modelBuilder.newColumnForImportExport("CONTACT_QUALITE_DONNEE", "dataReliability",
+ new Common.ToStringParserFormatter<>(DataReliability.values()));
+ modelBuilder.newColumnForImportExport("CONTACT_OBSERVATION_MAMMIFERE", Contact.PROPERTY_MAMMALS_OBSERVATION, Common.BOOLEAN);
+ modelBuilder.newColumnForImportExport("CONTACT_CAPTURE_ACCIDENTELLE", Contact.PROPERTY_MAMMALS_CAPTURE, Common.BOOLEAN);
+ modelBuilder.newIgnoredColumn("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS");
+ modelBuilder.newColumnForExport("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS", Contact.PROPERTY_MAMMALS_INFO);
+ if (motives != null) {
+ modelBuilder.newColumnForImportExport("CONTACT_ETAT_MOTIF_CODE", Contact.PROPERTY_CONTACT_STATE_MOTIF, new ContactStateMotivesParserFormatter(motives));
+ }
+ modelBuilder.newIgnoredColumn("CONTACT_ETAT_MOTIF_NOM");
+ modelBuilder.newColumnForExport("CONTACT_ETAT_MOTIF_NOM", new ValueGetter<Contact, String>() {
+ @Override
+ public String get(Contact contact) throws Exception {
+ String name = "";
+ if (contact.getContactStateMotif() != null) {
+ name = contact.getContactStateMotif().getName();
+ }
+ return name;
+ }
+ });
+ modelBuilder.newColumnForImportExport("CONTACT_TRANSMISSION_RESTITUTION", Contact.PROPERTY_RESTITUTION, Common.DAY);
+ modelBuilder.newColumnForImportExport("CONTACT_DONNEES_ALLEGRO_VALIDEES", Contact.PROPERTY_OBSERVED_DATA_CONTROL, new ObservedDataControlParserFormatter());
+
+ return modelBuilder;
+ }
+
+ @Override
+ public Iterable<ExportableColumn<Contact, Object>> getColumnsForExport() {
+ return (Iterable) getModel().getColumnsForExport();
+ }
+
+ @Override
+ public Iterable<ImportableColumn<Contact, Object>> getColumnsForImport() {
+ return (Iterable) getModel().getColumnsForImport();
+ }
+
+}
Modified: trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties
===================================================================
--- trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-04-04 15:37:35 UTC (rev 1837)
@@ -34,7 +34,22 @@
wao.export.ical.title=ObsDeb Observation
wao.import.contact.failure.boatMissing=You need to precise the plate number of the boat associated to the contact
wao.import.contact.failure.districtMissing=You need to precise the boat district
+wao.import.contact.failure.invalid.company.for.observer=L'observateur %s n'est pas membre de la société %s
+wao.import.contact.failure.invalid.observation.end=La date de saisie des données ne peut pas être antérieure à la date de fin d'observation
+wao.import.contact.failure.invalid.observation.end2=La date de saisie des données ne peut pas être postérieure à la date du jour
+wao.import.contact.failure.invalid.observation.endDate=La date de fin d'observation ne peut pas être antérieure à celle du début
+wao.import.contact.failure.invalid.observer.state=Il ne peut y avoir aucun observateur pour l'état '%s'
+wao.import.contact.failure.invalid.transmissionDate=Il faut que la date de transmission de la restitution soit après la date de saisie des données
+wao.import.contact.failure.invalid.trip.beginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne
+wao.import.contact.failure.invalid.trip.endDate=La date de fin de la marée ne peut pas être postérieure à la date du jour
wao.import.contact.failure.locationTypeMissing=The type of the location must be filled
+wao.import.contact.failure.mainObserver.cant.be.secondaryObserver=
+wao.import.contact.failure.mainObserver.cant.be.secondaryObserver.=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires
+wao.import.contact.failure.missing.main.observer=Il faut au moins un observateur référant
+wao.import.contact.failure.missing.observation.endDate=La date de fin d'observation est obligatoire pour l'état '%s'
+wao.import.contact.failure.missing.observationArea=Il faut préciser un lieu d'observation
+wao.import.contact.failure.missing.observationDate=Il faut préciser une date de saisie des données en plus de la date de transmission de la restitution
+wao.import.contact.failure.missing.trip.beginDate=La date de début de marée est obligatoire pour l'état '%s'
wao.import.contact.failure.sampleRowCodeMissing=The code of the sample row line is missing
wao.import.contact.failure.terrestrialLocationMissing=The code of the terrestrial location is missing
wao.import.contact.failure.wrongBoat=There is no boat with plate number '%s'
Modified: trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties
===================================================================
--- trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-04-04 15:37:35 UTC (rev 1837)
@@ -33,7 +33,22 @@
wao.export.ical.title=Observation ObsDeb
wao.import.contact.failure.boatMissing=Il faut préciser l'immatriculation du navire associé au contact
wao.import.contact.failure.districtMissing=Il faut préciser le code d'un quartier maritime
+wao.import.contact.failure.invalid.company.for.observer=L'observateur %s n'est pas membre de la société %s
+wao.import.contact.failure.invalid.observation.end=La date de saisie des données ne peut pas être antérieure à la date de fin d'observation
+wao.import.contact.failure.invalid.observation.end2=La date de saisie des données ne peut pas être postérieure à la date du jour
+wao.import.contact.failure.invalid.observation.endDate=La date de fin d'observation ne peut pas être antérieure à celle du début
+wao.import.contact.failure.invalid.observer.state=Il ne peut y avoir aucun observateur pour l'état '%s'
+wao.import.contact.failure.invalid.transmissionDate=Il faut que la date de transmission de la restitution soit après la date de saisie des données
+wao.import.contact.failure.invalid.trip.beginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne
+wao.import.contact.failure.invalid.trip.endDate=La date de fin de la marée ne peut pas être postérieure à la date du jour
wao.import.contact.failure.locationTypeMissing=Le type du lieu doit être renseigné
+wao.import.contact.failure.mainObserver.cant.be.secondaryObserver=
+wao.import.contact.failure.mainObserver.cant.be.secondaryObserver.=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires
+wao.import.contact.failure.missing.main.observer=Il faut au moins un observateur référant
+wao.import.contact.failure.missing.observation.endDate=La date de fin d'observation est obligatoire pour l'état '%s'
+wao.import.contact.failure.missing.observationArea=Il faut préciser un lieu d'observation
+wao.import.contact.failure.missing.observationDate=Il faut préciser une date de saisie des données en plus de la date de transmission de la restitution
+wao.import.contact.failure.missing.trip.beginDate=La date de début de marée est obligatoire pour l'état '%s'
wao.import.contact.failure.sampleRowCodeMissing=Il manque le code de la ligne de plan associée
wao.import.contact.failure.terrestrialLocationMissing=Il manque le code du lieu
wao.import.contact.failure.wrongBoat=Il n'y a pas de navire avec l'immatriculation '%s'
Modified: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java
===================================================================
--- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java 2014-04-04 15:37:35 UTC (rev 1837)
@@ -24,7 +24,7 @@
}
@Test
- public void testGetBoatsFilterValues() {
+ public void testGetContactsFilterValues() {
ContactsFilter filter = service.newContactFilter(fixtures.admin());
@@ -32,7 +32,7 @@
}
@Test
- public void testGetBoatsList() {
+ public void testGetContactsList() {
ContactsFilter filter = service.newContactFilter(fixtures.admin());
Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp
===================================================================
--- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp 2014-04-04 15:37:35 UTC (rev 1837)
@@ -246,7 +246,7 @@
<i class="icon-download"></i> <s:text name="wao.ui.action.csvExport"/>
</s:submit>
- <s:submit action="import-contacts" type="button" cssClass="btn">
+ <s:submit action="import-contacts" method="input" type="button" cssClass="btn">
<i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/>
</s:submit>
@@ -304,7 +304,8 @@
</div>
<s:set var="fullView" value="%{fullView}"/>
<s:if test="authenticatedWaoUser.admin">
- <button type="button" id="switch-compact-full-view" class="btn <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>">
+ <button type="button" id="switch-compact-full-view"
+ class="btn <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>">
<span class="only-in-compact-view">
<i class="icon-resize-full"></i> <s:text name="wao.ui.action.switchToFullView"/>
</span>
@@ -317,19 +318,19 @@
<thead>
<tr>
<th><s:text name="wao.ui.field.Contact.creationDate"/></th>
- <th><s:text name="wao.ui.contacts.observers"/></th>
- <th><s:text name="wao.ui.field.SampleRow.company"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.contacts.observers"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.company"/></th>
<th><s:text name="wao.ui.field.Contact.sampleRow"/></th>
- <th><s:text name="wao.ui.field.SampleRow.programName"/></th>
- <th><s:text name="wao.ui.field.SampleRow.professionCode"/></th>
- <th><s:text name="wao.ui.field.Profression.libelle"/></th>
- <th><s:text name="wao.ui.field.SampleRow.species"/></th>
- <th><s:text name="wao.ui.field.FishingZone.facadeName"/></th>
- <th><s:text name="wao.ui.field.FishingZone.sectorName"/></th>
- <th><s:text name="wao.ui.contacts.division"/></th>
- <th><s:text name="wao.ui.field.Boat.name"/></th>
- <th><s:text name="wao.ui.field.Boat.immatriculation"/></th>
- <th><s:text name="wao.ui.field.Boat.district"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.programName"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.professionCode"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.Profression.libelle"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.species"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.FishingZone.facadeName"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.FishingZone.sectorName"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.contacts.division"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.Boat.name"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.Boat.immatriculation"/></th>
+ <th class="only-in-full-view"><s:text name="wao.ui.field.Boat.district"/></th>
<th><s:text name="wao.ui.field.Contact.contactState"/></th>
<th><s:text name="wao.ui.field.Contact.contactStateMotif"/></th>
<th><s:text name="wao.ui.field.Contact.beginDate"/></th>
@@ -351,213 +352,213 @@
<s:iterator value="contacts" var="contact">
<tr class="contact-row">
- <td>
- <s:property value="%{formatDate(creationDate)}"/>
- </td>
- <td>
- <s:if test="secondaryObserversEmpty">
- <s:property value="mainObserver.fullName"/>
- </s:if>
- <s:else>
- <s:property value="mainObserver.fullName"/>...
- <%--TODO<s:text name="wao.ui.field.Contact.secondaryObservers"><s:param value="secondaryObservers"/></s:text>--%>
- </s:else>
+<td>
+ <s:property value="%{formatDate(creationDate)}"/>
+</td>
+<td class="only-in-full-view">
+ <s:if test="secondaryObserversEmpty">
+ <s:property value="mainObserver.fullName"/>
+ </s:if>
+ <s:else>
+ <s:property value="mainObserver.fullName"/>...
+ <%--TODO<s:text name="wao.ui.field.Contact.secondaryObservers"><s:param value="secondaryObservers"/></s:text>--%>
+ </s:else>
- </td>
- <td>
- <s:property value="sampleRow.company.name"/>
- </td>
- <td>
- <s:property value="sampleRow.code"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="sampleRow.company.name"/>
+</td>
+<td>
+ <s:property value="sampleRow.code"/>
<%--TODO<s:property value="%{getTooltipSampleRow(sampleRow)}"/>--%>
- </td>
- <td>
- <s:property value="sampleRow.programName"/>
- </td>
- <td>
- <s:property value="sampleRow.professionDescription"/>
- </td>
- <td>
- <s:property value="sampleRow.profession.libelle"/>
- </td>
- <td>
- <s:property value="sampleRow.profession.species"/>
- </td>
- <td>
- <s:property value="sampleRow.facade"/>
- </td>
- <td>
- <s:property value="sampleRow.sectors"/>
- </td>
- <td>
- <s:property value="%{getDivision(sampleRow)}"/>
- </td>
- <td>
- <s:property value="boat.name"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="sampleRow.programName"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="sampleRow.professionDescription"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="sampleRow.profession.libelle"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="sampleRow.profession.species"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="sampleRow.facade"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="sampleRow.sectors"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="%{getDivision(sampleRow)}"/>
+</td>
+<td>
+ <s:property value="boat.name"/>
<%--TODO <s:property value="%{getTooltipBoat(boat)}"/>--%>
- </td>
- <td>
- <s:property value="%{'' + boat.immatriculation}"/>
- </td>
- <td>
- <s:property value="boat.districtCode"/>
- </td>
- <td>
- <s:if test="contactStateMotif != null">
- <s:text name="%{contactState.i18nKey}"/>
- <%--TODO <s:text name="wao.ui.field.Contact.contactStateMotif"><s:param value="%{contactStateMotif.name}"/></s:text>--%>
+</td>
+<td class="only-in-full-view">
+ <s:property value="%{'' + boat.immatriculation}"/>
+</td>
+<td class="only-in-full-view">
+ <s:property value="boat.districtCode"/>
+</td>
+<td>
+ <s:if test="contactStateMotif">
+ <s:text name="%{contactState.i18nKey}"/>
+ <%--TODO <s:text name="wao.ui.field.Contact.contactStateMotif"><s:param value="%{contactStateMotif.name}"/></s:text>--%>
+ </s:if>
+ <s:else>
+ <s:text name="%{contactState.i18nKey}"/>
+ </s:else>
+</td>
+<td>
+ <s:if test="contactStateMotif">
+ <s:property value="contactStateMotif.name"/>
+ </s:if>
+</td>
+<td>
+ <s:if test="observationBeginDate">
+ <s:property value="%{formatDateTime(observationBeginDate)}"/>
+ </s:if>
+</td>
+<td>
+ <s:if test="observationEndDate">
+ <s:property value="%{formatDateTime(observationEndDate)}"/>
+ </s:if>
+</td>
+<td>
+ <s:property value="nbObservants"/>
+</td>
+<td>
+ <s:if test="mammalsObservation">
+ <img src="<s:url value="/img/eye-22px.png"/>"
+ alt="<s:text name="wao.ui.field.Contact.mammalsObservation"/>"/>
+ </s:if>
+ <s:if test="mammalsCapture">
+ <s:if test="mammalsInfo">
+ <img src="<s:url value="fishing-net-22px.png"/>"
+ alt="<s:text name="wao.ui.field.Contact.mammalsCapture"/>"/>
+ <%--TODO<s:text name="wao.ui.field.Contact.mammalsInfo"><s:param value="%{getMammalsInfo(#contact)}"/></s:text>--%>
</s:if>
<s:else>
- <s:text name="%{contactState.i18nKey}"/>
+ <img src="<s:url value="fishing-net-22px.png"/>"
+ alt="<s:text name="wao.ui.field.Contact.mammalsCapture"/>"/>
</s:else>
- </td>
- <td>
- <s:if test="contactStateMotif">
- <s:property value="contactStateMotif.name"/>
+ </s:if>
+</td>
+<td>
+ <s:if test="comment">
+ <s:property value="%{getCommentDisplayText(comment)}"/>
+ <%--TODO<s:text name="wao.ui.misc.comment"><s:param value="%{getTooltipText(comment)}"/></s:text>--%>
+ </s:if>
+</td>
+<td>
+ <s:if test="dataInputDate">
+ <s:property value="%{formatDate(dataInputDate)}"/>
+ </s:if>
+</td>
+<td>
+ <s:if test="observedDataControl">
+ <s:text name="%{observedDataControl.i18nKey}"/>
+ </s:if>
+</td>
+<td>
+ <s:if test="restitution">
+ <s:property value="%{formatDate(restitution)}"/>
+ </s:if>
+</td>
+<td>
+ Validation
+ <s:property value=""/>
+ <%--<t:booleanImage t:value="contact.validationCompany" t:empty="isEmpty(contact.validationCompany)"--%>
+ <%--t:emptyTitle="${message:wao.ui.misc.notValidated}"--%>
+ <%--t:trueTitle="${message:wao.ui.misc.validated}" t:falseTitle="${message:wao.ui.misc.refused}"/> --%>
+ <%--<t:booleanImage t:value="contact.validationProgram" t:empty="isEmpty(contact.validationProgram)"--%>
+ <%--t:emptyTitle="${message:wao.ui.misc.notValidated}"--%>
+ <%--t:trueTitle="${message:wao.ui.misc.validated}" t:falseTitle="${message:wao.ui.misc.refused}"/>--%>
+</td>
+<td>
+ <s:if test="commentCoordinator">
+ <s:property value="%{getCommentDisplayText(commentCoordinator)}"/>
+ <%--TODO<s:text name="wao.ui.field.Contact.commentCoordinator"><s:param value="%{getTooltipText(commentCoordinator)}"/></s:text>--%>
+ </s:if>
+</td>
+<td>
+ <s:if test="commentAdmin">
+ <s:property value="%{getCommentDisplayText(commentAdmin)}"/>
+ <%--TODO<s:text name="wao.ui.field.Contact.commentAdmin"><s:param value="%{getTooltipText(commentAdmin)}"/></s:text>--%>
+ </s:if>
+</td>
+<td>
+ <s:if test="boardingDone">
+ <s:if test="validationCompany">
+ <s:text name="%{dataReliability.i18nKey}"/>
</s:if>
- </td>
- <td>
- <s:if test="observationBeginDate">
- <s:property value="%{formatDateTime(observationBeginDate)}"/>
- </s:if>
- </td>
- <td>
- <s:if test="observationEndDate">
- <s:property value="%{formatDateTime(observationEndDate)}"/>
- </s:if>
- </td>
- <td>
- <s:property value="nbObservants"/>
- </td>
- <td>
- <s:if test="mammalsObservation">
- <img src="<s:url value="/img/eye-22px.png"/>"
- alt="<s:text name="wao.ui.field.Contact.mammalsObservation"/>"/>
- </s:if>
- <s:if test="mammalsCapture">
- <s:if test="mammalsInfo">
- <img src="<s:url value="fishing-net-22px.png"/>"
- alt="<s:text name="wao.ui.field.Contact.mammalsCapture"/>"/>
- <%--TODO<s:text name="wao.ui.field.Contact.mammalsInfo"><s:param value="%{getMammalsInfo(#contact)}"/></s:text>--%>
+ </s:if>
+</td>
+<td class="actions">
+ <div class="dropdown">
+ <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
+ <s:text name="wao.ui.actions"/>
+ <b class="caret"></b>
+ </a>
+ <ul class="dropdown-menu">
+ <s:if test="authenticatedWaoUser.isAuthorizedToEditContact(#contact)">
+ <li>
+ <s:url action="edit-contact!input" id="editContactUrl">
+ <s:param name="contactId" value="topiaId"/>
+ </s:url>
+ <s:a href="%{editContactUrl}">
+ <i class="icon-edit"></i> <s:text name="wao.ui.action.edit"/>
+ </s:a>
+ </li>
</s:if>
- <s:else>
- <img src="<s:url value="fishing-net-22px.png"/>"
- alt="<s:text name="wao.ui.field.Contact.mammalsCapture"/>"/>
- </s:else>
- </s:if>
- </td>
- <td>
- <s:if test="comment">
- <s:property value="%{getCommentDisplayText(comment)}"/>
- <%--TODO<s:text name="wao.ui.misc.comment"><s:param value="%{getTooltipText(comment)}"/></s:text>--%>
- </s:if>
- </td>
- <td>
- <s:if test="dataInputDate">
- <s:property value="%{formatDate(dataInputDate)}"/>
- </s:if>
- </td>
- <td>
- <s:if test="observedDataControl">
- <s:text name="%{observedDataControl.i18nKey}"/>
- </s:if>
- </td>
- <td>
- <s:if test="restitution">
- <s:property value="%{formatDate(restitution)}"/>
- </s:if>
- </td>
- <td>
- Validation
- <s:property value=""/>
- <%--<t:booleanImage t:value="contact.validationCompany" t:empty="isEmpty(contact.validationCompany)"--%>
- <%--t:emptyTitle="${message:wao.ui.misc.notValidated}"--%>
- <%--t:trueTitle="${message:wao.ui.misc.validated}" t:falseTitle="${message:wao.ui.misc.refused}"/> --%>
- <%--<t:booleanImage t:value="contact.validationProgram" t:empty="isEmpty(contact.validationProgram)"--%>
- <%--t:emptyTitle="${message:wao.ui.misc.notValidated}"--%>
- <%--t:trueTitle="${message:wao.ui.misc.validated}" t:falseTitle="${message:wao.ui.misc.refused}"/>--%>
- </td>
- <td>
- <s:if test="commentCoordinator">
- <s:property value="%{getCommentDisplayText(commentCoordinator)}"/>
- <%--TODO<s:text name="wao.ui.field.Contact.commentCoordinator"><s:param value="%{getTooltipText(commentCoordinator)}"/></s:text>--%>
- </s:if>
- </td>
- <td>
- <s:if test="commentAdmin">
- <s:property value="%{getCommentDisplayText(commentAdmin)}"/>
- <%--TODO<s:text name="wao.ui.field.Contact.commentAdmin"><s:param value="%{getTooltipText(commentAdmin)}"/></s:text>--%>
- </s:if>
- </td>
- <td>
- <s:if test="boardingDone">
- <s:if test="validationCompany">
- <s:text name="%{dataReliability.i18nKey}"/>
+ <s:if test="authenticatedWaoUser.isAuthorizedToDeleteContact(#contact)">
+ <li>
+ <s:url action="delete-contact!input" id="deleteContactUrl">
+ <s:param name="contactId" value="topiaId"/>
+ </s:url>
+ <s:a href="%{deleteContactUrl}">
+ <i class="icon-delete"></i> <s:text name="wao.ui.action.delete"/>
+ </s:a>
+ </li>
</s:if>
- </s:if>
- </td>
- <td class="actions">
- <div class="dropdown">
- <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
- <s:text name="wao.ui.actions" />
- <b class="caret"></b>
- </a>
- <ul class="dropdown-menu">
- <s:if test="authenticatedWaoUser.isAuthorizedToEditContact(#contact)">
+ <s:if test="authenticatedWaoUser.authorizedToValidateContacts">
+ <s:if test="authenticatedWaoUser.isAuthorizedToValidateContact(#contact)">
<li>
- <s:url action="edit-contact!input" id="editContactUrl">
- <s:param name="contactId" value="topiaId" />
+ <s:url action="validate-contact!input" id="acceptContactUrl">
+ <s:param name="contactId" value="topiaId"/>
+ <s:param name="validateState" value="true"/>
</s:url>
- <s:a href="%{editContactUrl}">
- <i class="icon-edit"></i> <s:text name="wao.ui.action.edit" />
+ <s:a href="%{acceptContactUrl}">
+ <s:text name="wao.ui.action.acceptContact"/>
</s:a>
</li>
+ <li>
+ <s:url action="validate-contact!input" id="refuseContactUrl">
+ <s:param name="contactId" value="topiaId"/>
+ <s:param name="validateState" value="false"/>
+ </s:url>
+ <s:a href="%{refuseContactUrl}">
+ <s:text name="wao.ui.action.refuseContact"/>
+ </s:a>
+ </li>
</s:if>
- <s:if test="authenticatedWaoUser.isAuthorizedToDeleteContact(#contact)">
+ <s:if test="authenticatedWaoUser.isAuthorizedToUnvalidateContact(#contact)">
<li>
- <s:url action="delete-contact!input" id="deleteContactUrl">
- <s:param name="contactId" value="topiaId" />
+ <s:url action="validate-contact!input" id="unvalidateContactUrl">
+ <s:param name="contactId" value="topiaId"/>
</s:url>
- <s:a href="%{deleteContactUrl}">
- <i class="icon-delete"></i> <s:text name="wao.ui.action.delete" />
+ <s:a href="%{unvalidateContactUrl}">
+ <s:text name="wao.ui.action.unvalidateContact"/>
</s:a>
</li>
</s:if>
- <s:if test="authenticatedWaoUser.authorizedToValidateContacts">
- <s:if test="authenticatedWaoUser.isAuthorizedToValidateContact(#contact)">
- <li>
- <s:url action="validate-contact!input" id="acceptContactUrl">
- <s:param name="contactId" value="topiaId"/>
- <s:param name="validateState" value="true"/>
- </s:url>
- <s:a href="%{acceptContactUrl}">
- <s:text name="wao.ui.action.acceptContact"/>
- </s:a>
- </li>
- <li>
- <s:url action="validate-contact!input" id="refuseContactUrl">
- <s:param name="contactId" value="topiaId"/>
- <s:param name="validateState" value="false"/>
- </s:url>
- <s:a href="%{refuseContactUrl}">
- <s:text name="wao.ui.action.refuseContact"/>
- </s:a>
- </li>
- </s:if>
- <s:if test="authenticatedWaoUser.isAuthorizedToUnvalidateContact(#contact)">
- <li>
- <s:url action="validate-contact!input" id="unvalidateContactUrl">
- <s:param name="contactId" value="topiaId" />
- </s:url>
- <s:a href="%{unvalidateContactUrl}">
- <s:text name="wao.ui.action.unvalidateContact" />
- </s:a>
- </li>
- </s:if>
- </s:if>
- </ul>
- </div>
- </td>
+ </s:if>
+ </ul>
+ </div>
+</td>
</tr>
</s:iterator>
</todby>
Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp (from rev 1830, trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts.jsp)
===================================================================
--- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp (rev 0)
+++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp 2014-04-04 15:37:35 UTC (rev 1837)
@@ -0,0 +1,32 @@
+<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
+<%@taglib uri="/struts-tags" prefix="s" %>
+
+<html>
+
+<head>
+ <title><s:text name="wao.ui.import.contacts" /></title>
+</head>
+
+<h1><s:text name="wao.ui.import.contacts" /></h1>
+
+<div class="alert alert-info">
+ <s:text name="wao.ui.import.disclaimer" />
+</div>
+
+<s:form action="import-contacts" method="POST" enctype="multipart/form-data">
+
+ <fieldset>
+ <legend>
+ <s:text name="wao.ui.import.contacts" />
+ </legend>
+
+ <s:file name="csvFile" />
+
+ <s:submit type="button">
+ <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/>
+ </s:submit>
+ </fieldset>
+
+</s:form>
+
+</html>
\ No newline at end of file
Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts.jsp
===================================================================
--- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts.jsp 2014-04-04 14:52:44 UTC (rev 1836)
+++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts.jsp 2014-04-04 15:37:35 UTC (rev 1837)
@@ -1,32 +0,0 @@
-<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
-<%@taglib uri="/struts-tags" prefix="s" %>
-
-<html>
-
-<head>
- <title><s:text name="wao.ui.import.contacts" /></title>
-</head>
-
-<h1><s:text name="wao.ui.import.contacts" /></h1>
-
-<div class="alert alert-info">
- <s:text name="wao.ui.import.disclaimer" />
-</div>
-
-<s:form action="import-contacts" method="POST" enctype="multipart/form-data">
-
- <fieldset>
- <legend>
- <s:text name="wao.ui.import.contacts" />
- </legend>
-
- <s:file name="csvFile" />
-
- <s:submit type="button">
- <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/>
- </s:submit>
- </fieldset>
-
-</s:form>
-
-</html>
\ No newline at end of file
1
0
Author: bleny
Date: 2014-04-04 16:52:44 +0200 (Fri, 04 Apr 2014)
New Revision: 1836
Url: http://forge.codelutin.com/projects/wao/repository/revisions/1836
Log:
disable select2
Modified:
trunk/wao-web/src/main/webapp/wao.js
Modified: trunk/wao-web/src/main/webapp/wao.js
===================================================================
--- trunk/wao-web/src/main/webapp/wao.js 2014-04-04 10:30:25 UTC (rev 1835)
+++ trunk/wao-web/src/main/webapp/wao.js 2014-04-04 14:52:44 UTC (rev 1836)
@@ -233,7 +233,7 @@
// $('a[data-toggle="popover"]').popover();
$('span[data-toggle="tooltip"]').tooltip();
- $('select').addClass('input-xlarge').select2();
+ //$('select').addClass('input-xlarge').select2();
WAO = new Wao();
1
0
r1835 - in trunk: wao-services/src/main/java/fr/ifremer/wao/services/service wao-web/src/main/resources/i18n wao-web/src/main/webapp wao-web/src/main/webapp/WEB-INF/content/obsmer
by bleny@users.forge.codelutin.com 04 Apr '14
by bleny@users.forge.codelutin.com 04 Apr '14
04 Apr '14
Author: bleny
Date: 2014-04-04 12:30:25 +0200 (Fri, 04 Apr 2014)
New Revision: 1835
Url: http://forge.codelutin.com/projects/wao/repository/revisions/1835
Log:
refs 4490 add boatinfos form in boat details jsp
Modified:
trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java
trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties
trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties
trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp
trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp
trunk/wao-web/src/main/webapp/wao.css
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-04-04 07:37:55 UTC (rev 1834)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-04-04 10:30:25 UTC (rev 1835)
@@ -157,10 +157,13 @@
Company company = getCompanyDao().findByTopiaId(companyId);
boatInfos = dao.create(BoatInfos.PROPERTY_BOAT, boat,
BoatInfos.PROPERTY_COMPANY, company);
+ commit();
}
Contact mostRecentContact = getContactDao().findMostRecentContactOrNull(obsProgram, boatId, companyId);
+ long count = getContactDao().newQueryBuilder().addTopiaIdEquals(Contact.PROPERTY_BOAT, boatId).count();
+
BoatDetails boatDetails = new BoatDetails(boatInfos, mostRecentContact);
return boatDetails;
Modified: trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties
===================================================================
--- trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-04-04 07:37:55 UTC (rev 1834)
+++ trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-04-04 10:30:25 UTC (rev 1835)
@@ -143,6 +143,15 @@
wao.ui.field.Boat.portOfRegistry=Port of registry
wao.ui.field.Boat.shipOwner=Shipowner
wao.ui.field.BoatDistrict.code=District code
+wao.ui.field.BoatInfos.comment=Comment
+wao.ui.field.BoatInfos.contactAddress1=Address
+wao.ui.field.BoatInfos.contactAddress2=Address 2
+wao.ui.field.BoatInfos.contactCity=City
+wao.ui.field.BoatInfos.contactEmail=Email
+wao.ui.field.BoatInfos.contactFirstName=First name
+wao.ui.field.BoatInfos.contactLastName=Last name
+wao.ui.field.BoatInfos.contactPhoneNumber=Phone
+wao.ui.field.BoatInfos.contactPostalCode=Postal code
wao.ui.field.BoatInfos.dup=Capacity of the ship in specialized staff
wao.ui.field.Company.active=Active
wao.ui.field.Company.address1=Address
Modified: trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties
===================================================================
--- trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-04-04 07:37:55 UTC (rev 1834)
+++ trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-04-04 10:30:25 UTC (rev 1835)
@@ -143,6 +143,15 @@
wao.ui.field.Boat.portOfRegistry=Port d'attache
wao.ui.field.Boat.shipOwner=Armateur
wao.ui.field.BoatDistrict.code=Code du quartier maritime
+wao.ui.field.BoatInfos.comment=Commentaire
+wao.ui.field.BoatInfos.contactAddress1=Adresse
+wao.ui.field.BoatInfos.contactAddress2=Complément d'adresse
+wao.ui.field.BoatInfos.contactCity=Ville
+wao.ui.field.BoatInfos.contactEmail=Mél
+wao.ui.field.BoatInfos.contactFirstName=Prénom
+wao.ui.field.BoatInfos.contactLastName=Nom
+wao.ui.field.BoatInfos.contactPhoneNumber=Tél
+wao.ui.field.BoatInfos.contactPostalCode=Code postal
wao.ui.field.BoatInfos.dup=Capacité d'accueil du navire en personnels spécialisés
wao.ui.field.Company.active=Active
wao.ui.field.Company.address1=Adresse
Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp
===================================================================
--- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp 2014-04-04 07:37:55 UTC (rev 1834)
+++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp 2014-04-04 10:30:25 UTC (rev 1835)
@@ -80,6 +80,23 @@
</table>
</s:if>
+<s:form cssClass="form-horizontal">
+
+ <s:hidden name="boatInfosId" value="%{boatDetails.boatInfos.topiaId}" />
+
+ <s:textfield name="boatInfos.contactFirstName" value="%{boatDetails.boatInfos.contactFirstName}" label="%{getText('wao.ui.field.BoatInfos.contactFirstName')}" readOnly="true" />
+ <s:textfield name="boatInfos.contactLastName" value="%{boatDetails.boatInfos.contactLastName}" label="%{getText('wao.ui.field.BoatInfos.contactLastName')}" readOnly="true" />
+ <s:textfield type="email" name="boatInfos.contactEmail" value="%{boatDetails.boatInfos.contactEmail}" label="%{getText('wao.ui.field.BoatInfos.contactEmail')}" readOnly="true" />
+ <s:textfield type="phone" name="boatInfos.contactPhoneNumber" value="%{boatDetails.boatInfos.contactPhoneNumber}" label="%{getText('wao.ui.field.BoatInfos.contactPhoneNumber')}" readOnly="true" />
+ <s:textfield type="number" name="boatInfos.dup" value="%{boatDetails.boatInfos.dup}" label="%{getText('wao.ui.field.BoatInfos.dup')}" readOnly="true" />
+ <s:textfield name="boatInfos.contactAddress1" value="%{boatDetails.boatInfos.contactAddress1}" label="%{getText('wao.ui.field.BoatInfos.contactAddress1')}" readOnly="true" />
+ <s:textfield name="boatInfos.contactAddress2" value="%{boatDetails.boatInfos.contactAddress2}" label="%{getText('wao.ui.field.BoatInfos.contactAddress2')}" readOnly="true" />
+ <s:textfield name="boatInfos.contactPostalCode" value="%{boatDetails.boatInfos.contactPostalCode}" label="%{getText('wao.ui.field.BoatInfos.contactPostalCode')}" readOnly="true" />
+ <s:textfield name="boatInfos.contactCity" value="%{boatDetails.boatInfos.contactCity}" label="%{getText('wao.ui.field.BoatInfos.contactCity')}" readOnly="true" />
+ <s:textfield name="boatInfos.comment" value="%{boatDetails.boatInfos.comment}" label="%{getText('wao.ui.field.BoatInfos.comment')}" readOnly="true" />
+
+</s:form>
+
<s:text name="wao.ui.boats.associatedLine"/>
<ul>
<s:iterator value="boatDetails.boatInfos.boat.elligibleBoat">
Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp
===================================================================
--- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp 2014-04-04 07:37:55 UTC (rev 1834)
+++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp 2014-04-04 10:30:25 UTC (rev 1835)
@@ -43,7 +43,7 @@
$('tr.boat-row').removeClass('highlight');
$('#').addClass('highlight');
}
- WAO.get(url, {}, successCallback);
+ WAO.get(url, { fragment: true }, successCallback);
});
$('#reset-filters').click(function () {
@@ -175,13 +175,12 @@
</thead>
<tbody>
<s:iterator value="boats" var="boat">
- <tr class="boat-row<s:if test="!active"> inactive</s:if>">
- <td id="<s:property value="topiaId"/>">
+ <tr id="<s:property value="topiaId"/>" class="boat-row">
+ <td>
<s:if test="authenticatedWaoUser.authorizedToViewBoatDetails">
<s:url action="boat-details" id="boatDetailsUrl">
<s:param name="companyId" value="authenticatedWaoUser.waoUser.company.topiaId" />
<s:param name="boatId" value="topiaId" />
- <s:param name="fragment" value="true" />
</s:url>
<s:a href="%{boatDetailsUrl}" cssClass="boat-details-action">
<s:property value="%{'' + immatriculation}"/>
@@ -191,7 +190,9 @@
<s:property value="%{'' + immatriculation}"/>
</s:else>
</td>
- <td><s:property value="name"/></td>
+ <td<s:if test="!active"> class="inactive"</s:if>>
+ <s:property value="name"/>
+ </td>
<td><s:property value="boatLength"/></td>
<td><s:property value="%{'' + buildYear}"/></td>
<td><s:property value="district.districtCode"/></td>
Modified: trunk/wao-web/src/main/webapp/wao.css
===================================================================
--- trunk/wao-web/src/main/webapp/wao.css 2014-04-04 07:37:55 UTC (rev 1834)
+++ trunk/wao-web/src/main/webapp/wao.css 2014-04-04 10:30:25 UTC (rev 1835)
@@ -51,7 +51,7 @@
}
/* pour représente qu'une entité (société, utilisateur) est inactive */
-.inactive {
+.inactive, .inactive span[data-toggle="tooltip"] {
text-decoration: line-through;
}
1
0
r1834 - in trunk: wao-services/src/main/java/fr/ifremer/wao/services wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer wao-web/src/main/resources/i18n wao-web/src/main/webapp/WEB-INF/content/obsmer
by tchemit@users.forge.codelutin.com 04 Apr '14
by tchemit@users.forge.codelutin.com 04 Apr '14
04 Apr '14
Author: tchemit
Date: 2014-04-04 09:37:55 +0200 (Fri, 04 Apr 2014)
New Revision: 1834
Url: http://forge.codelutin.com/projects/wao/repository/revisions/1834
Log:
refs #4487
Modified:
trunk/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java
trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java
trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties
trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties
trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp
Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java
===================================================================
--- trunk/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java 2014-04-04 07:37:10 UTC (rev 1833)
+++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/AuthenticatedWaoUser.java 2014-04-04 07:37:55 UTC (rev 1834)
@@ -23,11 +23,14 @@
import com.google.common.base.Preconditions;
import fr.ifremer.wao.entity.Company;
+import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.ContactState;
import fr.ifremer.wao.entity.News;
import fr.ifremer.wao.entity.ObsProgram;
import fr.ifremer.wao.entity.UserProfile;
import fr.ifremer.wao.entity.UserRole;
import fr.ifremer.wao.entity.WaoUser;
+import org.apache.commons.lang3.BooleanUtils;
import java.io.Serializable;
@@ -212,4 +215,71 @@
return authorizedToViewBoatDetails;
}
+ public boolean isAuthorizedToEditContact(Contact contact) {
+ boolean canEdit = getCanWrite() &&
+
+ // user is admin and no validation program
+ (!isReadOnly() && isAdmin() && contact.getValidationProgram() == null
+
+ || // or
+ // user is coordinator or observer
+ isCoordinatorOrObserver() && contact.getValidationCompany() == null);
+ return canEdit;
+ }
+
+ public boolean isAuthorizedToDeleteContact(Contact contact) {
+ boolean noValidation = contact.getValidationProgram() == null
+ && contact.getValidationCompany() == null;
+ return noValidation && getCanWrite();
+ }
+
+ /**
+ * Display validation actions. Evo #2063 : only coordinator can validate
+ * for a company.
+ *
+ * @return true if the validation actions can be displayed
+ */
+ public boolean isAuthorizedToValidateContacts() {
+ return (isAdmin() || isCoordinator()) && !isReadOnly();
+ }
+
+ public boolean isAuthorizedToValidateContact(Contact contact) {
+ // Can't validate during edition of the contact row
+ switch (getUserRole()) {
+ case ADMIN:
+ return contact.getValidationProgram() == null &&
+ BooleanUtils.isTrue(contact.getValidationCompany());
+ // Evo #2063 : only coordinator can validate
+ case COORDINATOR:
+ boolean requiredDataAreFilled;
+ if (contact.getObsProgram() == ObsProgram.OBSMER) {
+ requiredDataAreFilled = contact.getRestitution() != null;
+ } else {
+ requiredDataAreFilled = contact.getDataInputDate() != null;
+ }
+ ContactState state = contact.getContactState();
+ boolean observationDone =
+ state.equals(ContactState.OBSERVATION_DONE) &&
+ requiredDataAreFilled;
+ return contact.getValidationCompany() == null &&
+ (state.isUnfinishedState() || observationDone);
+ default:
+ return false;
+ }
+ }
+
+ public boolean isAuthorizedToUnvalidateContact(Contact contact) {
+ switch (getUserRole()) {
+ case ADMIN:
+ return contact.getValidationProgram() != null;
+ // Evo #2063 : only coordinator can unvalidate
+ case COORDINATOR:
+ return contact.getValidationCompany() != null &&
+ contact.getValidationProgram() == null;
+ default:
+ return false;
+ }
+ }
+
+
}
Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java
===================================================================
--- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java 2014-04-04 07:37:10 UTC (rev 1833)
+++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java 2014-04-04 07:37:55 UTC (rev 1834)
@@ -4,7 +4,6 @@
import fr.ifremer.wao.ContactsFilter;
import fr.ifremer.wao.entity.Boat;
import fr.ifremer.wao.entity.Contact;
-import fr.ifremer.wao.entity.ContactState;
import fr.ifremer.wao.entity.FishingZone;
import fr.ifremer.wao.entity.ObsProgram;
import fr.ifremer.wao.entity.Profession;
@@ -14,7 +13,6 @@
import fr.ifremer.wao.services.service.ObsMerContactsService;
import fr.ifremer.wao.services.service.PaginationBean;
import fr.ifremer.wao.web.WaoJspActionSupport;
-import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.nuiton.topia.persistence.pager.TopiaPagerBean;
@@ -107,6 +105,11 @@
return placeholder;
}
+ public boolean isFullView() {
+ boolean fullView = getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isProfessional();
+ return fullView;
+ }
+
public String getMammalsInfo(Contact contact) {
return escapeForToolTip(contact.getMammalsInfo());
}
@@ -177,79 +180,6 @@
return result;
}
- /**
- * Display validation actions. Evo #2063 : only coordinator can validate
- * for a company.
- *
- * @return true if the validation actions can be displayed
- */
- //TODO Move this in AuthenticatedWaoUser
- public boolean hasValidationActions() {
- return (getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isCoordinator()) &&
- !getAuthenticatedWaoUser().isReadOnly();
- }
-
- public boolean canEditSampleRow(Contact contact) {
- boolean canEdit = getAuthenticatedWaoUser().getCanWrite() &&
-
- // user is admin and no validation program
- (!getAuthenticatedWaoUser().isReadOnly() && getAuthenticatedWaoUser().isAdmin() && contact.getValidationProgram() == null
-
- || // or
- // user is coordinator or observer
- getAuthenticatedWaoUser().isCoordinatorOrObserver() && contact.getValidationCompany() == null);
- return canEdit;
- }
-
- //TODO Move this in AuthenticatedWaoUser
- public boolean canDeleteSampleRow(Contact contact) {
-
- boolean noValidation = contact.getValidationProgram() == null
- && contact.getValidationCompany() == null;
- return noValidation && getAuthenticatedWaoUser().getCanWrite();
- }
-
- //TODO Move this in AuthenticatedWaoUser
- public boolean canValidateContact(Contact contact) {
- // Can't validate during edition of the contact row
- switch (getAuthenticatedWaoUser().getUserRole()) {
- case ADMIN:
- return contact.getValidationProgram() == null &&
- BooleanUtils.isTrue(contact.getValidationCompany());
- // Evo #2063 : only coordinator can validate
- case COORDINATOR:
- boolean requiredDataAreFilled;
- if (contact.getObsProgram() == ObsProgram.OBSMER) {
- requiredDataAreFilled = contact.getRestitution() != null;
- } else {
- requiredDataAreFilled = contact.getDataInputDate() != null;
- }
- ContactState state = contact.getContactState();
- boolean observationDone =
- state.equals(ContactState.OBSERVATION_DONE) &&
- requiredDataAreFilled;
- return contact.getValidationCompany() == null &&
- (state.isUnfinishedState() || observationDone);
- default:
- return false;
- }
- }
-
- //TODO Move this in AuthenticatedWaoUser
- public boolean canUnvalidateContact(Contact contact) {
- switch (getAuthenticatedWaoUser().getUserRole()) {
- case ADMIN:
- return contact.getValidationProgram() != null;
- // Evo #2063 : only coordinator can unvalidate
- case COORDINATOR:
- return contact.getValidationCompany() != null &&
- contact.getValidationProgram() == null;
- default:
- return false;
- }
- }
-
-
//FIXME
public String getTooltipText(String input) {
if (input != null) {
Modified: trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties
===================================================================
--- trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-04-04 07:37:10 UTC (rev 1833)
+++ trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-04-04 07:37:55 UTC (rev 1834)
@@ -114,10 +114,10 @@
wao.ui.contacts.createFromBoat=Create a new contact for this boat and this sample row
wao.ui.contacts.createFromBoat.fail=Contact creation failed
wao.ui.contacts.createFromBoat.warn=Warning \:this sample-row is out of date, are your sure you want to create a new contact ?
-wao.ui.contacts.title=%s contacts trouvés
wao.ui.contacts.division=Division
wao.ui.contacts.observations=Accidental catches and observations
wao.ui.contacts.observers=Observers
+wao.ui.contacts.title=%s contacts found
wao.ui.contacts.validation=Validation
wao.ui.disclaimer=The website "SUIVI DU REALISE DU PLAN D'ECHANTILLONNAGE DES OBSERVATIONS A LA MER" is declared to the CNIL with the number \: 1414476
wao.ui.disclaimer.boats=Data your provide remains property of your company.Outside your company, only an administrator may access to your data for maintenance purpose. The administrator is someone from Ifremer.
Modified: trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties
===================================================================
--- trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-04-04 07:37:10 UTC (rev 1833)
+++ trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-04-04 07:37:55 UTC (rev 1834)
@@ -117,8 +117,8 @@
wao.ui.contacts.division=Division
wao.ui.contacts.observations=Observations et captures accidentelles
wao.ui.contacts.observers=Observateurs
+wao.ui.contacts.title=%s contacts trouvés
wao.ui.contacts.validation=Validation
-wao.ui.contacts.title=%s contacts trouvés
wao.ui.disclaimer=Le site de « SUIVI DU REALISE DU PLAN D'ECHANTILLONNAGE DES OBSERVATIONS A LA MER » a fait l'objet d'une déclaration à la CNIL sous le numéro suivant \: 1414476
wao.ui.disclaimer.boats=Les données saisies dans cette page sont la propriété exclusive de la société. En dehors de la société, seul l'administrateur peut les consulter pour des questions de maintenance sur le site. L'administrateur est une personne de l'Ifremer.
wao.ui.email=Adresse e-mail
Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp
===================================================================
--- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp 2014-04-04 07:37:10 UTC (rev 1833)
+++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp 2014-04-04 07:37:55 UTC (rev 1834)
@@ -35,6 +35,11 @@
var contactsFilterController = new FilterController(WAO.OBSMER_CONTACTS_FILTER_VALUES_JSON_URL, $('#contacts-filters-form'));
contactsFilterController.init();
+ $('#switch-compact-full-view').click(function () {
+ $('#switch-compact-full-view').toggleClass('full-view').toggleClass('compact-view');
+ $('table.contacts-list').toggleClass('full-view').toggleClass('compact-view');
+ });
+
$('#reset-filters').click(function () {
contactsFilterController.reset();
});
@@ -297,6 +302,17 @@
</s:if>
</ul>
</div>
+<s:set var="fullView" value="%{fullView}"/>
+<s:if test="authenticatedWaoUser.admin">
+ <button type="button" id="switch-compact-full-view" class="btn <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>">
+ <span class="only-in-compact-view">
+ <i class="icon-resize-full"></i> <s:text name="wao.ui.action.switchToFullView"/>
+ </span>
+ <span class="only-in-full-view">
+ <i class="icon-resize-small"></i> <s:text name="wao.ui.action.switchToCompactView"/>
+ </span>
+ </button>
+</s:if>
<table id="contacts-list" class="large-table contacts-list">
<thead>
<tr>
@@ -396,15 +412,19 @@
</s:else>
</td>
<td>
- <s:if test="contactStateMotif != null">
+ <s:if test="contactStateMotif">
<s:property value="contactStateMotif.name"/>
</s:if>
</td>
<td>
- <s:property value="%{formatDateTime(observationBeginDate)}"/>
+ <s:if test="observationBeginDate">
+ <s:property value="%{formatDateTime(observationBeginDate)}"/>
+ </s:if>
</td>
<td>
- <s:property value="%{formatDateTime(observationEndDate)}"/>
+ <s:if test="observationEndDate">
+ <s:property value="%{formatDateTime(observationEndDate)}"/>
+ </s:if>
</td>
<td>
<s:property value="nbObservants"/>
@@ -433,7 +453,9 @@
</s:if>
</td>
<td>
- <s:property value="%{formatDate(dataInputDate)}"/>
+ <s:if test="dataInputDate">
+ <s:property value="%{formatDate(dataInputDate)}"/>
+ </s:if>
</td>
<td>
<s:if test="observedDataControl">
@@ -481,7 +503,7 @@
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
- <s:if test="canEditSampleRow(#contact)">
+ <s:if test="authenticatedWaoUser.isAuthorizedToEditContact(#contact)">
<li>
<s:url action="edit-contact!input" id="editContactUrl">
<s:param name="contactId" value="topiaId" />
@@ -491,7 +513,7 @@
</s:a>
</li>
</s:if>
- <s:if test="canDeleteSampleRow(#contact)">
+ <s:if test="authenticatedWaoUser.isAuthorizedToDeleteContact(#contact)">
<li>
<s:url action="delete-contact!input" id="deleteContactUrl">
<s:param name="contactId" value="topiaId" />
@@ -501,8 +523,8 @@
</s:a>
</li>
</s:if>
- <s:if test="hasValidationActions()">
- <s:if test="canValidateContact(contact)">
+ <s:if test="authenticatedWaoUser.authorizedToValidateContacts">
+ <s:if test="authenticatedWaoUser.isAuthorizedToValidateContact(#contact)">
<li>
<s:url action="validate-contact!input" id="acceptContactUrl">
<s:param name="contactId" value="topiaId"/>
@@ -522,10 +544,7 @@
</s:a>
</li>
</s:if>
- <s:else>
- <%--FIXME Display nothing?--%>
- </s:else>
- <s:if test="canUnvalidateContact(contact)">
+ <s:if test="authenticatedWaoUser.isAuthorizedToUnvalidateContact(#contact)">
<li>
<s:url action="validate-contact!input" id="unvalidateContactUrl">
<s:param name="contactId" value="topiaId" />
1
0
r1833 - trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity
by tchemit@users.forge.codelutin.com 04 Apr '14
by tchemit@users.forge.codelutin.com 04 Apr '14
04 Apr '14
Author: tchemit
Date: 2014-04-04 09:37:10 +0200 (Fri, 04 Apr 2014)
New Revision: 1833
Url: http://forge.codelutin.com/projects/wao/repository/revisions/1833
Log:
add fixme
Modified:
trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java
Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java
===================================================================
--- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java 2014-04-04 07:28:22 UTC (rev 1832)
+++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java 2014-04-04 07:37:10 UTC (rev 1833)
@@ -41,6 +41,7 @@
@Override
public String getDistrictName() {
+ //FIXME Do not use I18n without user locale
String districtName = super.getDistrictName();
if (districtName == null) {
districtName = I18n.t("wao.business.other");
1
0