r1864 - in trunk: wao-persistence/src/main/java/fr/ifremer/wao/entity wao-services/src/main/java/fr/ifremer/wao/services 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/java/fr/ifremer/wao/services/service/csv/operations wao-services/src/main/resources/i18n wao-services/src/test/java/fr/ifremer/wao/services/service wao-services/src/test/resources/import wao-web/src/main/java/fr/ifremer/wao/web/actio
Author: tchemit Date: 2014-04-08 13:44:47 +0200 (Tue, 08 Apr 2014) New Revision: 1864 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1864 Log: refs #4487 fix filter query, import of contact, test import Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateBeforeObservationEndDateException.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocalizedToStringParserFormatter.java Removed: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateAfterObservationEndDateException.java Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.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/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.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/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/ObsMerContactImportExportModel.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ObservedDataControlParserFormatter.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-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java trunk/wao-services/src/test/resources/import/contacts.csv trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -41,14 +41,16 @@ private static final Log log = LogFactory.getLog(ContactTopiaDao.class); - public List<Contact> findAll(ContactsFilter filter) { + public List<Contact> findAll(ContactsFilter filter, boolean sort) { HqlAndParametersBuilder<Contact> query = toSampleRowHqlAndParametersBuilder(filter); - if (filter.isSortedByBoardingDate()) { - query.setOrderByArguments(Contact.PROPERTY_OBSERVATION_BEGIN_DATE); - } else { - query.setOrderByArguments(Contact.PROPERTY_CREATION_DATE); + if (sort) { + if (filter.isSortedByBoardingDate()) { + query.setOrderByArguments(Contact.PROPERTY_OBSERVATION_BEGIN_DATE); + } else { + query.setOrderByArguments(Contact.PROPERTY_CREATION_DATE); + } } List<Contact> all = findAll(query.getHql(), query.getHqlParameters()); @@ -61,23 +63,27 @@ HqlAndParametersBuilder<Contact> query = toSampleRowHqlAndParametersBuilder(filter); + // Note: pager alrady contains the sort List<Contact> boats = find(query.getHql(), query.getHqlParameters(), pager); return boats; } public TopiaPagerBean newPager(ContactsFilter filter, int pageSize, - int pageIndex, - String sortProperty, - boolean sortAscendant) { + int pageIndex) { HqlAndParametersBuilder<Contact> query = toSampleRowHqlAndParametersBuilder(filter); TopiaPagerBean pager = newPager(query.getHql(), query.getHqlParameters(), pageSize); pager.setPageIndex(pageIndex); PagerBeanUtil.computeRecordIndexesAndPagesNumber(pager); - pager.setSortColumn(sortProperty); - pager.setSortAscendant(sortAscendant); + + if (filter.isSortedByBoardingDate()) { + pager.setSortColumn(Contact.PROPERTY_OBSERVATION_BEGIN_DATE); + } else { + pager.setSortColumn(Contact.PROPERTY_CREATION_DATE); + } + pager.setSortAscendant(true); return pager; } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -37,6 +37,7 @@ import fr.ifremer.wao.entity.WaoUserImpl; import fr.ifremer.wao.entity.WaoUserTopiaDao; import fr.ifremer.wao.services.service.ImportErrorException; +import fr.ifremer.wao.services.service.ObsMerContactsService; import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; import fr.ifremer.wao.services.service.administration.ReferentialService; import org.apache.commons.io.IOUtils; @@ -51,6 +52,10 @@ protected Map<String, Company> companies = new HashMap<>(); + protected Map<String, WaoUser> waoUsers = new HashMap<>(); + + protected Map<String, UserProfile> userProfiles = new HashMap<>(); + public ObsMerFixtures(WaoServiceContext serviceContext) { this.serviceContext = serviceContext; } @@ -68,6 +73,64 @@ return company; } + protected UserProfile getUserProfile(String userRole) { + UserProfile userProfile = userProfiles.get(userRole); + if (userProfile == null) { + switch (userRole) { + case "admin": + userProfile = new UserProfileImpl(); + userProfile.setUserRole(UserRole.ADMIN); + userProfile.setObsProgram(ObsProgram.OBSMER); + userProfile.setCanWrite(true); + break; + case "jmichmuche": + userProfile = new UserProfileImpl(); + userProfile.setUserRole(UserRole.COORDINATOR); + userProfile.setObsProgram(ObsProgram.OBSMER); + userProfile.setCanWrite(true); + break; + default: + throw new IllegalArgumentException("Don't know userRole: " + userRole); + } + UserProfileTopiaDao userProfileDao = serviceContext.getPersistenceContext().getUserProfileDao(); + userProfileDao.create(userProfile); + serviceContext.getPersistenceContext().commit(); + userProfiles.put(userRole, userProfile); + } + return userProfile; + } + + protected WaoUser getWaoUser(String login) { + WaoUser waoUser = waoUsers.get(login); + if (waoUser == null) { + + switch (login) { + case "admin": + waoUser = new WaoUserImpl(); + waoUser.setCompany(ifremer()); + waoUser.setLogin(login); + waoUser.setActive(true); + waoUser.addUserProfile(getUserProfile("admin")); + break; + case "jmichmuche": + waoUser = new WaoUserImpl(); + waoUser.setCompany(ifremer()); + waoUser.setLogin(login); + waoUser.setActive(true); + waoUser.addUserProfile(getUserProfile("jmichmuche")); + break; + default: + throw new IllegalArgumentException("Don't know user: " + login); + } + + WaoUserTopiaDao waoUserDao = serviceContext.getPersistenceContext().getWaoUserDao(); + waoUserDao.create(waoUser); + serviceContext.getPersistenceContext().commit(); + waoUsers.put(login, waoUser); + } + return waoUser; + } + public Company ifremer() { return getCompany("Ifremer"); } @@ -77,23 +140,44 @@ } public AuthenticatedWaoUser admin() { - WaoUserTopiaDao waoUserDao = serviceContext.getPersistenceContext().getWaoUserDao(); - WaoUser admin = new WaoUserImpl(); - admin.setCompany(ifremer()); - admin.setLogin("admin"); - admin.setActive(true); - UserProfileTopiaDao userProfileDao = serviceContext.getPersistenceContext().getUserProfileDao(); - UserProfile userProfile = new UserProfileImpl(); - userProfile.setUserRole(UserRole.ADMIN); - userProfile.setObsProgram(ObsProgram.OBSMER); - userProfile.setCanWrite(true); - userProfileDao.create(userProfile); - admin.addUserProfile(userProfile); - waoUserDao.create(admin); +// WaoUserTopiaDao waoUserDao = serviceContext.getPersistenceContext().getWaoUserDao(); + WaoUser admin = getWaoUser("admin"); + UserProfile userProfile = getUserProfile("admin"); +// admin.setCompany(ifremer()); +// admin.setLogin("admin"); +// admin.setActive(true); +// UserProfileTopiaDao userProfileDao = serviceContext.getPersistenceContext().getUserProfileDao(); +// UserProfile userProfile = new UserProfileImpl(); +// userProfile.setUserRole(UserRole.ADMIN); +// userProfile.setObsProgram(ObsProgram.OBSMER); +// userProfile.setCanWrite(true); +// userProfileDao.create(userProfile); +// admin.addUserProfile(userProfile); +// waoUserDao.create(admin); AuthenticatedWaoUser authenticatedWaoUser = new AuthenticatedWaoUser(admin, userProfile); return authenticatedWaoUser; } + public AuthenticatedWaoUser jmichmuche() { + WaoUser jmichmuche = getWaoUser("jmichmuche"); + UserProfile userProfile = getUserProfile("jmichmuche"); +// WaoUserTopiaDao waoUserDao = serviceContext.getPersistenceContext().getWaoUserDao(); +// WaoUser jmichmuche = new WaoUserImpl(); +// jmichmuche.setCompany(ifremer()); +// jmichmuche.setLogin("jmichmuche"); +// jmichmuche.setActive(true); +// UserProfileTopiaDao userProfileDao = serviceContext.getPersistenceContext().getUserProfileDao(); +// UserProfile userProfile = new UserProfileImpl(); +// userProfile.setUserRole(UserRole.COORDINATOR); +// userProfile.setObsProgram(ObsProgram.OBSMER); +// userProfile.setCanWrite(true); +// userProfileDao.create(userProfile); +// jmichmuche.addUserProfile(userProfile); +// waoUserDao.create(jmichmuche); + AuthenticatedWaoUser authenticatedWaoUser = new AuthenticatedWaoUser(jmichmuche, userProfile); + return authenticatedWaoUser; + } + public void fishingZones() { InputStream input = null; try { @@ -106,6 +190,18 @@ } } + public void navires() { + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/navires.csv"); + serviceContext.newService(ReferentialService.class).importBoats(input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } + public void samplingPlan() { ifremer(); oceanet(); @@ -121,6 +217,21 @@ } } + public void contacts() { + samplingPlan(); + jmichmuche(); + navires(); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/contacts.csv"); + serviceContext.newService(ObsMerContactsService.class).importContacts(admin(), input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } + public FishingGearDCF ptb() { FishingGearDCFTopiaDao fishingGearDCFDao = serviceContext.getPersistenceContext().getFishingGearDCFDao(); FishingGearDCF ptb = fishingGearDCFDao.forCodeEquals("PTB").findUnique(); Deleted: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateAfterObservationEndDateException.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateAfterObservationEndDateException.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateAfterObservationEndDateException.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -1,18 +0,0 @@ -package fr.ifremer.wao.services.service; - -import fr.ifremer.wao.entity.Contact; - -/** - * Created on 4/7/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ContactDataInputDateAfterObservationEndDateException extends WaoContactValidationException { - - private static final long serialVersionUID = 1L; - - public ContactDataInputDateAfterObservationEndDateException(Contact contact) { - super(contact); - } -} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateBeforeObservationEndDateException.java (from rev 1859, trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateAfterObservationEndDateException.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateBeforeObservationEndDateException.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactDataInputDateBeforeObservationEndDateException.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -0,0 +1,18 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.Contact; + +/** + * Created on 4/7/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class ContactDataInputDateBeforeObservationEndDateException extends WaoContactValidationException { + + private static final long serialVersionUID = 1L; + + public ContactDataInputDateBeforeObservationEndDateException(Contact contact) { + super(contact); + } +} 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ImportErrorException.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -22,7 +22,6 @@ */ import fr.ifremer.wao.WaoException; -import org.nuiton.csv.ImportRuntimeException; import org.nuiton.i18n.I18n; import java.util.Locale; @@ -34,7 +33,7 @@ private static final long serialVersionUID = 1L; - public ImportErrorException(ImportRuntimeException e) { + public ImportErrorException(Throwable e) { super(e); } 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -54,14 +54,18 @@ import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.csv.AbstractImportErrorInfo; import org.nuiton.csv.Export; import org.nuiton.csv.ExportModel; -import org.nuiton.csv.Import; +import org.nuiton.csv.Import2; +import org.nuiton.csv.ImportConf; import org.nuiton.csv.ImportModel; -import org.nuiton.csv.ImportRuntimeException; +import org.nuiton.csv.ImportRow; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.pager.TopiaPagerBean; import org.nuiton.util.DateUtil; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; import java.io.InputStream; import java.util.Calendar; @@ -72,6 +76,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import static org.nuiton.i18n.I18n.l; @@ -82,7 +87,7 @@ public ContactsFilterValues getContactsFilterValues(ContactsFilter filter) { ContactTopiaDao dao = getContactDao(); - List<Contact> contacts = dao.findAll(filter); + List<Contact> contacts = dao.findAll(filter, false); ContactsFilterValues contactsFilterValues = new ContactsFilterValues(serviceContext.getLocale(), filter.getObsProgram()); @@ -100,9 +105,7 @@ TopiaPagerBean pager = dao.newPager(filter, queryPager.getPageSize(), - queryPager.getPageIndex(), - queryPager.getSortColumn(), - queryPager.isSortAscendant()); + queryPager.getPageIndex()); List<Contact> contacts = dao.find(filter, pager); @@ -209,7 +212,7 @@ public InputStream exportContacts(ContactsFilter filter) { ContactTopiaDao dao = getContactDao(); - List<Contact> contacts = dao.findAll(filter); + List<Contact> contacts = dao.findAll(filter, true); ExportModel<Contact> exportModel = ObsMerContactImportExportModel.forExport(getLocale(), filter.getSampleRowFilter().getObsProgram()); @@ -249,108 +252,143 @@ boats, motives); - Import<Contact> contactImport = Import.newImport(contactImportModel, csv); + ImportConf importConf = new ImportConf(); + importConf.setStrictMode(true); - try { + Import2<Contact> contactImport = Import2.newImport(importConf, contactImportModel, csv); - for (Contact contact : contactImport) { + for (ImportRow<Contact> contactRow : contactImport) { - String contactId = contact.getTopiaId(); + if (!contactRow.isValid()) { + // throw first error + Set<AbstractImportErrorInfo<Contact>> errors = contactRow.getErrors(); + AbstractImportErrorInfo<Contact> errorInfo = errors.iterator().next(); + throw new ImportErrorException(errorInfo.getCause()); + } + long lineNumber = contactRow.getLineNumber(); - Optional<String> optionalContactId = Optional.fromNullable(contactId); - UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, - optionalContactId); + Contact contact = contactRow.getBean(); - if (updateContactCommand.isCreation()) { + String contactId = contact.getTopiaId(); - // TODO bind everything ? - } else { + if (StringUtils.isEmpty(contactId)) { + contactId = null; + } - // TODO bind only filled ? - } + Optional<String> optionalContactId = Optional.fromNullable(contactId); + UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, + optionalContactId); - preValidate(authenticatedWaoUser, updateContactCommand, false); + if (updateContactCommand.isCreation()) { - save0(updateContactCommand); + updateContactCommand.setContact(contact); + } else { + + Contact contactToUpdate = updateContactCommand.getContact(); + Binder<Contact, Contact> binder = BinderFactory.newBinder(Contact.class); + binder.copy(contact, contactToUpdate, + Contact.PROPERTY_CREATION_DATE, + Contact.PROPERTY_MAIN_OBSERVER, + Contact.PROPERTY_SECONDARY_OBSERVERS, + "contactState", + Contact.PROPERTY_OBSERVATION_BEGIN_DATE, + Contact.PROPERTY_OBSERVATION_END_DATE, + Contact.PROPERTY_DATA_INPUT_DATE, + Contact.PROPERTY_COMMENT, + Contact.PROPERTY_COMMENT_COORDINATOR, + Contact.PROPERTY_COMMENT_ADMIN, + Contact.PROPERTY_BOAT, + Contact.PROPERTY_VALIDATION_COMPANY, + Contact.PROPERTY_VALIDATION_PROGRAM, + Contact.PROPERTY_SAMPLE_ROW, + Contact.PROPERTY_MAMMALS_OBSERVATION, + Contact.PROPERTY_MAMMALS_CAPTURE, + Contact.PROPERTY_MAMMALS_INFO, + Contact.PROPERTY_CONTACT_STATE_MOTIF, + Contact.PROPERTY_RESTITUTION, + Contact.PROPERTY_OBSERVED_DATA_CONTROL); } - } catch (ImportRuntimeException e) { - throw new ImportErrorException(e); - } catch (ContactNotUpdatableException e) { - String message = l(l, "wao.import.contact.failure.not.updatable"); - throw new ImportErrorException(message); - } catch (UnwantedContactContactStateMotifException e) { - String message = l(l, "wao.import.contact.failure.unwantedContactStateMotif"); - throw new ImportErrorException(message); - } catch (MissingContactNbObservantsException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingObserver", state); - throw new ImportErrorException(message); - } catch (MissingContactObservationEndDateException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingObservationEndDate", state); - throw new ImportErrorException(message); - } catch (ContactDataInputDateAfterObservationEndDateException e) { - String message = l(l, "wao.import.contact.failure.dataInputDateAfterObservationEndDate"); - throw new ImportErrorException(message); - } catch (InvalidContactObservationBeginDateException e) { - String message = l(l, "wao.import.contact.failure.invalidObservationBeginDate"); - throw new ImportErrorException(message); - } catch (MissingContactRestitutionException e) { - String message = l(l, "wao.import.contact.failure.missingRestitution"); - throw new ImportErrorException(message); - } catch (ContactDataInputDateAfterTodayException e) { - String message = l(l, "wao.import.contact.failure.dataInputDateAfterObservationEndDate"); - throw new ImportErrorException(message); - } catch (MissingContactCommentException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingComment", state); - throw new ImportErrorException(message); - } catch (MismatchContactMainObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", observerLogin, companyName); - throw new ImportErrorException(message); - } catch (ContactRestitutionDateBeforeDataInputDateException e) { - String message = l(l, "wao.import.contact.failure.transmissionDateBeforeDataInputDate"); - throw new ImportErrorException(message); - } catch (ContactObservationEndDateBeforeBeginDateException e) { - String message = l(l, "wao.import.contact.failure.observationEndDateBeforeBeginDate"); - throw new ImportErrorException(message); - } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { - String message = l(l, "wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers"); - throw new ImportErrorException(message); - } catch (MissingContactDataReliabilityException e) { - String message = l(l, "wao.import.contact.failure.missingDataReliability"); - throw new ImportErrorException(message); - } catch (MismatchContactSecondaryObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", observerLogin, companyName); - throw new ImportErrorException(message); - } catch (MissingContactObservedDataControlException e) { - String message = l(l, "wao.import.contact.failure.missingObservedDataControl"); - throw new ImportErrorException(message); - } catch (MissingContactStateMotifException e) { - String message = l(l, "wao.import.contact.failure.missingContactStateMotif"); - throw new ImportErrorException(message); - } catch (MissingContactDataInputDateException e) { - String message = l(l, "wao.import.contact.failure.missingDataInputDate"); - throw new ImportErrorException(message); - } catch (MissingContactMainObserverException e) { - String message = l(l, "wao.import.contact.failure.missingMainObserver"); - throw new ImportErrorException(message); - } catch (MissingContactCommentAdminException e) { - String dataReliability = WaoUtils.l(l, e.getContact().getDataReliability()); - String message = l(l, "wao.import.contact.failure.missingCommentAdmin", dataReliability); - throw new ImportErrorException(message); - } catch (ContactObservationEndDateAfterTodayException e) { - String message = l(l, "wao.import.contact.failure.observationEndDateAfterToday"); - throw new ImportErrorException(message); - } catch (MissingContactObservationBeginDateException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingObservationBeginDate", state); - throw new ImportErrorException(message); + try { + preValidate(authenticatedWaoUser, updateContactCommand, false); + } catch (ContactNotUpdatableException e) { + String message = l(l, "wao.import.contact.failure.not.updatable", lineNumber); + throw new ImportErrorException(message); + } catch (UnwantedContactContactStateMotifException e) { + String message = l(l, "wao.import.contact.failure.unwantedContactStateMotif", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactNbObservantsException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingObserver", lineNumber, state); + throw new ImportErrorException(message); + } catch (MissingContactObservationEndDateException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingObservationEndDate", lineNumber, state); + throw new ImportErrorException(message); + } catch (ContactDataInputDateBeforeObservationEndDateException e) { + String message = l(l, "wao.import.contact.failure.dataInputDateBeforeObservationEndDate", lineNumber); + throw new ImportErrorException(message); + } catch (InvalidContactObservationBeginDateException e) { + String message = l(l, "wao.import.contact.failure.invalidObservationBeginDate", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactRestitutionException e) { + String message = l(l, "wao.import.contact.failure.missingRestitution", lineNumber); + throw new ImportErrorException(message); + } catch (ContactDataInputDateAfterTodayException e) { + String message = l(l, "wao.import.contact.failure.dataInputDateAfterToday", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactCommentException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingComment", state, lineNumber); + throw new ImportErrorException(message); + } catch (MismatchContactMainObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); + throw new ImportErrorException(message); + } catch (ContactRestitutionDateBeforeDataInputDateException e) { + String message = l(l, "wao.import.contact.failure.transmissionDateBeforeDataInputDate", lineNumber); + throw new ImportErrorException(message); + } catch (ContactObservationEndDateBeforeBeginDateException e) { + String message = l(l, "wao.import.contact.failure.observationEndDateBeforeBeginDate", lineNumber); + throw new ImportErrorException(message); + } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { + String message = l(l, "wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactDataReliabilityException e) { + String message = l(l, "wao.import.contact.failure.missingDataReliability", lineNumber); + throw new ImportErrorException(message); + } catch (MismatchContactSecondaryObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); + throw new ImportErrorException(message); + } catch (MissingContactObservedDataControlException e) { + String message = l(l, "wao.import.contact.failure.missingObservedDataControl", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactStateMotifException e) { + String message = l(l, "wao.import.contact.failure.missingContactStateMotif", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactDataInputDateException e) { + String message = l(l, "wao.import.contact.failure.missingDataInputDate", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactMainObserverException e) { + String message = l(l, "wao.import.contact.failure.missingMainObserver", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactCommentAdminException e) { + String dataReliability = WaoUtils.l(l, e.getContact().getDataReliability()); + String message = l(l, "wao.import.contact.failure.missingCommentAdmin", lineNumber, dataReliability); + throw new ImportErrorException(message); + } catch (ContactObservationEndDateAfterTodayException e) { + String message = l(l, "wao.import.contact.failure.observationEndDateAfterToday", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactObservationBeginDateException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingObservationBeginDate", lineNumber, state); + throw new ImportErrorException(message); + } + + save0(updateContactCommand); } commit(); @@ -367,7 +405,7 @@ InvalidContactObservationBeginDateException, ContactObservationEndDateBeforeBeginDateException, ContactObservationEndDateAfterTodayException, - ContactDataInputDateAfterObservationEndDateException, + ContactDataInputDateBeforeObservationEndDateException, ContactDataInputDateAfterTodayException, MissingContactCommentException, MissingContactObservationBeginDateException, @@ -490,11 +528,11 @@ // 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.before(DateUtil.setMaxTimeOfDay(dataInputDate)); + boolean dataInputDateAfterObservationEndDate = + observationEndDate.after(DateUtil.setMaxTimeOfDay(dataInputDate)); - if (!observationEndDateIsBeforeDataInputDate) { - throw new ContactDataInputDateAfterObservationEndDateException(contact); + if (dataInputDateAfterObservationEndDate) { + throw new ContactDataInputDateBeforeObservationEndDateException(contact); } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -29,6 +29,7 @@ import fr.ifremer.wao.entity.SampleRowLog; import fr.ifremer.wao.entity.TerrestrialLocation; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; import org.nuiton.util.DateUtil; import java.io.Serializable; @@ -41,8 +42,6 @@ import java.util.Locale; import java.util.Map; -import static org.nuiton.i18n.I18n.l; - public class ObsMerSamplingPlan implements Iterable<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart>, Serializable { private static final long serialVersionUID = 1L; @@ -245,8 +244,6 @@ } } -// protected static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); - /** * Created on 3/24/14. * @@ -419,9 +416,9 @@ dcf5CodesAndDescriptions = new LinkedHashMap<>(); for (DCF5Code dcf5Code : sampleRow.getdCF5Code()) { String key = dcf5Code.getCode(); - String description = dcf5Code.getFishingGearCode() + " - " + l(locale, dcf5Code.getFishingGearDCF().getI18nKey()); + String description = dcf5Code.getFishingGearCode() + " - " + WaoUtils.l(locale, dcf5Code.getFishingGearDCF()); if (dcf5Code.getTargetSpeciesCode() != null) { - description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + l(locale, dcf5Code.getTargetSpeciesDCF().getI18nKey()); + description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + WaoUtils.l(locale, dcf5Code.getTargetSpeciesDCF()); } dcf5CodesAndDescriptions.put(key, description); } @@ -435,7 +432,8 @@ } } professionDescriptionWithoutDCF5 = sampleRow.getProfessionDescriptionWithoutDCF5(); - samplingStrategy = "";//TODO sampleRow.getSamplingStrategy().getI18nKey(); + //FIXME Is this ok? + samplingStrategy = WaoUtils.l(locale,sampleRow.getSamplingStrategy()); sampleRowId = sampleRow.getTopiaId(); // compute lastSampleLogCreateDate @@ -614,18 +612,6 @@ return observationTimesInDaysEstimated; } -// public boolean hasNbTidesReal(Date month) { -// Date current = new Date(); -// boolean validMonth = month.before(current) || WaoUtils.isCurrentMonth(month); -// return validMonth && getNbTidesReal(month) != null; -// } -// -// public boolean hasNbTidesEstimated(Date month) { -// Date current = new Date(); -// boolean validMonth = month.before(current) || WaoUtils.isCurrentMonth(month); -// return validMonth && getNbTidesEstimated(month) != null; -// } - public boolean isElligibleBoatsProvided() { return elligibleBoatsProvided; } @@ -701,5 +687,11 @@ return ratio; } + @Override + public String toString() { + String toString = ToStringBuilder.reflectionToString(this); + return toString; + } + } } 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -632,7 +632,7 @@ // on exclue les contacts invalidés par la société contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); - Collection<Contact> contacts = getContactDao().findAll(contactFilter); + Collection<Contact> contacts = getContactDao().findAll(contactFilter, false); final double minutesPerDay = 24 * 60; // Pour calculer le temps passé, on prend pour chaque observation @@ -729,7 +729,7 @@ // on exclue les contacts invalidés par la société contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); - Collection<Contact> contacts = getContactDao().findAll(contactFilter); + Collection<Contact> contacts = getContactDao().findAll(contactFilter, false); //---- // Recalcul des tides 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/BoatImportExportModel.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -59,7 +59,7 @@ /** * Constructor for export. * - * @param locale + * @param locale current locale used for this import/export */ public BoatImportExportModel(Locale locale) { this.locale = locale; @@ -68,7 +68,7 @@ /** * Constructor for import. * - * @param locale + * @param locale current locale used for this import/export * @param ports ports that can be used by boats as port of registry */ public BoatImportExportModel(Locale locale, List<TerrestrialLocation> ports, List<TerrestrialLocation> districts) { 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -40,6 +40,7 @@ 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.LocalizedToStringParserFormatter; import fr.ifremer.wao.services.service.csv.operations.LocationTypeParserFormatter; import fr.ifremer.wao.services.service.csv.operations.ObsDebCodeParserFormatter; import fr.ifremer.wao.services.service.csv.operations.ObservedDataControlParserFormatter; @@ -119,7 +120,7 @@ terrestrialLocation = indexedLocations.get(locationType).get(code); if (terrestrialLocation == null) { throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongTerrestrialLocation", - locationType.toString(), code)); + locationType.toString(), code)); } } return terrestrialLocation; @@ -182,7 +183,7 @@ protected ModelBuilder<Contact> getModel() { ModelBuilder<Contact> modelBuilder = new ModelBuilder<>(); - modelBuilder.newColumnForImportExport("CONTACT_ID", Contact.TOPIA_ID); + modelBuilder.newColumnForImportExport("CONTACT_ID", Contact.PROPERTY_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(locale, waoUsers)); modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(locale, waoUsers)); @@ -212,7 +213,7 @@ }, new CompanyParserFormatter(locale, null) ); - modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new Common.ToStringParserFormatter(ContactState.getAllowedStates(obsProgram))); + modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new LocalizedToStringParserFormatter<>(locale, 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); @@ -235,7 +236,7 @@ if (obsProgram == ObsProgram.OBSMER) { modelBuilder.newColumnForImportExport("CONTACT_QUALITE_DONNEE", "dataReliability", - new Common.ToStringParserFormatter<>(DataReliability.values())); + new LocalizedToStringParserFormatter<>(locale, 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"); @@ -253,7 +254,7 @@ } }); modelBuilder.newColumnForImportExport("CONTACT_TRANSMISSION_RESTITUTION", Contact.PROPERTY_RESTITUTION, Common.DAY); - modelBuilder.newColumnForImportExport("CONTACT_DONNEES_ALLEGRO_VALIDEES", Contact.PROPERTY_OBSERVED_DATA_CONTROL, new ObservedDataControlParserFormatter()); + modelBuilder.newColumnForImportExport("CONTACT_DONNEES_ALLEGRO_VALIDEES", Contact.PROPERTY_OBSERVED_DATA_CONTROL, new ObservedDataControlParserFormatter(locale)); } else { // FIXME 20110606 bleny contact.getTerrestrialLocation() may be null, export will fail @@ -272,12 +273,13 @@ LocationType locationType = null; if (contact.getTerrestrialLocation() != null) { locationType = contact.getTerrestrialLocation() - .getLocationType(); + .getLocationType(); } return locationType; } }, - locationTypeParserFormatter); + locationTypeParserFormatter + ); modelBuilder.newColumnForImportExport( "CONTACT_LIEU_CODE", Contact.PROPERTY_TERRESTRIAL_LOCATION, @@ -290,7 +292,7 @@ String description = ""; if (contact.getTerrestrialLocation() != null) { description = contact.getTerrestrialLocation() - .getDescription(); + .getDescription(); } return description; } @@ -303,7 +305,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_TYPE_OBSERVATION", "observationType", new LocalizedToStringParserFormatter<>(locale, ObservationType.values())); modelBuilder.newColumnForImportExport("CONTACT_METIER", Contact.PROPERTY_OBS_DEB_CODE, new ObsDebCodeParserFormatter(locale, obsDebCodes)); } 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactStateMotivesImportModel.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -74,6 +74,7 @@ @Override public String parse(String value) throws ParseException { if (value.length() != 6) { + //FIXME Not correct i18n key 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/FishingZoneImportModel.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -31,7 +31,6 @@ import org.nuiton.csv.ImportableColumn; import org.nuiton.csv.ModelBuilder; -import java.util.Collection; import java.util.List; import java.util.Locale; @@ -69,6 +68,6 @@ modelBuilder.newMandatoryColumn("PECHE_FACADE", FishingZone.PROPERTY_FACADE_NAME); 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(); + return (Iterable) 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -37,6 +37,7 @@ 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.LocalizedToStringParserFormatter; 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; @@ -118,18 +119,6 @@ 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); @@ -165,7 +154,7 @@ }, new CompanyParserFormatter(locale, null) ); - modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new Common.ToStringParserFormatter(ContactState.getAllowedStates(obsProgram))); + modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new LocalizedToStringParserFormatter<>(locale, 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); @@ -191,7 +180,7 @@ } modelBuilder.newColumnForImportExport("CONTACT_QUALITE_DONNEE", "dataReliability", - new Common.ToStringParserFormatter<>(DataReliability.values())); + new LocalizedToStringParserFormatter<>(locale, 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"); @@ -211,19 +200,19 @@ } }); modelBuilder.newColumnForImportExport("CONTACT_TRANSMISSION_RESTITUTION", Contact.PROPERTY_RESTITUTION, Common.DAY); - modelBuilder.newColumnForImportExport("CONTACT_DONNEES_ALLEGRO_VALIDEES", Contact.PROPERTY_OBSERVED_DATA_CONTROL, new ObservedDataControlParserFormatter()); + modelBuilder.newColumnForImportExport("CONTACT_DONNEES_ALLEGRO_VALIDEES", Contact.PROPERTY_OBSERVED_DATA_CONTROL, new ObservedDataControlParserFormatter(locale)); return modelBuilder; } @Override public Iterable<ExportableColumn<Contact, Object>> getColumnsForExport() { - return (Iterable) getExportModel().getColumnsForExport(); + return (Iterable) getModel().getColumnsForExport(); } @Override public Iterable<ImportableColumn<Contact, Object>> getColumnsForImport() { - return (Iterable) getImportModel().getColumnsForImport(); + return (Iterable) getModel().getColumnsForImport(); } } Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocalizedToStringParserFormatter.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocalizedToStringParserFormatter.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocalizedToStringParserFormatter.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -0,0 +1,72 @@ +package fr.ifremer.wao.services.service.csv.operations; + +import com.google.common.collect.Sets; +import org.nuiton.csv.ValueParserFormatter; +import org.nuiton.util.StringUtil; + +import java.text.ParseException; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import static org.nuiton.i18n.I18n.l; + +/** + * Created on 4/8/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class LocalizedToStringParserFormatter<E> implements ValueParserFormatter<E> { + + protected Map<E, String> toStrings = new HashMap<>(); + + protected Map<String, E> fromString = new HashMap<>(); + + protected Locale locale; + + @SafeVarargs + public LocalizedToStringParserFormatter(Locale locale, E... values) { + this(locale, Sets.newHashSet(values), null); + } + + public LocalizedToStringParserFormatter(Locale locale, + Iterable<E> values) { + this(locale, values, null); + } + + public LocalizedToStringParserFormatter(Locale locale, + Iterable<E> values, + StringUtil.ToString<E> toString) { + this.locale = locale; + for (E value : values) { + String valueToString; + if (toString == null) { + valueToString = value.toString(); + } else { + valueToString = toString.toString(value); + } + toStrings.put(value, valueToString); + fromString.put(valueToString, value); + } + } + + @Override + public String format(E value) { + String valueAsString = toStrings.get(value); + if (valueAsString == null) { + throw new IllegalArgumentException(); + } + return valueAsString; + } + + @Override + public E parse(String valueAsString) throws ParseException { + E value = fromString.get(valueAsString); + if (value == null) { + String message = l(locale, "wao.import.failure.wrongValue", valueAsString, fromString.keySet().toString()); + throw new IllegalArgumentException(message); + } + return value; + } +} Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/LocalizedToStringParserFormatter.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/csv/operations/ObservedDataControlParserFormatter.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ObservedDataControlParserFormatter.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/ObservedDataControlParserFormatter.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -25,7 +25,6 @@ import fr.ifremer.wao.entity.ObservedDataControl; import org.apache.commons.lang3.StringUtils; -import org.nuiton.csv.Common; import org.nuiton.csv.ValueParserFormatter; import org.nuiton.util.StringUtil; @@ -33,6 +32,7 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Locale; /** * Basé sur un ToStringParserFormatter (comme toutes les énums) mais il faut @@ -44,7 +44,7 @@ protected ValueParserFormatter<ObservedDataControl> nonNullObservedDataControlParserFormatter; - public ObservedDataControlParserFormatter() { + public ObservedDataControlParserFormatter(Locale locale) { List<ObservedDataControl> observedDataControlsValues = new LinkedList<>(); Collections.addAll(observedDataControlsValues, ObservedDataControl.values()); observedDataControlsValues.add(null); @@ -58,7 +58,7 @@ return toString; } }; - nonNullObservedDataControlParserFormatter = new Common.ToStringParserFormatter(observedDataControlsValues, nullableObservedDataControlToString); + nonNullObservedDataControlParserFormatter = new LocalizedToStringParserFormatter<>(locale, observedDataControlsValues, nullableObservedDataControlToString); } @Override 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-04-08 11:44:47 UTC (rev 1864) @@ -44,8 +44,8 @@ wao.import.contact.failure.missingDataInputDate=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.missingDataReliability=You must provide data reliability before validating wao.import.contact.failure.missingHoursOfBeginEndObservation=You must provide accurate time for the beginning and the end of observation -wao.import.contact.failure.missingMainBbserver=Il faut au moins un observateur référant -wao.import.contact.failure.missingMainObserver= +wao.import.contact.failure.missingMainObserver=Il faut au moins un observateur référant +wao.import.failure.wrongValue=Unable to parse value '%S'. Possible values are %s wao.import.contact.failure.missingObservationArea=Il faut préciser un lieu d'observation wao.import.contact.failure.missingObservationBeginDate=La date de début de marée est obligatoire pour l'état '%s' wao.import.contact.failure.missingObservationEndDate=La date de fin d'observation est obligatoire pour l'état '%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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-04-08 11:44:47 UTC (rev 1864) @@ -30,36 +30,35 @@ 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.dataInputDateAfterObservationEndDate= -wao.import.contact.failure.dataInputDateBeforeObservationEndDate=La date de saisie des données ne peut pas être antérieure à la date de fin d'observation -wao.import.contact.failure.dataInputDateBeforeToday=La date de saisie des données doit être antérieur à la date du jour +wao.import.contact.failure.dataInputDateBeforeObservationEndDate=La date de saisie des données doit être postérieure à la date de fin d'observation +wao.import.contact.failure.dataInputDateAfterToday=La date de saisie des données doit être antérieure à la date du jour wao.import.contact.failure.districtMissing=Il faut préciser le code d'un quartier maritime wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires -wao.import.contact.failure.invalid.observationBeginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne -wao.import.contact.failure.invalidObservationBeginDate= +wao.import.contact.failure.invalidObservationBeginDate=Ligne %s : La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.import.contact.failure.locationTypeMissing=Le type du lieu doit être renseigné -wao.import.contact.failure.mismatchCompanyForObserver=L'observateur %s n'est pas membre de la société %s -wao.import.contact.failure.missingComment=Il faut préciser un commentaire pour l'état '%s' -wao.import.contact.failure.missingCommentAdmin=Il faut préciser dans le commentaire administrateur pourquoi la donnée est '%s' -wao.import.contact.failure.missingContactStateMotif=Il faut préciser un motif de refus -wao.import.contact.failure.missingDataInputDate=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.missingDataReliability=Il faut préciser la qualité de la donnée avant de valider +wao.import.contact.failure.mismatchCompanyForObserver=Ligne %s : L'observateur %s n'est pas membre de la société %s +wao.import.contact.failure.missingComment=Ligne %s : Il faut préciser un commentaire pour l'état '%s' +wao.import.contact.failure.missingCommentAdmin=Ligne %s : Il faut préciser dans le commentaire administrateur pourquoi la donnée est '%s' +wao.import.contact.failure.missingContactStateMotif=Ligne %s : Il faut préciser un motif de refus +wao.import.contact.failure.missingDataInputDate=Ligne %s : 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.missingDataReliability=Ligne %s : Il faut préciser la qualité de la donnée avant de valider wao.import.contact.failure.missingHoursOfBeginEndObservation=Il faut préciser les heures exactes de début et de fin d'observation -wao.import.contact.failure.missingMainObserver=Il faut au moins un observateur référant +wao.import.contact.failure.missingMainObserver=Ligne %s : Il faut au moins un observateur référant +wao.import.failure.wrongValue=Valeur '%s' non reconnue. Valeurs possibles : %s wao.import.contact.failure.missingObservationArea=Il faut préciser un lieu d'observation -wao.import.contact.failure.missingObservationBeginDate=La date de début de marée est obligatoire pour l'état '%s' -wao.import.contact.failure.missingObservationEndDate=La date de fin d'observation est obligatoire pour l'état '%s' -wao.import.contact.failure.missingObservedDataControl=Il faut préciser une valeur pour le contrôle des données observées -wao.import.contact.failure.missingObserver=Il ne peut y avoir aucun observateur pour l'état '%s' -wao.import.contact.failure.missingRestitution=Il faut préciser une date de transmission de la restitution de la donnée avant de valider -wao.import.contact.failure.not.updatable=Vous n'avez pas les droits suffisants pour modifier le contact -wao.import.contact.failure.observationEndDateAfterToday=La date de fin de la marée ne peut pas être postérieure à la date du jour -wao.import.contact.failure.observationEndDateBeforeBeginDate=La date de fin d'observation ne peut pas être antérieure à celle du début +wao.import.contact.failure.missingObservationBeginDate=Ligne %s : La date de début de marée est obligatoire pour l'état '%s' +wao.import.contact.failure.missingObservationEndDate=Ligne %s : La date de fin d'observation est obligatoire pour l'état '%s' +wao.import.contact.failure.missingObservedDataControl=Ligne %s : Il faut préciser une valeur pour le contrôle des données observées +wao.import.contact.failure.missingObserver=Ligne %s : Il ne peut y avoir aucun observateur pour l'état '%s' +wao.import.contact.failure.missingRestitution=Ligne %s : Il faut préciser une date de transmission de la restitution de la donnée avant de valider +wao.import.contact.failure.not.updatable=Ligne %s : Vous n'avez pas les droits suffisants pour modifier le contact +wao.import.contact.failure.observationEndDateAfterToday=Ligne %s : La date de fin de la marée ne peut pas être postérieure à la date du jour +wao.import.contact.failure.observationEndDateBeforeBeginDate=Ligne %s : La date de fin d'observation ne peut pas être antérieure à celle du début 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.transmissionDateBeforeDataInputDate=Il faut que la date de transmission de la restitution soit après la date de saisie des données +wao.import.contact.failure.transmissionDateBeforeDataInputDate=Ligne %s : Il faut que la date de transmission de la restitution soit après la date de saisie des données wao.import.contact.failure.unkwonCompany=Il n'y a pas de société ayant pour nom '%s' -wao.import.contact.failure.unwantedContactStateMotif=Il ne faut pas préciser de motif de refus +wao.import.contact.failure.unwantedContactStateMotif=Ligne %s : Il ne faut pas préciser de motif de refus 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 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -24,12 +24,22 @@ import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.services.AbstractWaoServiceTest; import fr.ifremer.wao.services.ObsMerFixtures; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.nuiton.topia.persistence.pager.TopiaPagerBean; +import java.io.InputStream; + public class ObsMerContactsServiceTest extends AbstractWaoServiceTest { + /** Logger. */ + private static final Log log = LogFactory.getLog(ObsMerContactsServiceTest.class); + protected ObsMerContactsService service; protected ObsMerFixtures fixtures; @@ -62,4 +72,28 @@ ObsMerContactsList contactsList = service.getContactsList(filter, pager); } + //FIXME finish to code samplingPlan import to make this works + @Ignore + @Test + public void testImportContacts() { + fixtures.samplingPlan(); + fixtures.jmichmuche(); + fixtures.navires(); + + InputStream input = null; + try { + Assert.assertEquals(0, service.getContactDao().count()); + input = getClass().getResourceAsStream("/import/contacts.csv"); + service.importContacts(fixtures.admin(), input); + Assert.assertEquals(2, service.getContactDao().count()); + } catch (ImportErrorException e) { + if (log.isDebugEnabled()) { + log.debug("unexpected exception raised", e); + } + Assert.fail("exception should not be raised"); + } finally { + IOUtils.closeQuietly(input); + } + } + } Modified: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -23,6 +23,8 @@ import com.google.common.collect.ImmutableSet; import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.AbstractWaoServiceTest; import fr.ifremer.wao.services.ObsMerFixtures; import org.apache.commons.io.IOUtils; @@ -35,6 +37,9 @@ import java.io.IOException; import java.io.InputStream; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart; import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart; @@ -96,13 +101,13 @@ filter = service.newSampleRowsFilter(fixtures.admin()); filter.setTargetSpeciesDcfIds(ImmutableSet.of(fixtures.def().getTopiaId())); samplingPlan = service.getSamplingPlan(filter); - assertSamplePlanRowsNumber(4, samplingPlan ); + assertSamplePlanRowsNumber(4, samplingPlan); filter = service.newSampleRowsFilter(fixtures.admin()); filter.setFishingGearDcfIds(ImmutableSet.of(fixtures.ptb().getTopiaId())); filter.setTargetSpeciesDcfIds(ImmutableSet.of(fixtures.def().getTopiaId())); samplingPlan = service.getSamplingPlan(filter); - assertSamplePlanRowsNumber(1, samplingPlan ); + assertSamplePlanRowsNumber(1, samplingPlan); } protected void assertSamplePlanRowsNumber(int expectedRowsSize, ObsMerSamplingPlan samplingPlan) { @@ -151,4 +156,35 @@ } } + + @Test + public void testRecomputeSampleRowEstimatedAndRealTides() throws Exception { + + fixtures.contacts(); + + SampleRow sampleRow = serviceContext.getPersistenceContext().getSampleRowDao().forCodeEquals("2010_M0011").findUnique(); + + Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> oldStats = new HashMap<>(); + for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { + + ObsMerSamplingPlan.ObsMerSamplingPlanStatistics stats = new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics( + sampleMonth.getExpectedTidesValue(), + sampleMonth.getRealTidesValue(), + sampleMonth.getEstimatedTidesValue() + ); + oldStats.put(sampleMonth.getPeriodDate(), stats); + } + service.recomputeSampleRowEstimatedAndRealTides(sampleRow); + + for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { + + ObsMerSamplingPlan.ObsMerSamplingPlanStatistics oldMonth = oldStats.get(sampleMonth.getPeriodDate()); + int expectedTidesValue = sampleMonth.getExpectedTidesValue(); + int realTidesValue = sampleMonth.getRealTidesValue(); + int estimatedTidesValue = sampleMonth.getEstimatedTidesValue(); + Assert.assertEquals(oldMonth.getNbTidesExpected(), expectedTidesValue, 0.01); + Assert.assertEquals(oldMonth.getNbTidesReal(), realTidesValue, 0.01); + Assert.assertEquals(oldMonth.getNbTidesEstimated(), estimatedTidesValue, 0.01); + } + } } Modified: trunk/wao-services/src/test/resources/import/contacts.csv =================================================================== --- trunk/wao-services/src/test/resources/import/contacts.csv 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-services/src/test/resources/import/contacts.csv 2014-04-08 11:44:47 UTC (rev 1864) @@ -1,2 +1,2 @@ CONTACT_ID;CONTACT_DATE_CREATION;CONTACT_OBSERVATEUR_PRINCIPAL;CONTACT_OBSERVATEURS_SECONDAIRES;CONTACT_ETAT;CONTACT_DEBUT_OBSERVATION;CONTACT_FIN_OBSERVATION;CONTACT_SAISIE_DONNEES;CONTACT_COMMENTAIRE_OBSERVATEUR;CONTACT_COMMENTAIRE_COORDINATEUR;CONTACT_COMMENTAIRE_PROGRAMME;PLAN_CODE;NAVIRE_IMMATRICULATION;CONTACT_VALIDATION_SOCIETE;CONTACT_VALIDATION_PROGRAMME;CONTACT_QUALITE_DONNEE;CONTACT_OBSERVATION_MAMMIFERE;CONTACT_CAPTURE_ACCIDENTELLE;CONTACT_ETAT_MOTIF_CODE;CONTACT_ETAT_MOTIF_NOM;CONTACT_TRANSMISSION_RESTITUTION;CONTACT_DONNEES_ALLEGRO_VALIDEES -;01/03/2011 10:24;jmichmuche;;Refus définitif;;;;ne veut plus collaborer;;;2010_0001;175846;?;?;Inconnue;N;N;REFUS_PROFESSION;;; \ No newline at end of file +;01/03/2011 10:24;jmichmuche;;CONTACT_DEFINITELY_REFUSED;;;;ne veut plus collaborer;;;2010_M0001;174258;?;?;UNKNOWN;N;N;REFUS_PROFESSION;;; Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -26,7 +26,7 @@ import com.opensymphony.xwork2.Preparable; import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.ContactDataInputDateAfterObservationEndDateException; +import fr.ifremer.wao.services.service.ContactDataInputDateBeforeObservationEndDateException; import fr.ifremer.wao.services.service.ContactDataInputDateAfterTodayException; import fr.ifremer.wao.services.service.ContactNotUpdatableException; import fr.ifremer.wao.services.service.ContactObservationEndDateAfterTodayException; @@ -107,80 +107,100 @@ try { service.preValidate(authenticatedWaoUser, updateContactCommand, true); } catch (ContactNotUpdatableException e) { - addActionError(t("wao.ui.contacts.validation.failure.not.updatable")); - addFieldError("updateContactCommand.contact.", t("wao.ui.contacts.validation.failure.not.updatable", e.getMessage())); + session.addErrorMessages(t("wao.ui.contacts.validation.failure.not.updatable")); } catch (UnwantedContactContactStateMotifException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.unwantedContactStateMotif")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.unwantedContactStateMotif")); } catch (MissingContactNbObservantsException e) { String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingObserver", state)); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingObserver", state)); } catch (MissingContactObservationEndDateException e) { String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingObservationEndDate", state)); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingObservationEndDate", state)); - } catch (ContactDataInputDateAfterObservationEndDateException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.dataInputDateAfterObservationEndDate")); + } catch (ContactDataInputDateBeforeObservationEndDateException e) { + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate")); } catch (InvalidContactObservationBeginDateException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.invalidObservationBeginDate")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.invalidObservationBeginDate")); } catch (MissingContactRestitutionException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingRestitution")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingRestitution")); } catch (ContactDataInputDateAfterTodayException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.dataInputDateAfterObservationEndDate")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.dataInputDateAfterToday")); } catch (MissingContactCommentException e) { String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingComment", state)); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingComment", state)); } catch (MismatchContactMainObserverCompanyException e) { String companyName = e.getCompany().getName(); String observerLogin = e.getObserver().getLogin(); - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.mismatchCompanyForObserver", observerLogin, companyName)); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); } catch (ContactRestitutionDateBeforeDataInputDateException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.transmissionDateBeforeDataInputDate")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.transmissionDateBeforeDataInputDate")); } catch (ContactObservationEndDateBeforeBeginDateException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.observationEndDateBeforeBeginDate")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.observationEndDateBeforeBeginDate")); } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers")); } catch (MissingContactDataReliabilityException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingDataReliability")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingDataReliability")); } catch (MismatchContactSecondaryObserverCompanyException e) { String companyName = e.getCompany().getName(); String observerLogin = e.getObserver().getLogin(); - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.mismatchCompanyForObserver", observerLogin, companyName)); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); } catch (MissingContactObservedDataControlException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingObservedDataControl")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingObservedDataControl")); } catch (MissingContactStateMotifException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingContactStateMotif")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingContactStateMotif")); } catch (MissingContactDataInputDateException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingDataInputDate")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingDataInputDate")); } catch (MissingContactMainObserverException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingMainObserver")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingMainObserver")); } catch (MissingContactCommentAdminException e) { String dataReliability = WaoUtils.l(getLocale(), e.getContact().getDataReliability()); - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingCommentAdmin", dataReliability)); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingCommentAdmin", dataReliability)); } catch (ContactObservationEndDateAfterTodayException e) { - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.observationEndDateAfterToday")); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.observationEndDateAfterToday")); } catch (MissingContactObservationBeginDateException e) { String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.", t("wao.import.contact.failure.missingObservationBeginDate", state)); + //TODO fix field + addFieldError("updateContactCommand.contact.", t("wao.ui.form.Contact.error.missingObservationBeginDate", state)); } } Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java 2014-04-08 10:54:25 UTC (rev 1863) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java 2014-04-08 11:44:47 UTC (rev 1864) @@ -26,7 +26,7 @@ import com.opensymphony.xwork2.Preparable; import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.ContactDataInputDateAfterObservationEndDateException; +import fr.ifremer.wao.services.service.ContactDataInputDateBeforeObservationEndDateException; import fr.ifremer.wao.services.service.ContactDataInputDateAfterTodayException; import fr.ifremer.wao.services.service.ContactNotUpdatableException; import fr.ifremer.wao.services.service.ContactObservationEndDateAfterTodayException; @@ -180,7 +180,7 @@ String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); errorMessage = t("wao.import.contact.failure.missingObservationEndDate", state); - } catch (ContactDataInputDateAfterObservationEndDateException e) { + } catch (ContactDataInputDateBeforeObservationEndDateException e) { errorMessage = t("wao.import.contact.failure.dataInputDateAfterObservationEndDate"); } catch (InvalidContactObservationBeginDateException e) { 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-08 10:54:25 UTC (rev 1863) +++ trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-04-08 11:44:47 UTC (rev 1864) @@ -5,25 +5,6 @@ wao.import.boatGroups.success=Import des flotilles réalisé avec succès wao.import.boats.prompt=Import des navires wao.import.boats.success=Import des navires réalisé avec succès -wao.import.contact.failure.dataInputDateAfterObservationEndDate= -wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers= -wao.import.contact.failure.invalidObservationBeginDate= -wao.import.contact.failure.mismatchCompanyForObserver= -wao.import.contact.failure.missingComment= -wao.import.contact.failure.missingCommentAdmin= -wao.import.contact.failure.missingContactStateMotif= -wao.import.contact.failure.missingDataInputDate= -wao.import.contact.failure.missingDataReliability= -wao.import.contact.failure.missingMainObserver= -wao.import.contact.failure.missingObservationBeginDate= -wao.import.contact.failure.missingObservationEndDate= -wao.import.contact.failure.missingObservedDataControl= -wao.import.contact.failure.missingObserver= -wao.import.contact.failure.missingRestitution= -wao.import.contact.failure.observationEndDateAfterToday= -wao.import.contact.failure.observationEndDateBeforeBeginDate= -wao.import.contact.failure.transmissionDateBeforeDataInputDate= -wao.import.contact.failure.unwantedContactStateMotif= wao.import.contactStateMotives.prompt=Import des motifs de refus wao.import.contactStateMotives.success=Import des motifs de refus réalisé avec succès wao.import.fishingZones.prompt=Import des zones de pêches @@ -158,6 +139,26 @@ wao.ui.contacts.validation.to.accept.state.success=Le contact a été accepté avec succès wao.ui.contacts.validation.to.reject.state.success=Le contact a été rejeté avec succès wao.ui.contacts.validation.to.unvalidate.state.success=Le contact a été invalidé avec succès +wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate=La date de saisie des données doit être postérieure à la date de fin d'observation +wao.ui.form.Contact.error.dataInputDateAfterToday=La date de saisie des données doit être antérieure à la date du jour +wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires +wao.ui.form.Contact.error.invalidObservationBeginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne +wao.ui.form.Contact.error.mismatchCompanyForObserver=L'observateur %s n'est pas membre de la société %s +wao.ui.form.Contact.error.missingComment=Il faut préciser un commentaire pour l'état '%s' +wao.ui.form.Contact.error.missingCommentAdmin=Il faut préciser dans le commentaire administrateur pourquoi la donnée est '%s' +wao.ui.form.Contact.error.missingContactStateMotif=Il faut préciser un motif de refus +wao.ui.form.Contact.error.missingDataInputDate=Il faut préciser une date de saisie des données en plus de la date de transmission de la restitution +wao.ui.form.Contact.error.missingDataReliability=Il faut préciser la qualité de la donnée avant de valider +wao.ui.form.Contact.error.missingMainObserver=Il faut au moins un observateur référant +wao.ui.form.Contact.error.missingObservationBeginDate=La date de début de marée est obligatoire pour l'état '%s' +wao.ui.form.Contact.error.missingObservationEndDate=La date de fin d'observation est obligatoire pour l'état '%s' +wao.ui.form.Contact.error.missingObservedDataControl=Il faut préciser une valeur pour le contrôle des données observées +wao.ui.form.Contact.error.missingObserver=Il ne peut y avoir aucun observateur pour l'état '%s' +wao.ui.form.Contact.error.missingRestitution=Il faut préciser une date de transmission de la restitution de la donnée avant de valider +wao.ui.form.Contact.error.observationEndDateAfterToday=La date de fin de la marée ne peut pas être postérieure à la date du jour +wao.ui.form.Contact.error.observationEndDateBeforeBeginDate=La date de fin d'observation ne peut pas être antérieure à celle du début +wao.ui.form.Contact.error.transmissionDateBeforeDataInputDate=Il faut que la date de transmission de la restitution soit après la date de saisie des données +wao.ui.form.Contact.error.unwantedContactStateMotif=Il ne faut pas préciser de motif de refus 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
participants (1)
-
tchemit@users.forge.codelutin.com