r2088 - 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
Author: bleny Date: 2014-06-23 21:11:45 +0200 (Mon, 23 Jun 2014) New Revision: 2088 Url: http://forge.codelutin.com/projects/wao/repository/revisions/2088 Log: fixes #5285 i18n for contacts import/export Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/LocationType.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/LocationType.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/LocationType.java 2014-06-23 18:52:57 UTC (rev 2087) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/LocationType.java 2014-06-23 19:11:45 UTC (rev 2088) @@ -22,7 +22,7 @@ import static org.nuiton.i18n.I18n.n; -public enum LocationType implements I18nAble{ +public enum LocationType implements I18nAble { PORT(n("LocationType.PORT")), AUCTION(n("LocationType.AUCTION")), Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java 2014-06-23 18:52:57 UTC (rev 2087) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java 2014-06-23 19:11:45 UTC (rev 2088) @@ -65,6 +65,7 @@ import org.nuiton.csv.ImportConf; import org.nuiton.csv.ImportModel; import org.nuiton.csv.ImportRow; +import org.nuiton.csv.ImportRuntimeException; import org.nuiton.i18n.I18n; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.DateUtil; @@ -286,151 +287,156 @@ Import2<Contact> contactImport = Import2.newImport(importConf, contactImportModel, csv); - for (ImportRow<Contact> contactRow : contactImport) { + try { - 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(); + for (ImportRow<Contact> contactRow : contactImport) { - Contact contact = contactRow.getBean(); + 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(); - String contactId = contact.getTopiaId(); + Contact contact = contactRow.getBean(); - if (StringUtils.isEmpty(contactId)) { - contactId = null; - } + String contactId = contact.getTopiaId(); - Optional<String> optionalContactId = Optional.fromNullable(contactId); - UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, - optionalContactId); + if (StringUtils.isEmpty(contactId)) { + contactId = null; + } - if (updateContactCommand.isCreation()) { + Optional<String> optionalContactId = Optional.fromNullable(contactId); + UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, + optionalContactId); - updateContactCommand.setContact(contact); + if (updateContactCommand.isCreation()) { - // Prevent that someone who is not admin change data that only admin - // must be able to modify - if ( ! authenticatedWaoUser.isAdmin()) { - contact.setCommentAdmin(null); - contact.setValidationProgram(null); - contact.setDataReliability(DataReliability.UNKNOWN); - } + updateContactCommand.setContact(contact); - } else { + // Prevent that someone who is not admin change data that only admin + // must be able to modify + if ( ! authenticatedWaoUser.isAdmin()) { + contact.setCommentAdmin(null); + contact.setValidationProgram(null); + contact.setDataReliability(DataReliability.UNKNOWN); + } - Contact contactToUpdate = updateContactCommand.getContact(); + } else { - // TODO brendan 20/06/14 create to binders - Binder<Contact, Contact> binder = BinderFactory.newBinder(Contact.class); - binder.copyExcluding(contact, contactToUpdate, TopiaEntity.PROPERTY_TOPIA_ID, TopiaEntity.PROPERTY_TOPIA_VERSION, - TopiaEntity.PROPERTY_TOPIA_CREATE_DATE, Contact.PROPERTY_SAMPLE_ROW); + Contact contactToUpdate = updateContactCommand.getContact(); - // Prevent that someone who is not admin change data that only admin - // must be able to modify - if ( ! authenticatedWaoUser.isAdmin()) { - contactToUpdate.setCommentAdmin(contact.getCommentAdmin()); - contactToUpdate.setValidationProgram(contact.getValidationProgram()); - contactToUpdate.setDataReliability(contact.getDataReliability()); + // TODO brendan 20/06/14 create to binders + Binder<Contact, Contact> binder = BinderFactory.newBinder(Contact.class); + binder.copyExcluding(contact, contactToUpdate, TopiaEntity.PROPERTY_TOPIA_ID, TopiaEntity.PROPERTY_TOPIA_VERSION, + TopiaEntity.PROPERTY_TOPIA_CREATE_DATE, Contact.PROPERTY_SAMPLE_ROW); + + // Prevent that someone who is not admin change data that only admin + // must be able to modify + if ( ! authenticatedWaoUser.isAdmin()) { + contactToUpdate.setCommentAdmin(contact.getCommentAdmin()); + contactToUpdate.setValidationProgram(contact.getValidationProgram()); + contactToUpdate.setDataReliability(contact.getDataReliability()); + } + } - } + try { + validate(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 (ContactWithObservedDataControlToCorrectionAskedException e) { + String message = l(l, "wao.import.contact.failure.observedDataControlToCorrectionAsked", 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); + } catch (MissingContactMammalsInfoException e) { + String message = l(l, "wao.import.contact.failure.missingContactMammalsInfo", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactTerrestrialLocationException e) { + String message = l(l, "wao.import.contact.failure.missingTerrestrialLocation", lineNumber); + throw new ImportErrorException(message); + } catch (IllegalAcceptationException e) { + String message = l(l, "wao.import.contact.failure.illegalAcceptation", lineNumber); + throw new ImportErrorException(message); + } - try { - validate(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 (ContactWithObservedDataControlToCorrectionAskedException e) { - String message = l(l, "wao.import.contact.failure.observedDataControlToCorrectionAsked", 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); - } catch (MissingContactMammalsInfoException e) { - String message = l(l, "wao.import.contact.failure.missingContactMammalsInfo", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactTerrestrialLocationException e) { - String message = l(l, "wao.import.contact.failure.missingTerrestrialLocation", lineNumber); - throw new ImportErrorException(message); - } catch (IllegalAcceptationException e) { - String message = l(l, "wao.import.contact.failure.illegalAcceptation", lineNumber); - throw new ImportErrorException(message); + save0(updateContactCommand); } - - save0(updateContactCommand); + } catch (ImportRuntimeException e) { + throw new ImportErrorException(e); } commit(); 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-06-23 18:52:57 UTC (rev 2087) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java 2014-06-23 19:11:45 UTC (rev 2088) @@ -24,6 +24,7 @@ package fr.ifremer.wao.services.service.csv; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; @@ -42,7 +43,6 @@ 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.I18nAbleParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.LocationTypeParserFormatter; 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; @@ -227,7 +227,8 @@ // terrestrial location for both ObsVente and ObsDeb ValueGetterSetter<Contact, LocationType> locationTypeGetter = new Common.ValueSaver<>(); - LocationTypeParserFormatter locationTypeParserFormatter = new LocationTypeParserFormatter(locale); + ValueParserFormatter<LocationType> locationTypeParserFormatter = + new I18nAbleParserFormatter<>(locale, ImmutableSet.of(LocationType.AUCTION, LocationType.PORT)); modelBuilder.newMandatoryColumn( "CONTACT_LIEU_TYPE", locationTypeParserFormatter,
participants (1)
-
bleny@users.forge.codelutin.com