branch feature/2264 created (now 912ef1e)
This is an automated email from the git hooks/post-receive script. New change to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git at 912ef1e Ébauche du formulaire de modification d'un contact scléro This branch includes the following new commits: new 8503b96 Correction des tests new 8c8c2a5 Utilisation d'une constante disponible depuis le refactoring de Wao 4.1 new 737b88f Dans le modèle, on ajoute les champs scléro sur l'entité Contact, dans les tests, on ajoute un import d'un contact new 7ab5f4e Correction d'un lien pour la création d'un utilisateur new 2a485b8 Ouverture de l'accès à l'onglet « Contacts » new 529a0b8 On rétrograde la version de struts car on a plus les traces en cas d'erreur new a6674c1 Activivation de la création d'un contact sous scléro new 912ef1e Ébauche du formulaire de modification d'un contact scléro The 8 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 912ef1e1fd070bec6fcc878afbfcffea2aa902d6 Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 16:31:14 2014 +0100 Ébauche du formulaire de modification d'un contact scléro commit a6674c177f99316a6ee72ab3d5ff2fc791cf749b Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 15:48:50 2014 +0100 Activivation de la création d'un contact sous scléro commit 529a0b8ea58bb2efd9fda20fc6fcf4f698b15e0c Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 15:47:17 2014 +0100 On rétrograde la version de struts car on a plus les traces en cas d'erreur commit 2a485b8a1f2764cfd900b2b1f2a4e8a1cbadd50c Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 10:57:32 2014 +0100 Ouverture de l'accès à l'onglet « Contacts » commit 7ab5f4e43329ad91505e74b4f9a153856768615d Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 10:57:10 2014 +0100 Correction d'un lien pour la création d'un utilisateur commit 737b88f5b6b56641dce670396b91d1a34657789a Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Dec 23 16:40:25 2014 +0100 Dans le modèle, on ajoute les champs scléro sur l'entité Contact, dans les tests, on ajoute un import d'un contact commit 8c8c2a53b1b10f66f0d49118457635de039e897f Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Dec 23 11:49:53 2014 +0100 Utilisation d'une constante disponible depuis le refactoring de Wao 4.1 commit 8503b961dc8b854c1cbff4f6931692d720a7db28 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Dec 23 11:47:02 2014 +0100 Correction des tests -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 8503b961dc8b854c1cbff4f6931692d720a7db28 Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Dec 23 11:47:02 2014 +0100 Correction des tests --- .../src/main/java/fr/ifremer/wao/entity/Organisations.java | 12 ++++++++++++ .../service/csv/operations/OrganisationParserFormatter.java | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/Organisations.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Organisations.java index 30efc81..d2951df 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/Organisations.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Organisations.java @@ -13,6 +13,10 @@ public class Organisations { return Ordering.natural().onResultOf(getFullName()); } + public static Function<Organisation, String> getName() { + return new GetName<>(); + } + protected static class GetFullName<T extends Organisation> implements Function<T, String> { @Override @@ -20,4 +24,12 @@ public class Organisations { return input.getFullName(); } } + + protected static class GetName<T extends Organisation> implements Function<T, String> { + + @Override + public String apply(T input) { + return input.getName(); + } + } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/OrganisationParserFormatter.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/OrganisationParserFormatter.java index 58ac330..472f0a2 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/OrganisationParserFormatter.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/OrganisationParserFormatter.java @@ -63,7 +63,7 @@ public class OrganisationParserFormatter implements ValueParserFormatter<Organis @Override public Organisation parse(String organisationName) throws ParseException { if (indexedOrganisations == null) { - indexedOrganisations = Maps.uniqueIndex(organisations, Organisations.getFullName()); + indexedOrganisations = Maps.uniqueIndex(organisations, Organisations.getName()); } Organisation organisation = null; if (StringUtils.isNotBlank(organisationName)) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 8c8c2a53b1b10f66f0d49118457635de039e897f Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Dec 23 11:49:53 2014 +0100 Utilisation d'une constante disponible depuis le refactoring de Wao 4.1 --- .../fr/ifremer/wao/services/service/csv/ContactImportExportModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java index ab838bd..a1c4c41 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java @@ -173,7 +173,7 @@ public class ContactImportExportModel implements ImportExportModel<Contact> { new OrganisationParserFormatter(locale, null) ); - modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new ContactStateParserFormatter(locale, obsProgram)); + modelBuilder.newColumnForImportExport("CONTACT_ETAT", Contact.PROPERTY_CONTACT_STATE, new ContactStateParserFormatter(locale, obsProgram)); modelBuilder.newColumnForImportExport("CONTACT_DEBUT_OBSERVATION", Contact.PROPERTY_OBSERVATION_BEGIN_DATE, new DayTimeParserFormatter(locale)); modelBuilder.newColumnForImportExport("CONTACT_FIN_OBSERVATION", Contact.PROPERTY_OBSERVATION_END_DATE, new DayTimeParserFormatter(locale)); modelBuilder.newColumnForImportExport("CONTACT_SAISIE_DONNEES", Contact.PROPERTY_DATA_INPUT_DATE, new DayParserFormatter(locale)); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 737b88f5b6b56641dce670396b91d1a34657789a Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Dec 23 16:40:25 2014 +0100 Dans le modèle, on ajoute les champs scléro sur l'entité Contact, dans les tests, on ajoute un import d'un contact --- .../java/fr/ifremer/wao/entity/ContactState.java | 1 + .../entity/SclerochronologySamplingContext.java | 14 ++++++ ...ies,_add_laboratories,_add_sclerochronology.sql | 5 ++ wao-persistence/src/main/xmi/wao-model.zargo | Bin 61993 -> 62318 bytes .../ifremer/wao/services/service/BoatsService.java | 56 +++++++++++++++++++++ .../{ObsMerContactsList.java => ContactsList.java} | 8 ++- .../wao/services/service/ContactsService.java | 10 +++- .../wao/services/service/InitWaoService.java | 9 ++-- .../wao/services/service/SynthesisService.java | 2 +- .../wao/services/service/WaoServiceSupport.java | 8 +++ .../service/csv/ContactImportExportModel.java | 32 ++++++++---- .../wao/services/service/ContactsServiceTest.java | 52 +++++++++++++++---- .../services/service/SclerochronologyFixtures.java | 18 +++++++ .../import/contacts-sclerochronologie.csv | 2 + .../fr/ifremer/wao/web/action/ContactsAction.java | 4 +- 15 files changed, 185 insertions(+), 36 deletions(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactState.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactState.java index b273c0e..9e2a96f 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactState.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactState.java @@ -83,6 +83,7 @@ public enum ContactState { ImmutableSetMultimap.<ObsProgram, ContactState>builder() .putAll(ObsProgram.OBSMER, ALL_CONTACT_STATES) .putAll(ObsProgram.OBSVENTE, ImmutableSet.of(OBSERVATION_EXPECTED, OBSERVATION_DONE, OBSERVATION_CANCELLED)) + .putAll(ObsProgram.SCLEROCHRONOLOGY, ImmutableSet.of(OBSERVATION_EXPECTED, OBSERVATION_DONE, OBSERVATION_CANCELLED)) .build(); protected String i18nKey; diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SclerochronologySamplingContext.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SclerochronologySamplingContext.java index 68648a3..0897a9c 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SclerochronologySamplingContext.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SclerochronologySamplingContext.java @@ -35,4 +35,18 @@ public enum SclerochronologySamplingContext implements I18nAble { public String getI18nKey() { return i18nKey; } + + public boolean isScientificCampaign() { + return SCIENTIFIC_CAMPAIGN == this; + } + + public String getDedicatedBoatRegistrationCode() { + String dedicatedBoatRegistrationCode; + if (isScientificCampaign()) { + dedicatedBoatRegistrationCode = "SCLEROCAM"; + } else { + dedicatedBoatRegistrationCode = "SCLEROPRO"; + } + return dedicatedBoatRegistrationCode; + } } diff --git a/wao-persistence/src/main/resources/db/migration/V5_0__add_species,_add_laboratories,_add_sclerochronology.sql b/wao-persistence/src/main/resources/db/migration/V5_0__add_species,_add_laboratories,_add_sclerochronology.sql index 96ab55c..24e0ddc 100644 --- a/wao-persistence/src/main/resources/db/migration/V5_0__add_species,_add_laboratories,_add_sclerochronology.sql +++ b/wao-persistence/src/main/resources/db/migration/V5_0__add_species,_add_laboratories,_add_sclerochronology.sql @@ -74,3 +74,8 @@ alter table SampleRow add column species character varying(255) references Speci alter table SampleRow add column sclerochronologySamplingContext character varying(255); alter table SampleRow add column individualMeasurementStrategy character varying(255); alter table SampleRow add column sclerochronologySamplingContextInfo text; + +alter table Contact add column sampleSize integer; +alter table Contact add column sampleSubmission timestamp without time zone; +alter table Contact add column sampleReception timestamp without time zone; +alter table Contact add column sampleTreatment timestamp without time zone; diff --git a/wao-persistence/src/main/xmi/wao-model.zargo b/wao-persistence/src/main/xmi/wao-model.zargo index 5535ef4..69b2317 100644 Binary files a/wao-persistence/src/main/xmi/wao-model.zargo and b/wao-persistence/src/main/xmi/wao-model.zargo differ diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java index da286422a..1deab18 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java @@ -41,6 +41,9 @@ import fr.ifremer.wao.entity.ContactTopiaDao; import fr.ifremer.wao.entity.ElligibleBoat; import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SclerochronologySamplingContext; +import fr.ifremer.wao.entity.ShipOwner; import fr.ifremer.wao.services.AuthenticatedWaoUser; import fr.ifremer.wao.services.service.csv.BoatImportExportModel; import org.apache.commons.collections4.CollectionUtils; @@ -302,4 +305,57 @@ public class BoatsService extends WaoServiceSupport { commit(); } + + /** + * Dans la sclérochronologie, on utilise pas les navires du référentiel mais des navires + * fictifs représentant respectivement un navire de l'Ifremer ou un navire d'un professionnel. + */ + public Boat getBoatToUseForSclerochronologySampleRow(SampleRow sampleRow) { + + String dedicatedBoatRegistrationCode = sampleRow.getSclerochronologySamplingContext().getDedicatedBoatRegistrationCode(); + + Boat boat = getBoatDao().forRegistrationCodeEquals(dedicatedBoatRegistrationCode).findUnique(); + + return boat; + + } + + public void createBoatsForSclerochronologyIfNecessary() { + + BoatTopiaDao dao = getBoatDao(); + + for (SclerochronologySamplingContext sclerochronologySamplingContext : SclerochronologySamplingContext.values()) { + + String dedicatedBoatRegistrationCode = sclerochronologySamplingContext.getDedicatedBoatRegistrationCode(); + + boolean exists = dao.forRegistrationCodeEquals(dedicatedBoatRegistrationCode).exists(); + + if ( ! exists) { + + getFictiveShipownerForSclerochronology(); + + dao.create(Boat.PROPERTY_REGISTRATION_CODE, dedicatedBoatRegistrationCode, + Boat.PROPERTY_SHIP_OWNER, getFictiveShipownerForSclerochronology(), + Boat.PROPERTY_NAME, "" + ); + } + + } + + commit(); + } + + protected ShipOwner getFictiveShipownerForSclerochronology() { + + final String FICTIVE_SHIP_OWNER_CODE = "SCLERO"; + + ShipOwner shipOwner = getShipOwnerDao().forCodeEquals(FICTIVE_SHIP_OWNER_CODE).findUniqueOrNull(); + + if (shipOwner == null) { + shipOwner = getShipOwnerDao().create(ShipOwner.PROPERTY_CODE, FICTIVE_SHIP_OWNER_CODE); + } + + return shipOwner; + + } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsList.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsList.java similarity index 91% rename from wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsList.java rename to wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsList.java index 24d7581..af984d0 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsList.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsList.java @@ -22,11 +22,9 @@ package fr.ifremer.wao.services.service; */ import fr.ifremer.wao.entity.Contact; +import org.nuiton.util.pagination.PaginationResult; import java.io.Serializable; -import java.util.List; - -import org.nuiton.util.pagination.PaginationResult; /** * Created on 4/3/14. @@ -34,9 +32,9 @@ import org.nuiton.util.pagination.PaginationResult; * @author Tony Chemit <chemit@codelutin.com> * @since 4.0 */ -public class ObsMerContactsList implements Serializable { +public class ContactsList implements Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 2L; protected PaginationResult<Contact> contacts; diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java index b2d5cd5..fc7c3fc 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java @@ -207,7 +207,7 @@ public class ContactsService extends WaoServiceSupport { } - public ObsMerContactsList getContactsList(AuthenticatedWaoUser authenticatedWaoUser, + public ContactsList getContactsList(AuthenticatedWaoUser authenticatedWaoUser, ContactsFilter filter, PaginationParameter queryPager) { @@ -226,7 +226,7 @@ public class ContactsService extends WaoServiceSupport { ContactsFilterValues filterValues = getContactsFilterValues(authenticatedWaoUser, filter); - ObsMerContactsList contactsList = new ObsMerContactsList(); + ContactsList contactsList = new ContactsList(); contactsList.setContacts(contacts); contactsList.setFilterValues(filterValues); return contactsList; @@ -431,6 +431,12 @@ public class ContactsService extends WaoServiceSupport { } + if (obsProgram.isSclerochronology()) { + SampleRow sampleRow = updateContactCommand.getContact().getSampleRow(); + Boat boat = getBoatsService().getBoatToUseForSclerochronologySampleRow(sampleRow); + updateContactCommand.getContact().setBoat(boat); + } + try { validate(authenticatedWaoUser, updateContactCommand); } catch (ContactNotUpdatableException e) { diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/InitWaoService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/InitWaoService.java index 8013668..626e790 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/InitWaoService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/InitWaoService.java @@ -26,7 +26,6 @@ import com.google.common.collect.ImmutableSet; import fr.ifremer.wao.BoatsFilter; import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.services.service.administration.ReferentialService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -38,9 +37,9 @@ public class InitWaoService extends WaoServiceSupport { public void init() { - ReferentialService referentialService = getReferentialService(); + getReferentialService().initialImport(); - referentialService.initialImport(); + getBoatsService().createBoatsForSclerochronologyIfNecessary(); // pré-chargement des caches @@ -50,8 +49,8 @@ public class InitWaoService extends WaoServiceSupport { log.info("début du pré-chargement des caches"); } - BoatsService boatsService = newService(BoatsService.class); - ContactsService contactsService = newService(ContactsService.class); + BoatsService boatsService = getBoatsService(); + ContactsService contactsService = getContactsService(); for (ObsProgram obsProgram : ImmutableSet.of(ObsProgram.OBSMER, ObsProgram.OBSVENTE)) { BoatsFilter boatsFilter = boatsService.newEmptyBoatsFilter(); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java index d5f4a12..c84c6d0 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java @@ -69,7 +69,7 @@ public class SynthesisService extends WaoServiceSupport { public ContactsFilter newFilter(AuthenticatedWaoUser authenticatedWaoUser) { - ContactsService contactsService = newService(ContactsService.class); + ContactsService contactsService = getContactsService(); ContactsFilter newFilter = contactsService.newContactFilter(authenticatedWaoUser); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java index ebc60f9..8730e99 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java @@ -211,4 +211,12 @@ public abstract class WaoServiceSupport implements WaoService { public LaboratoriesService getLaboratoriesService() { return newService(LaboratoriesService.class); } + + protected BoatsService getBoatsService() { + return newService(BoatsService.class); + } + + protected ContactsService getContactsService() { + return newService(ContactsService.class); + } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java index a1c4c41..487c7e7 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java @@ -161,9 +161,9 @@ public class ContactImportExportModel implements ImportExportModel<Contact> { } } ); - modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_SOCIETE"); + modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_ORGANISATION"); modelBuilder.newColumnForExport( - "CONTACT_OBSERVATEURS_SOCIETE", + "CONTACT_OBSERVATEURS_ORGANISATION", new ValueGetter<Contact, Organisation>() { @Override public Organisation get(Contact contact) { @@ -176,19 +176,29 @@ public class ContactImportExportModel implements ImportExportModel<Contact> { modelBuilder.newColumnForImportExport("CONTACT_ETAT", Contact.PROPERTY_CONTACT_STATE, new ContactStateParserFormatter(locale, obsProgram)); modelBuilder.newColumnForImportExport("CONTACT_DEBUT_OBSERVATION", Contact.PROPERTY_OBSERVATION_BEGIN_DATE, new DayTimeParserFormatter(locale)); modelBuilder.newColumnForImportExport("CONTACT_FIN_OBSERVATION", Contact.PROPERTY_OBSERVATION_END_DATE, new DayTimeParserFormatter(locale)); - modelBuilder.newColumnForImportExport("CONTACT_SAISIE_DONNEES", Contact.PROPERTY_DATA_INPUT_DATE, new DayParserFormatter(locale)); + if (obsProgram.isObsMer() || obsProgram.isObsVente()) { + modelBuilder.newColumnForImportExport("CONTACT_SAISIE_DONNEES", Contact.PROPERTY_DATA_INPUT_DATE, new DayParserFormatter(locale)); + } + if (obsProgram.isSclerochronology()) { + modelBuilder.newColumnForImportExport("CONTACT_NOMBRE_INDIVIDUS", Contact.PROPERTY_SAMPLE_SIZE, Common.PRIMITIVE_INTEGER); + modelBuilder.newColumnForImportExport("CONTACT_DATE_ENVOI_ECHANTILLON", Contact.PROPERTY_SAMPLE_SUBMISSION, new DayParserFormatter(locale)); + modelBuilder.newColumnForImportExport("CONTACT_DATE_RECEPTION_ECHANTILLON", Contact.PROPERTY_SAMPLE_RECEPTION, new DayParserFormatter(locale)); + modelBuilder.newColumnForImportExport("CONTACT_DATE_TRAITEMENT_ECHANTILLON", Contact.PROPERTY_SAMPLE_TREATMENT, new DayParserFormatter(locale)); + } modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_OBSERVATEUR", Contact.PROPERTY_COMMENT); modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_COORDINATEUR", Contact.PROPERTY_COMMENT_COORDINATOR); modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_PROGRAMME", Contact.PROPERTY_COMMENT_ADMIN); + if (obsProgram.isObsMer() || obsProgram.isObsVente()) { + modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats, locale)); + modelBuilder.newIgnoredColumn("NAVIRE_NOM"); + modelBuilder.newColumnForExport("NAVIRE_NOM", new ValueGetter<Contact, String>() { - modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats, locale)); - modelBuilder.newIgnoredColumn("NAVIRE_NOM"); - modelBuilder.newColumnForExport("NAVIRE_NOM", new ValueGetter<Contact, String>() { - @Override - public String get(Contact contact) { - return contact.getBoat().getName(); - } - }); + @Override + public String get(Contact contact) { + return contact.getBoat().getName(); + } + }); + } modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_SOCIETE", Contact.PROPERTY_VALIDATION_COMPANY, Common.BOOLEAN); modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_PROGRAMME", Contact.PROPERTY_VALIDATION_PROGRAM, Common.BOOLEAN); diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java index ed7f169..946d207 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java @@ -22,7 +22,9 @@ package fr.ifremer.wao.services.service; */ import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.services.AbstractWaoServiceTest; +import fr.ifremer.wao.services.AuthenticatedWaoUser; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,12 +43,15 @@ public class ContactsServiceTest extends AbstractWaoServiceTest { protected ContactsService service; - protected ObsMerFixtures fixtures; + protected ObsMerFixtures obsMerfixtures; + + protected SclerochronologyFixtures sclerochronologyFixtures; @Before public void setUp() { service = newService(ContactsService.class); - fixtures = new ObsMerFixtures(newServiceContext()); + obsMerfixtures = new ObsMerFixtures(newServiceContext()); + sclerochronologyFixtures = new SclerochronologyFixtures(newServiceContext()); } protected boolean isDatabaseWithReferential() { @@ -56,26 +61,26 @@ public class ContactsServiceTest extends AbstractWaoServiceTest { @Test public void testGetContactsFilterValues() { - ContactsFilter filter = service.newContactFilter(fixtures.admin()); + ContactsFilter filter = service.newContactFilter(obsMerfixtures.admin()); - ContactsFilterValues filterValues = service.getContactsFilterValues(fixtures.admin(), filter); + ContactsFilterValues filterValues = service.getContactsFilterValues(obsMerfixtures.admin(), filter); } @Test public void testGetContactsList() { - ContactsFilter filter = service.newContactFilter(fixtures.admin()); + ContactsFilter filter = service.newContactFilter(obsMerfixtures.admin()); PaginationParameter pager = service.newContactsPaginationParameter(0, 50); - ObsMerContactsList contactsList = service.getContactsList(fixtures.admin(), filter, pager); + ContactsList contactsList = service.getContactsList(obsMerfixtures.admin(), filter, pager); } @Test public void testImportContacts() { - fixtures.samplingPlan(); - fixtures.jmichmuche(); - fixtures.navires(); + obsMerfixtures.samplingPlan(); + obsMerfixtures.jmichmuche(); + obsMerfixtures.navires(); // today must be after the observation end date applicationContext.setDate(DateUtil.createDate(1, 2, 2011)); @@ -85,7 +90,7 @@ public class ContactsServiceTest extends AbstractWaoServiceTest { Assert.assertEquals(0, service.getContactDao().count()); input = getClass().getResourceAsStream("/import/contacts.csv"); - service.importContacts(fixtures.admin(), input); + service.importContacts(obsMerfixtures.admin(), input); Assert.assertEquals(2, service.getContactDao().count()); } catch (ImportErrorException e) { if (log.isDebugEnabled()) { @@ -97,4 +102,31 @@ public class ContactsServiceTest extends AbstractWaoServiceTest { } } + @Test + public void testImportsSclerochronologyContacts() { + AuthenticatedWaoUser bob = sclerochronologyFixtures.bob(); + applicationContext.setDate(DateUtil.createDate(0, 0, 12, 15, 1, 2015)); + sclerochronologyFixtures.samplingPlan(); + applicationContext.setDate(DateUtil.createDate(0, 0, 12, 15, 2, 2015)); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/contacts-sclerochronologie.csv"); + service.importContacts(sclerochronologyFixtures.admin(), input); + } catch (ImportErrorException e) { + if (log.isDebugEnabled()) { + log.debug("unexpected exception raised", e); + } + Assert.fail("exception should not be raised"); + } finally { + IOUtils.closeQuietly(input); + } + + ContactsFilter filter = service.newContactFilter(bob); + ContactsList contactsList = service.getContactsList(bob, filter, PaginationParameter.of(0, 20)); + Assert.assertEquals(1, contactsList.getContacts().getCount()); + for (Contact contact : contactsList.getContacts().getElements()) { + Assert.assertNotNull(contact.getBoat()); + } + } + } diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java index 5c97dd3..b3a2c70 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java @@ -70,4 +70,22 @@ public class SclerochronologyFixtures extends WaoFixtures { IOUtils.closeQuietly(input); } } + + public AuthenticatedWaoUser bob() { + return newAuthenticatedWaoUser("bob", ObsProgram.SCLEROCHRONOLOGY, UserRole.OBSERVER, oceanet()); + } + + public void contacts() { + bob(); + samplingPlan(); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/contacts-sclerochronologie.csv"); + serviceContext.newService(ContactsService.class).importContacts(admin(), input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } } diff --git a/wao-services/src/test/resources/import/contacts-sclerochronologie.csv b/wao-services/src/test/resources/import/contacts-sclerochronologie.csv new file mode 100644 index 0000000..4e0288b --- /dev/null +++ b/wao-services/src/test/resources/import/contacts-sclerochronologie.csv @@ -0,0 +1,2 @@ +CONTACT_ID;CONTACT_DATE_CREATION;CONTACT_OBSERVATEUR_PRINCIPAL;CONTACT_OBSERVATEURS_SECONDAIRES;CONTACT_OBSERVATEURS_NOMS;CONTACT_OBSERVATEURS_ORGANISATION;CONTACT_ETAT;CONTACT_DEBUT_OBSERVATION;CONTACT_FIN_OBSERVATION;CONTACT_NOMBRE_INDIVIDUS;CONTACT_DATE_ENVOI_ECHANTILLON;CONTACT_DATE_RECEPTION_ECHANTILLON;CONTACT_DATE_TRAITEMENT_ECHANTILLON;CONTACT_COMMENTAIRE_OBSERVATEUR;CONTACT_COMMENTAIRE_COORDINATEUR;CONTACT_COMMENTAIRE_PROGRAMME;CONTACT_VALIDATION_SOCIETE;CONTACT_VALIDATION_PROGR [...] +;22/01/2015 03:00;bob;;;OCEANET;Observation réalisée;16/01/2015 09:00;16/01/2015 17:00;53;17/01/2015;19/01/2015;21/01/2015;;;;Y;Y;2015_S0001;CAMPAGNE 22 diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java index 43f7a16..d1fbc5a 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java @@ -32,7 +32,7 @@ import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.service.ContactsFilterValues; import fr.ifremer.wao.services.service.ContactsService; -import fr.ifremer.wao.services.service.ObsMerContactsList; +import fr.ifremer.wao.services.service.ContactsList; import fr.ifremer.wao.web.WaoJspActionSupport; import org.apache.commons.lang3.time.DateUtils; import org.nuiton.i18n.I18n; @@ -70,7 +70,7 @@ public class ContactsAction extends WaoJspActionSupport implements Preparable { /** * List of contacts according to the input pager and filter. */ - protected ObsMerContactsList contactsList; + protected ContactsList contactsList; public void setService(ContactsService service) { this.service = service; -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 7ab5f4e43329ad91505e74b4f9a153856768615d Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 10:57:10 2014 +0100 Correction d'un lien pour la création d'un utilisateur --- wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp b/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp index 57028bd..5cd7db0 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/administration/wao-users.jsp @@ -100,7 +100,7 @@ <div class="form-actions"> <s:url action="edit-wao-user!input" id="createWaoUserUrl"> - <s:param name="companyId" value="%{companyId}" /> + <s:param name="organisationId" value="%{waoUsersList.organisation.topiaId}" /> </s:url> <s:a href="%{createWaoUserUrl}" cssClass="btn float-right"> <i class="icon-plus"></i> <s:text name="wao.ui.action.createWaoUser" /> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 2a485b8a1f2764cfd900b2b1f2a4e8a1cbadd50c Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 10:57:32 2014 +0100 Ouverture de l'accès à l'onglet « Contacts » --- wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp b/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp index 7f9a39f..3a308f1 100644 --- a/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp +++ b/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp @@ -138,15 +138,13 @@ </li> </s:if> </s:if> - <s:if test=" ! sclerochronology"> - <s:if test="authenticatedWaoUser.authorizedToViewContacts"> - <li class="<decorator:getProperty property="page.contactsMenuItemClass"/>"> - <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="contacts" id="contactsUrl" /> - <s:a href="%{contactsUrl}"> - <i class="fa fa-stack-exchange"></i> <s:text name="wao.ui.page.Contacts.title" /> - </s:a> - </li> - </s:if> + <s:if test="authenticatedWaoUser.authorizedToViewContacts"> + <li class="<decorator:getProperty property="page.contactsMenuItemClass"/>"> + <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="contacts" id="contactsUrl" /> + <s:a href="%{contactsUrl}"> + <i class="fa fa-stack-exchange"></i> <s:text name="wao.ui.page.Contacts.title" /> + </s:a> + </li> </s:if> <s:if test=" ! sclerochronology"> <s:if test="authenticatedWaoUser.authorizedToViewSynthesis"> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 529a0b8ea58bb2efd9fda20fc6fcf4f698b15e0c Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 15:47:17 2014 +0100 On rétrograde la version de struts car on a plus les traces en cas d'erreur --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bca0260..839b624 100644 --- a/pom.xml +++ b/pom.xml @@ -111,7 +111,7 @@ <commonsBeanutilsVersion>1.9.2</commonsBeanutilsVersion> <commonsIoVersion>2.4</commonsIoVersion> <h2Version>1.3.176</h2Version> - <struts2Version>2.3.20</struts2Version> + <struts2Version>2.3.16.3</struts2Version> <jqueryPluginVersion>3.7.1</jqueryPluginVersion> <bootstrapPluginVersion>1.7.0</bootstrapPluginVersion> <slf4jVersion>1.7.9</slf4jVersion> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit a6674c177f99316a6ee72ab3d5ff2fc791cf749b Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 15:48:50 2014 +0100 Activivation de la création d'un contact sous scléro --- .../fr/ifremer/wao/entity/ContactTopiaDao.java | 4 +- .../ifremer/wao/services/service/BoatsService.java | 5 +- .../wao/services/service/ContactsService.java | 72 ++++++++++++++-------- .../services/service/SampleRowsFilterValues.java | 18 ++++-- .../services/service/UpdateSampleRowCommand.java | 2 +- .../wao/services/service/ContactsServiceTest.java | 26 ++++++++ .../services/service/SclerochronologyFixtures.java | 15 +++++ .../wao/web/action/CreateContactAction.java | 6 +- .../ifremer/wao/web/action/EditContactAction.java | 2 +- .../content/sclerochronology/sampling-plan.jsp | 16 +---- 10 files changed, 114 insertions(+), 52 deletions(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java index fd5ba51..fa642d2 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/ContactTopiaDao.java @@ -199,9 +199,9 @@ public class ContactTopiaDao extends AbstractContactTopiaDao<Contact> { } - public Contact findMostRecentContactOrNull(ObsProgram obsProgram, String boatId, String companyId) { + public Contact findMostRecentContactOrNull(ObsProgram obsProgram, Boat boat, String companyId) { TopiaQueryBuilderAddCriteriaOrRunQueryStep<Contact> query = newQueryBuilder(); - query.addTopiaIdEquals(Contact.PROPERTY_BOAT, boatId); + query.addEquals(Contact.PROPERTY_BOAT, boat); query.addTopiaIdEquals(Contact.PROPERTY_SAMPLE_ROW + "." + SampleRow.PROPERTY_ORGANISATION, companyId); query.addEquals(Contact.PROPERTY_SAMPLE_ROW + "." + SampleRow.PROPERTY_OBS_PROGRAM, obsProgram); query.setOrderByArguments(Contact.PROPERTY_CREATION_DATE + " desc"); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java index 1deab18..71458de 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java @@ -202,7 +202,7 @@ public class BoatsService extends WaoServiceSupport { BoatInfos boatInfos = getBoatInfos(boatId, companyId); - Contact mostRecentContact = getContactDao().findMostRecentContactOrNull(obsProgram, boatId, companyId); + Contact mostRecentContact = getContactDao().findMostRecentContactOrNull(obsProgram, boatInfos.getBoat(), companyId); ContactsFilter filter = new ContactsFilter(); filter.getSampleRowFilter().setObsProgram(obsProgram); @@ -336,7 +336,8 @@ public class BoatsService extends WaoServiceSupport { dao.create(Boat.PROPERTY_REGISTRATION_CODE, dedicatedBoatRegistrationCode, Boat.PROPERTY_SHIP_OWNER, getFictiveShipownerForSclerochronology(), - Boat.PROPERTY_NAME, "" + Boat.PROPERTY_NAME, "", + Boat.PROPERTY_ACTIVE, true ); } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java index fc7c3fc..c7aafc3 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java @@ -104,10 +104,17 @@ public class ContactsService extends WaoServiceSupport { ContactsFilter newContactsFilter = newEmptyContactsFilter(obsProgram); - // DO NOT REMOVE THIS + // ATTENTION, il s'agit de sécu if (authenticatedWaoUser.isCoordinatorOrObserver()) { - String authenticatedWaoUserCompanyTopiaId = authenticatedWaoUser.getWaoUser().getCompany().getTopiaId(); - newContactsFilter.getSampleRowFilter().setOrganisationIds(ImmutableSet.of(authenticatedWaoUserCompanyTopiaId)); + // quand on appartient à une organisation (société ou labo), par défaut on ne peut voir + // que les lignes de cette même organisation + Organisation organisationToFilterOn = authenticatedWaoUser.getOrganisation(); + if (obsProgram.isObsMer() || obsProgram.isObsVente()) { + // dans ce cas, on est plus souple : si on appartient à des labos différents mais à + // la même société, on peut voir tout ce qui concerne la société tous labos confondus + organisationToFilterOn = authenticatedWaoUser.getOrganisation().getCompany(); + } + newContactsFilter.getSampleRowFilter().setOrganisationIds(ImmutableSet.of(organisationToFilterOn.getTopiaId())); } if (authenticatedWaoUser.isProfessional()) { @@ -929,10 +936,10 @@ public class ContactsService extends WaoServiceSupport { boolean addBoatToObserversAllegroWallet = false; - if (obsProgram == ObsProgram.OBSMER) { + if (obsProgram.isObsMer()) { addBoatToObserversAllegroWallet = contactState == ContactState.OBSERVATION_DONE || contactState == ContactState.OBSERVATION_EXPECTED; - } else if (obsProgram == ObsProgram.OBSVENTE) { + } else if (obsProgram.isObsVente()) { addBoatToObserversAllegroWallet = ContactState.OBSERVATION_DONE == contactState; } @@ -1034,46 +1041,61 @@ public class ContactsService extends WaoServiceSupport { } } - public Contact createContact(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, String boatId) { - + public Contact createContact(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, Optional<String> optionalBoatId) { + if (log.isInfoEnabled()) { - log.info(authenticatedWaoUser.getWaoUser() + " is creating a contact for " + sampleRowId + " and " + boatId); + log.info(authenticatedWaoUser.getWaoUser() + " is creating a contact for " + sampleRowId + " and " + optionalBoatId); } - UpdateContactCommand updateContactCommand = newUpdateContactCommandForCreation(authenticatedWaoUser); + SampleRow sampleRow = getSampleRowDao().forTopiaIdEquals(sampleRowId).findUnique(); + ObsProgram obsProgram = sampleRow.getObsProgram(); - Boat boat = getBoatDao().findByTopiaId(boatId); - Preconditions.checkState(boat.isActive(), "boat must be active"); + Boat boat; + if (obsProgram.isSclerochronology()) { + boat = getBoatsService().getBoatToUseForSclerochronologySampleRow(sampleRow); + } else { + Preconditions.checkArgument(optionalBoatId.isPresent(), "boatId must be provided for contact creation"); + String boatId = optionalBoatId.get(); + boat = getBoatDao().forTopiaIdEquals(boatId).findUnique(); + } - SampleRow sampleRow = getSampleRowDao().findByTopiaId(sampleRowId); - ObsProgram obsProgram = sampleRow.getObsProgram(); + Preconditions.checkState(boat.isActive(), "boat must be active"); - WaoUser observer = authenticatedWaoUser.getWaoUser(); - Contact mostRecentContactOrNull = getContactDao().findMostRecentContactOrNull(obsProgram, boatId, observer.getCompany().getTopiaId()); + WaoUser mainObserver = authenticatedWaoUser.getWaoUser(); Preconditions.checkState( - mostRecentContactOrNull == null || mostRecentContactOrNull.getContactState().isFinalState(), - "contact already exists"); + getPossibleObservers(sampleRow).contains(mainObserver), + authenticatedWaoUser + " is not allowed to create a contact for row " + sampleRow); + + if (obsProgram.isObsMer() || obsProgram.isObsVente()) { + Contact mostRecentContactOrNull = getContactDao().findMostRecentContactOrNull(obsProgram, boat, mainObserver.getCompany().getTopiaId()); + Preconditions.checkState( + mostRecentContactOrNull == null || mostRecentContactOrNull.getContactState().isFinalState(), + "contact already exists"); + } Date now = serviceContext.getNow(); + UpdateContactCommand updateContactCommand = newUpdateContactCommandForCreation(authenticatedWaoUser); Contact newContact = updateContactCommand.getContact(); newContact.setDataReliability(DataReliability.UNKNOWN); newContact.setBoat(boat); - newContact.setMainObserver(observer); newContact.setSampleRow(sampleRow); newContact.setCreationDate(now); + newContact.setMainObserver(mainObserver); // initial contact state depends on the program - if (obsProgram == ObsProgram.OBSMER) { + if (obsProgram.isObsMer()) { newContact.setContactState(ContactState.CONTACT_START); - } else if (obsProgram == ObsProgram.OBSVENTE) { + } else if (obsProgram.isObsVente() || obsProgram.isSclerochronology()) { newContact.setContactState(ContactState.OBSERVATION_EXPECTED); + } else { + throw new UnsupportedOperationException("program " + obsProgram); } // we can suppose a new contact default values are the one // expected in the sampling plan - if (newContact.getObsProgram() == ObsProgram.OBSVENTE) { + if (newContact.getObsProgram().isObsVente()) { // we hope in this contact, user used expected sampling strategy newContact.setSamplingStrategy(sampleRow.getSamplingStrategy()); } @@ -1083,14 +1105,14 @@ public class ContactsService extends WaoServiceSupport { // of data by trying to pre-fill some field using data given // in a previous entered contact - if (newContact.getObsProgram() == ObsProgram.OBSVENTE) { + if (newContact.getObsProgram().isObsVente()) { // try to pre-fill some field for user-experience // let's try to find a recent similar contact Map<String, Object> properties = new HashMap<>(); properties.put(Contact.PROPERTY_SAMPLE_ROW + "." + SampleRow.PROPERTY_OBS_PROGRAM, newContact.getObsProgram()); properties.put(Contact.PROPERTY_SAMPLE_ROW, sampleRow); - properties.put(Contact.PROPERTY_MAIN_OBSERVER, observer); + properties.put(Contact.PROPERTY_MAIN_OBSERVER, mainObserver); List<Contact> candidates = getContactDao().forProperties(properties).findAll(); @@ -1134,9 +1156,9 @@ public class ContactsService extends WaoServiceSupport { * Pour un contact donné, tous les utilisateurs qui peuvent être sélectionnés en tant qu' * observateurs (principale ou secondaire). */ - public SortedSet<WaoUser> getPossibleObservers(Contact contact) { + public SortedSet<WaoUser> getPossibleObservers(SampleRow sampleRow) { - Organisation organisation = contact.getSampleRow().getOrganisation(); + Organisation organisation = sampleRow.getOrganisation(); Set<Organisation> organisationsUserMustBeInToBeAnObserver = getOrganisationsService().getOrganisationsBelongingsTo(organisation); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SampleRowsFilterValues.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SampleRowsFilterValues.java index 4184fc4..824701d 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SampleRowsFilterValues.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SampleRowsFilterValues.java @@ -84,16 +84,22 @@ public class SampleRowsFilterValues extends AbstractFilterValues { protected void addSampleRow(SampleRow sampleRow, boolean fromBoatFilter) { boolean sampleRowMatchesObsProgram = obsProgram.equals(sampleRow.getObsProgram()); - boolean sampleRowMatchesCompany = true; + boolean sampleRowMatchesOrganisation = true; if (optionalCompanyId.isPresent()) { - String sampleRowCompanyId = null; - if (sampleRow.getCompany() != null) { - sampleRowCompanyId = sampleRow.getCompany().getTopiaId(); + String sampleRowOrganisationId = null; + if (sampleRow.getOrganisation() != null) { + sampleRowOrganisationId = sampleRow.getOrganisation().getTopiaId(); } - sampleRowMatchesCompany = optionalCompanyId.get().equals(sampleRowCompanyId); + sampleRowMatchesOrganisation = optionalCompanyId.get().equals(sampleRowOrganisationId); } - if (sampleRowMatchesObsProgram && sampleRowMatchesCompany) { + // par exemple, dans le cas du filtre navire, la présente méthode est appelée pour toutes les + // lignes pour lesquelles la navire est éligible, or on ne veut les données que pour les lignes + // du programme sous lequel l'utilisateur est connecté et on ne veux que les lignes du plan + // affecté à sa société (alors que l'admin voit tout) + boolean addSampleRow = sampleRowMatchesObsProgram + && sampleRowMatchesOrganisation; + if (addSampleRow) { for (FishingZone fishingZone : sampleRow.getFishingZone()) { fishingZoneFacadeNames.add(FilterOption.forString(fishingZone.getFacadeName())); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java index 3641d36..b3f58e7 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java @@ -114,7 +114,7 @@ public class UpdateSampleRowCommand implements Serializable{ public String getOrganisationId() { String organisationId = null; - if (sampleRow.getCompany() != null) { + if (sampleRow.getOrganisation() != null) { organisationId = sampleRow.getOrganisation().getTopiaId(); } return organisationId; diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java index 946d207..003b07b 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java @@ -21,8 +21,11 @@ package fr.ifremer.wao.services.service; * #L% */ +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.AbstractWaoServiceTest; import fr.ifremer.wao.services.AuthenticatedWaoUser; import org.apache.commons.io.IOUtils; @@ -129,4 +132,27 @@ public class ContactsServiceTest extends AbstractWaoServiceTest { } } + @Test + public void testCreateSclerochronologyContact() { + AuthenticatedWaoUser alex = sclerochronologyFixtures.alex(); + applicationContext.setDate(DateUtil.createDate(0, 0, 12, 15, 1, 2015)); + + SampleRow sampleRow = sclerochronologyFixtures.sampleRow3(); + String sampleRowId = sampleRow.getTopiaId(); + applicationContext.setDate(DateUtil.createDate(0, 0, 12, 15, 2, 2015)); + + Contact contact = service.createContact(alex, sampleRowId, Optional.<String>absent()); + + Assert.assertTrue(contact.isPersisted()); + Assert.assertEquals( + "Le contact aurait dû être rattaché au navire dédié selon le contexte de la ligne du plan", + sampleRow.getSclerochronologySamplingContext().getDedicatedBoatRegistrationCode(), + contact.getBoat().getRegistrationCode()); + + ContactsFilter filter = service.newContactFilter(alex); + ContactsList contactsList = service.getContactsList(alex, filter, PaginationParameter.of(0, 5)); + Assert.assertEquals(1, contactsList.getContacts().getCount()); + Assert.assertEquals(contact, Iterables.getOnlyElement(contactsList.getContacts().getElements())); + + } } diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java index b3a2c70..57b818c 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java @@ -3,6 +3,7 @@ package fr.ifremer.wao.services.service; import fr.ifremer.wao.WaoTechnicalException; import fr.ifremer.wao.entity.Laboratory; import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.UserRole; import fr.ifremer.wao.services.AuthenticatedWaoUser; import fr.ifremer.wao.services.WaoServiceContext; @@ -71,10 +72,24 @@ public class SclerochronologyFixtures extends WaoFixtures { } } + public SampleRow sampleRow1() { + samplingPlan(); + return serviceContext.getPersistenceContext().getSampleRowDao().forCodeEquals("2015_S0001").findUnique(); + } + + public SampleRow sampleRow3() { + samplingPlan(); + return serviceContext.getPersistenceContext().getSampleRowDao().forCodeEquals("2015_S0003").findUnique(); + } + public AuthenticatedWaoUser bob() { return newAuthenticatedWaoUser("bob", ObsProgram.SCLEROCHRONOLOGY, UserRole.OBSERVER, oceanet()); } + public AuthenticatedWaoUser alex() { + return newAuthenticatedWaoUser("alex", ObsProgram.SCLEROCHRONOLOGY, UserRole.OBSERVER, emh()); + } + public void contacts() { bob(); samplingPlan(); diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java index 3403117..4698660 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java @@ -21,6 +21,8 @@ package fr.ifremer.wao.web.action; * #L% */ +import com.google.common.base.Optional; +import com.google.common.base.Strings; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.services.service.ContactsService; import fr.ifremer.wao.web.WaoJspActionSupport; @@ -34,7 +36,7 @@ public class CreateContactAction extends WaoJspActionSupport { protected ContactsService service; - protected String boatId; + protected Optional<String> boatId = Optional.absent(); protected String sampleRowId; @@ -43,7 +45,7 @@ public class CreateContactAction extends WaoJspActionSupport { } public void setBoatId(String boatId) { - this.boatId = boatId; + this.boatId = Optional.fromNullable(Strings.emptyToNull(boatId)); } public void setSampleRowId(String sampleRowId) { diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java index 4a5ca9a..e408c20 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java @@ -200,7 +200,7 @@ public class EditContactAction extends WaoJspActionSupport implements Preparable addActionError(t("wao.ui.error.unknownContactId")); } - SortedSet<WaoUser> sortedWaoUsers = service.getPossibleObservers(updateContactCommand.getContact()); + SortedSet<WaoUser> sortedWaoUsers = service.getPossibleObservers(updateContactCommand.getContact().getSampleRow()); observers = new LinkedHashMap<>(); for (WaoUser waoUser : sortedWaoUsers) { observers.put(waoUser.getTopiaId(), waoUser.getFullName()); diff --git a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp index 3511394..0082bc8 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp @@ -382,16 +382,6 @@ <i class="icon-filter"></i> <s:text name="wao.ui.action.zoomOnSampleRowPeriod" /> </s:a> </li> - <s:if test="authenticatedWaoUser.authorizedToViewBoats && elligibleBoatsProvided"> - <li> - <s:url action="boats!applyFilter" id="viewElligibleBoatsUrl"> - <s:param name="filter.elligibleForSampleRowsFilter.sampleRowCodes" value="code" /> - </s:url> - <s:a href="%{viewElligibleBoatsUrl}"> - <i class="fa fa-anchor"></i> <s:text name="wao.ui.action.viewElligibleBoats" /> - </s:a> - </li> - </s:if> <s:if test="authenticatedWaoUser.authorizedToViewContacts && sampleRowContactCounts > 0"> <li> <s:url action="contacts!applyFilter" id="viewAssociatedContactsUrl"> @@ -406,10 +396,10 @@ </s:if> <s:if test="authenticatedWaoUser.authorizedToCreateContact && newContactCreatable"> <li> - <s:url action="boats!applyFilter" id="createAssociatedContactUrl"> - <s:param name="startBoatSelectionForSampleRowId" value="sampleRowId" /> + <s:url action="create-contact" id="createContactUrl"> + <s:param name="sampleRowId" value="sampleRowId" /> </s:url> - <s:a href="%{createAssociatedContactUrl}"> + <s:a href="%{createContactUrl}"> <i class="icon-plus"></i> <s:text name="wao.ui.action.createAssociatedContact" /> </s:a> </li> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2264 in repository wao. See http://git.codelutin.com/wao.git commit 912ef1e1fd070bec6fcc878afbfcffea2aa902d6 Author: Brendan Le Ny <bleny@codelutin.com> Date: Wed Dec 24 16:31:14 2014 +0100 Ébauche du formulaire de modification d'un contact scléro --- .../wao/services/service/ContactsService.java | 38 ++--- ...ismatchContactMainObserverCompanyException.java | 12 +- ...chContactSecondaryObserverCompanyException.java | 12 +- .../resources/i18n/wao-services_en_GB.properties | 2 +- .../resources/i18n/wao-services_fr_FR.properties | 2 +- .../wao/services/service/ContactsServiceTest.java | 17 +++ .../services/service/SclerochronologyFixtures.java | 11 ++ .../ifremer/wao/web/action/EditContactAction.java | 8 +- .../wao/web/action/ValidateContactJsonAction.java | 4 +- .../main/resources/i18n/wao-web_en_GB.properties | 6 +- .../main/resources/i18n/wao-web_fr_FR.properties | 6 +- .../webapp/WEB-INF/content/edit-contact-input.jsp | 155 +++++++++++++-------- 12 files changed, 168 insertions(+), 105 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java index c7aafc3..798e593 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java @@ -31,7 +31,6 @@ import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.WaoTechnicalException; import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactImpl; import fr.ifremer.wao.entity.ContactState; @@ -473,9 +472,9 @@ public class ContactsService extends WaoServiceSupport { String message = l(l, "wao.import.contact.failure.missingComment", state, lineNumber); throw new ImportErrorException(message); } catch (MismatchContactMainObserverCompanyException e) { - String companyName = e.getCompany().getName(); + String organisationName = e.getOrganisation().getName(); String observerLogin = e.getObserver().getLogin(); - String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); + String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, organisationName); throw new ImportErrorException(message); } catch (ContactRestitutionDateBeforeDataInputDateException e) { String message = l(l, "wao.import.contact.failure.transmissionDateBeforeDataInputDate", lineNumber); @@ -490,9 +489,9 @@ public class ContactsService extends WaoServiceSupport { String message = l(l, "wao.import.contact.failure.missingDataReliability", lineNumber); throw new ImportErrorException(message); } catch (MismatchContactSecondaryObserverCompanyException e) { - String companyName = e.getCompany().getName(); + String organisationName = e.getOrganisation().getName(); String observerLogin = e.getObserver().getLogin(); - String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); + String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, organisationName); throw new ImportErrorException(message); } catch (MissingContactObservedDataControlException e) { String message = l(l, "wao.import.contact.failure.missingObservedDataControl", lineNumber); @@ -608,23 +607,17 @@ public class ContactsService extends WaoServiceSupport { // Pass validation controls Contact contact = updateContactCommand.getContact(); - Company company = contact.getSampleRow().getCompany(); + SampleRow sampleRow = contact.getSampleRow(); WaoUser mainObserver = contact.getMainObserver(); - { - //--- - // mainObserver - //--- - - if (mainObserver == null) { - throw new MissingContactMainObserverException(contact); - } + if (mainObserver == null) { + throw new MissingContactMainObserverException(contact); + } - boolean observerWorksForCompanyInSampleRow = mainObserver.getCompany().equals(company); - if (!observerWorksForCompanyInSampleRow) { - throw new MismatchContactMainObserverCompanyException(contact, mainObserver, company); - } + Set<WaoUser> possibleObservers = getPossibleObservers(sampleRow); + if ( ! possibleObservers.contains(mainObserver)) { + throw new MismatchContactMainObserverCompanyException(contact, mainObserver, sampleRow.getOrganisation()); } if (contact.isSecondaryObserversNotEmpty()) { @@ -637,10 +630,9 @@ public class ContactsService extends WaoServiceSupport { throw new DuplicatedContactMainObserverInSecondaryObserversException(contact); } - for (WaoUser observer : contact.getSecondaryObservers()) { - boolean observerWorksForCompanyInSampleRow = observer.getCompany().equals(company); - if (!observerWorksForCompanyInSampleRow) { - throw new MismatchContactSecondaryObserverCompanyException(contact, observer, company); + for (WaoUser secondaryObserver : contact.getSecondaryObservers()) { + if ( ! possibleObservers.contains(secondaryObserver)) { + throw new MismatchContactSecondaryObserverCompanyException(contact, secondaryObserver, sampleRow.getOrganisation()); } } } @@ -649,8 +641,6 @@ public class ContactsService extends WaoServiceSupport { Date observationEndDate = contact.getObservationEndDate(); Date dataInputDate = contact.getDataInputDate(); - SampleRow sampleRow = contact.getSampleRow(); - if (observationBeginDate != null) { //--- diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactMainObserverCompanyException.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactMainObserverCompanyException.java index f5a2a61..ea13dff 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactMainObserverCompanyException.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactMainObserverCompanyException.java @@ -21,8 +21,8 @@ package fr.ifremer.wao.services.service; * #L% */ -import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.Organisation; import fr.ifremer.wao.entity.WaoUser; /** @@ -35,18 +35,18 @@ public class MismatchContactMainObserverCompanyException extends ContactValidati private static final long serialVersionUID = 1L; - protected Company company; + protected Organisation organisation; protected WaoUser observer; - public MismatchContactMainObserverCompanyException(Contact contact, WaoUser observer, Company company) { + public MismatchContactMainObserverCompanyException(Contact contact, WaoUser observer, Organisation organisation) { super(contact); - this.company = company; + this.organisation = organisation; this.observer = observer; } - public Company getCompany() { - return company; + public Organisation getOrganisation() { + return organisation; } public WaoUser getObserver() { diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactSecondaryObserverCompanyException.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactSecondaryObserverCompanyException.java index 8a9b0d8..e41e04e 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactSecondaryObserverCompanyException.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/MismatchContactSecondaryObserverCompanyException.java @@ -21,8 +21,8 @@ package fr.ifremer.wao.services.service; * #L% */ -import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.Organisation; import fr.ifremer.wao.entity.WaoUser; /** @@ -37,19 +37,19 @@ public class MismatchContactSecondaryObserverCompanyException extends ContactVal protected WaoUser observer; - protected Company company; + protected Organisation organisation; - public MismatchContactSecondaryObserverCompanyException(Contact contact, WaoUser observer, Company company) { + public MismatchContactSecondaryObserverCompanyException(Contact contact, WaoUser observer, Organisation organisation) { super(contact); this.observer = observer; - this.company = company; + this.organisation = organisation; } public WaoUser getObserver() { return observer; } - public Company getCompany() { - return company; + public Organisation getOrganisation() { + return organisation; } } diff --git a/wao-services/src/main/resources/i18n/wao-services_en_GB.properties b/wao-services/src/main/resources/i18n/wao-services_en_GB.properties index 77607c5..47dcf3e 100644 --- a/wao-services/src/main/resources/i18n/wao-services_en_GB.properties +++ b/wao-services/src/main/resources/i18n/wao-services_en_GB.properties @@ -41,7 +41,7 @@ wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers=Main obser wao.import.contact.failure.illegalAcceptation=Contact must be accepted by company before being accepted by program wao.import.contact.failure.invalidObservationBeginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.import.contact.failure.locationTypeMissing=The type of the location must be filled -wao.import.contact.failure.mismatchCompanyForObserver=L'observateur %s n'est pas membre de la société %s +wao.import.contact.failure.mismatchCompanyForObserver=Observer %s is not member of %s wao.import.contact.failure.missingComment=You must give a comment for state '%s' wao.import.contact.failure.missingCommentAdmin=You must precise in admin comment why data reliability is '%s' wao.import.contact.failure.missingContactMammalsInfo=You must provide information about capture diff --git a/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties b/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties index 01f18dd..a89b1dc 100644 --- a/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties +++ b/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties @@ -39,7 +39,7 @@ wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers=L'utilisat wao.import.contact.failure.illegalAcceptation=Le contact doit être accepté par la société avant d'être accepté par le programme 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=Ligne %s \: L'observateur %s n'est pas membre de la société %s +wao.import.contact.failure.mismatchCompanyForObserver=Ligne %s \: L'observateur %s n'est pas membre de %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.missingContactMammalsInfo=Ligne %s \: Il faut préciser le détail des espèces capturées diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java index 003b07b..259d8e2 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java @@ -155,4 +155,21 @@ public class ContactsServiceTest extends AbstractWaoServiceTest { Assert.assertEquals(contact, Iterables.getOnlyElement(contactsList.getContacts().getElements())); } + + @Test + public void testModifyContact() { + AuthenticatedWaoUser alex = sclerochronologyFixtures.alex(); + Contact contact = sclerochronologyFixtures.contact(); + try { + UpdateContactCommand updateContactCommand = service.newUpdateContactCommand(alex, contact.getTopiaId()); + service.preValidate(updateContactCommand); + service.validate(alex, updateContactCommand); + service.save(updateContactCommand); + } catch (ContactValidationException | ContactNotUpdatableException | UnknownContactIdException e) { + if (log.isDebugEnabled()) { + log.debug("unexpected exception", e); + } + Assert.fail("no exception expected"); + } + } } diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java index 57b818c..77a5bfa 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java @@ -1,6 +1,8 @@ package fr.ifremer.wao.services.service; +import com.google.common.base.Optional; import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.Laboratory; import fr.ifremer.wao.entity.ObsProgram; import fr.ifremer.wao.entity.SampleRow; @@ -103,4 +105,13 @@ public class SclerochronologyFixtures extends WaoFixtures { IOUtils.closeQuietly(input); } } + + public Contact contact() { + AuthenticatedWaoUser alex = alex(); + SampleRow sampleRow = sampleRow3(); + String sampleRowId = sampleRow.getTopiaId(); + Contact contact = serviceContext.newService(ContactsService.class).createContact(alex, sampleRowId, Optional.<String>absent()); + return contact; + } + } diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java index e408c20..5ce9b9d 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java @@ -279,9 +279,9 @@ public class EditContactAction extends WaoJspActionSupport implements Preparable addFieldError("updateContactCommand.contact.comment", t("wao.ui.form.Contact.error.missingComment", state)); } catch (MismatchContactMainObserverCompanyException e) { - String companyName = e.getCompany().getName(); + String organisationName = e.getOrganisation().getName(); String observerLogin = e.getObserver().getLogin(); - addFieldError("updateContactCommand.contact.mainObserver", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); + addFieldError("updateContactCommand.contact.mainObserver", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, organisationName)); } catch (ContactRestitutionDateBeforeDataInputDateException e) { addFieldError("updateContactCommand.contact.restitution", t("wao.ui.form.Contact.error.transmissionDateBeforeDataInputDate")); @@ -296,9 +296,9 @@ public class EditContactAction extends WaoJspActionSupport implements Preparable addFieldError("updateContactCommand.contact.dataReliability", t("wao.ui.form.Contact.error.missingDataReliability")); } catch (MismatchContactSecondaryObserverCompanyException e) { - String companyName = e.getCompany().getName(); + String organisationName = e.getOrganisation().getName(); String observerLogin = e.getObserver().getLogin(); - addFieldError("updateContactCommand.contact.secondaryObservers", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); + addFieldError("updateContactCommand.contact.secondaryObservers", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, organisationName)); } catch (MissingContactObservedDataControlException e) { addFieldError("updateContactCommand.contact.observedDataControl", t("wao.ui.form.Contact.error.missingObservedDataControl")); diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java index b41f82f..bd62216 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java @@ -196,7 +196,7 @@ public class ValidateContactJsonAction extends WaoJsonActionSupport implements P errorMessage = t("wao.ui.form.Contact.error.missingComment", state); } catch (MismatchContactMainObserverCompanyException e) { - String companyName = e.getCompany().getName(); + String companyName = e.getOrganisation().getName(); String observerLogin = e.getObserver().getLogin(); errorMessage = t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName); @@ -213,7 +213,7 @@ public class ValidateContactJsonAction extends WaoJsonActionSupport implements P errorMessage = t("wao.ui.form.Contact.error.missingDataReliability"); } catch (MismatchContactSecondaryObserverCompanyException e) { - String companyName = e.getCompany().getName(); + String companyName = e.getOrganisation().getName(); String observerLogin = e.getObserver().getLogin(); errorMessage = t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName); diff --git a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties index 397b46f..18dfe5d 100644 --- a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties +++ b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties @@ -228,7 +228,11 @@ wao.ui.field.Contact.observationTimeInDays=Observation time in days wao.ui.field.Contact.observationType=Observation type wao.ui.field.Contact.observedDataControl=Observed Data control wao.ui.field.Contact.restitution=Restitution +wao.ui.field.Contact.sampleReception= wao.ui.field.Contact.sampleRow=Sample row +wao.ui.field.Contact.sampleSize= +wao.ui.field.Contact.sampleSubmission= +wao.ui.field.Contact.sampleTreatment= wao.ui.field.Contact.samplingStrategy=Sampling strategy followed wao.ui.field.Contact.secondaryObservers=Secondary observers wao.ui.field.Contact.terrestrialLocation=Observation's place @@ -309,7 +313,7 @@ wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate=The data input d wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers=The main observer cannot also be a secondary observer wao.ui.form.Contact.error.illegalAcceptationException=Contact must be validated by company before being validated by program wao.ui.form.Contact.error.invalidObservationBeginDate=The observation begin date must be a date in a month with an expected effort in the sampling plan -wao.ui.form.Contact.error.mismatchCompanyForObserver=Observers must belong to the company attached to the sample row +wao.ui.form.Contact.error.mismatchCompanyForObserver=Observer %s is not member of %s wao.ui.form.Contact.error.missingComment=The comment is mandatory wao.ui.form.Contact.error.missingCommentAdmin=The admin comment is mandatory wao.ui.form.Contact.error.missingContactMammalsInfo=You must provide information about captured mammals diff --git a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties index 5ad3387..f917979 100644 --- a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties +++ b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties @@ -229,7 +229,11 @@ wao.ui.field.Contact.observationTimeInDays=Jours d'observation wao.ui.field.Contact.observationType=Type d'observation wao.ui.field.Contact.observedDataControl=Contrôle des données observées wao.ui.field.Contact.restitution=Transmission de la restitution +wao.ui.field.Contact.sampleReception= wao.ui.field.Contact.sampleRow=Ligne du plan +wao.ui.field.Contact.sampleSize= +wao.ui.field.Contact.sampleSubmission= +wao.ui.field.Contact.sampleTreatment= wao.ui.field.Contact.samplingStrategy=Stratégie d'échantillonnage suivie wao.ui.field.Contact.secondaryObservers=Observateurs secondaires wao.ui.field.Contact.terrestrialLocation=Lieu d'observation @@ -310,7 +314,7 @@ wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate=La date de saisi 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.illegalAcceptationException=Le contact doit être accepté par la société avant d'être accepté ou refusé par le programme 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.mismatchCompanyForObserver=L'observateur %s n'est pas membre de %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.missingContactMammalsInfo=Il faut préciser les informations concernants les captures accidentelles diff --git a/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp b/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp index 2029a39..1598c2f 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp @@ -122,52 +122,55 @@ <s:param value="%{formatDate(updateContactCommand.contact.creationDate)}"/> </s:text> - <h3><s:text name="wao.ui.field.Contact.boat"/></h3> - - <table class="table"> - <tbody> - <tr> - <th> - <s:text name="wao.ui.field.Boat.name"/> - </th> - <td> - <s:property value="updateContactCommand.contact.boat.name"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.registrationCode"/> - </th> - <td> - <s:property value="updateContactCommand.contact.boat.registrationCode"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.districtCode"/> - </th> - <td> - <s:property value="updateContactCommand.contact.boat.districtCode"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.boatLength"/> - </th> - <td> - <s:property value="%{'' + updateContactCommand.contact.boat.boatLength}"/> cm. - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.buildYear"/> - </th> - <td> - <s:property value="%{'' + updateContactCommand.contact.boat.buildYear}"/> - </td> - </tr> - </tbody> - </table> + <s:if test="updateContactCommand.contact.obsProgram.obsMer || updateContactCommand.contact.obsProgram.obsVente"> + + <h3><s:text name="wao.ui.field.Contact.boat"/></h3> + + <table class="table"> + <tbody> + <tr> + <th> + <s:text name="wao.ui.field.Boat.name"/> + </th> + <td> + <s:property value="updateContactCommand.contact.boat.name"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.registrationCode"/> + </th> + <td> + <s:property value="updateContactCommand.contact.boat.registrationCode"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.districtCode"/> + </th> + <td> + <s:property value="updateContactCommand.contact.boat.districtCode"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.boatLength"/> + </th> + <td> + <s:property value="%{'' + updateContactCommand.contact.boat.boatLength}"/> cm. + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.buildYear"/> + </th> + <td> + <s:property value="%{'' + updateContactCommand.contact.boat.buildYear}"/> + </td> + </tr> + </tbody> + </table> + </s:if> <h3><s:text name="wao.ui.field.Contact.sampleRow"/></h3> @@ -181,14 +184,16 @@ <s:property value="updateContactCommand.contact.sampleRow.code"/> </td> </tr> - <tr> - <th> - <s:text name="wao.ui.field.SampleRow.profession"/> - </th> - <td> - <s:property value="updateContactCommand.contact.sampleRow.professionDescription"/> - </td> - </tr> + <s:if test="updateContactCommand.contact.obsProgram.obsMer || updateContactCommand.contact.obsProgram.obsVente"> + <tr> + <th> + <s:text name="wao.ui.field.SampleRow.profession"/> + </th> + <td> + <s:property value="updateContactCommand.contact.sampleRow.professionDescription"/> + </td> + </tr> + </s:if> <tr> <th> <s:text name="wao.ui.field.SampleRow.programName"/> @@ -326,11 +331,43 @@ </s:if> - <s:textfield name="updateContactCommand.contact.dataInputDate" - label="%{getText('wao.ui.field.Contact.dataInputDate')}" - placeholder="%{getDatePlaceholder()}" - disabled="%{!#editObservationReport}" - cssClass="date"/> + <s:if test="updateContactCommand.contact.obsProgram.obsMer || updateContactCommand.contact.obsProgram.obsVente"> + + <s:textfield name="updateContactCommand.contact.dataInputDate" + label="%{getText('wao.ui.field.Contact.dataInputDate')}" + placeholder="%{getDatePlaceholder()}" + disabled="%{!#editObservationReport}" + cssClass="date"/> + + </s:if> + + <s:if test="updateContactCommand.contact.obsProgram.sclerochronology"> + + <s:textfield name="updateContactCommand.contact.sampleSize" + label="%{getText('wao.ui.field.Contact.sampleSize')}" + type="number" + disabled="%{!#editObservationReport}" + cssClass="input-small" /> + + <s:textfield name="updateContactCommand.contact.sampleSubmission" + label="%{getText('wao.ui.field.Contact.sampleSubmission')}" + placeholder="%{getDatePlaceholder()}" + disabled="%{!#editObservationReport}" + cssClass="date"/> + + <s:textfield name="updateContactCommand.contact.sampleReception" + label="%{getText('wao.ui.field.Contact.sampleReception')}" + placeholder="%{getDatePlaceholder()}" + disabled="%{!#editObservationReport}" + cssClass="date"/> + + <s:textfield name="updateContactCommand.contact.sampleTreatment" + label="%{getText('wao.ui.field.Contact.sampleTreatment')}" + placeholder="%{getDatePlaceholder()}" + disabled="%{!#editObservationReport}" + cssClass="date"/> + + </s:if> <s:if test="updateContactCommand.contact.obsProgram.obsMer"> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm