branch feature/2263 updated (5bcc4c2 -> a182c8a)
This is an automated email from the git hooks/post-receive script. New change to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git from 5bcc4c2 Dans le plan scléro, on ajoute une colonne pour l'espèce new 50588e1 On adapte la génération de la liste des modifications pour considérer les changements sur une ligne scléro new a182c8a Impact des données de test suite à changement de modèle CSV The 2 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 a182c8a6bb2769f803bc54491143330e4cb9b2a3 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Dec 19 11:48:38 2014 +0100 Impact des données de test suite à changement de modèle CSV commit 50588e180aed02fe197bbb2242e5f0e771e6afb6 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Dec 19 11:44:13 2014 +0100 On adapte la génération de la liste des modifications pour considérer les changements sur une ligne scléro Summary of changes: .../fr/ifremer/wao/entity/SampleRowLogImpl.java | 94 ++++++++++++++++++---- .../SclerochronologySamplingPlanServiceTest.java | 53 +++++++++++- .../ifremer/wao/services/service/WaoFixtures.java | 28 ++++--- .../src/test/resources/import/echantillonnage.csv | 2 +- 4 files changed, 150 insertions(+), 27 deletions(-) -- 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/2263 in repository wao. See http://git.codelutin.com/wao.git commit 50588e180aed02fe197bbb2242e5f0e771e6afb6 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Dec 19 11:44:13 2014 +0100 On adapte la génération de la liste des modifications pour considérer les changements sur une ligne scléro --- .../fr/ifremer/wao/entity/SampleRowLogImpl.java | 94 ++++++++++++++++++---- .../SclerochronologySamplingPlanServiceTest.java | 53 +++++++++++- .../ifremer/wao/services/service/WaoFixtures.java | 28 ++++--- 3 files changed, 149 insertions(+), 26 deletions(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java index 3253b65..bd39c1b 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java @@ -25,6 +25,8 @@ package fr.ifremer.wao.entity; import com.google.common.collect.Maps; +import fr.ifremer.wao.WaoUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.nuiton.topia.persistence.TopiaEntities; import org.nuiton.util.DateUtil; @@ -36,6 +38,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -48,6 +51,8 @@ import java.util.Set; */ public class SampleRowLogImpl extends SampleRowLogAbstract { + protected Locale locale = Locale.FRANCE; + // TODO brendan 29/04/14 i18n, i18n everywhere ! protected void addChange(String text) { String log = getLogText(); @@ -188,18 +193,18 @@ public class SampleRowLogImpl extends SampleRowLogAbstract { } } - protected void compareCompanies() { - Organisation oldCompany = oldRow == null ? null : oldRow.getOrganisation(); - Organisation newCompany = newRow.getOrganisation(); - if (oldCompany != null) { - String msg = "La ligne n'est plus associée à la société " + oldCompany.getName(); - if (newCompany != null && !newCompany.equals(oldCompany)) { - addChange(msg + " mais à la société " + newCompany.getName()); - } else if (newCompany == null) { + protected void compareOrganisations() { + Organisation oldOrganisation = oldRow == null ? null : oldRow.getOrganisation(); + Organisation newOrganisation = newRow.getOrganisation(); + if (oldOrganisation != null) { + String msg = "La ligne n'est plus associée à " + oldOrganisation.getFullName(); + if (newOrganisation != null && !newOrganisation.equals(oldOrganisation)) { + addChange(msg + " mais à la société " + newOrganisation.getName()); + } else if (newOrganisation == null) { addChange(msg); } - } else if (newCompany != null) { - addChange("La ligne est désormais associée à la société " + newCompany.getName()); + } else if (newOrganisation != null) { + addChange("La ligne est désormais associée à " + newOrganisation.getFullName()); } } @@ -397,6 +402,18 @@ public class SampleRowLogImpl extends SampleRowLogAbstract { } } + protected void compareSclerochronologySamplingContextInfos() { + String oldSclerochronologySamplingContextInfo = oldRow == null ? null : oldRow.getSclerochronologySamplingContextInfo(); + String newSclerochronologySamplingContextInfo = newRow.getSclerochronologySamplingContextInfo(); + if (!StringUtils.isEmpty(oldSclerochronologySamplingContextInfo)) { + if (!oldSclerochronologySamplingContextInfo.equals(newSclerochronologySamplingContextInfo)) { + addChange("Le complément d'information sur le contexte est passé de « " + oldSclerochronologySamplingContextInfo + " » à « " + newSclerochronologySamplingContextInfo + " »"); + } + } else if (!StringUtils.isEmpty(newSclerochronologySamplingContextInfo)) { + addChange("Le complément d'information sur le contexte est désormais « " + newSclerochronologySamplingContextInfo + " »"); + } + } + /** Compare a sample row before and after its modifications and generate * a differences summary and save it by setting log text. */ @@ -421,7 +438,7 @@ public class SampleRowLogImpl extends SampleRowLogAbstract { this.newRow = newRow; ObsProgram obsProgram = newRow.getObsProgram(); - if (ObsProgram.OBSMER.equals(obsProgram)) { + if (obsProgram.isObsMer()) { compareNbObservers(); compareAverageTidesTimes(); comparePrograms(); @@ -430,8 +447,7 @@ public class SampleRowLogImpl extends SampleRowLogAbstract { compareSampleMonths(); compareEligibleBoats(); compareFishingZones(); - } - if (ObsProgram.OBSVENTE.equals(obsProgram)) { + } else if (obsProgram.isObsVente()) { compareTerrestrialDistricts(); comparePrograms(); comparePeriods(); @@ -440,10 +456,60 @@ public class SampleRowLogImpl extends SampleRowLogAbstract { compareEligibleBoats(); compareFishingZones(); compareAverageObservationsCount(); + } else if (obsProgram.isSclerochronology()) { + comparePrograms(); + comparePeriods(); + compareSampleMonths(); + compareFishingZones(); + compareIndividualMeasurementStrategies(); + compareSclerochronologySamplingContexts(); + compareSclerochronologySamplingContextInfos(); + compareSpecies(); + } else { + throw new UnsupportedOperationException("not for " + obsProgram); } - compareCompanies(); + compareOrganisations(); this.oldRow = null; this.newRow = null; } + + protected void compareSclerochronologySamplingContexts() { + SclerochronologySamplingContext oldSclerochronologySamplingContext = oldRow.getSclerochronologySamplingContext(); + SclerochronologySamplingContext newSclerochronologySamplingContext = newRow.getSclerochronologySamplingContext(); + if (ObjectUtils.notEqual(oldSclerochronologySamplingContext, newSclerochronologySamplingContext)) { + String change = String.format( + "Le contexte est passé de %s à %s", + WaoUtils.l(locale, oldSclerochronologySamplingContext), + WaoUtils.l(locale, newSclerochronologySamplingContext) + ); + addChange(change); + } + } + + protected void compareIndividualMeasurementStrategies() { + IndividualMeasurementStrategy oldIndividualMeasurementStrategy = oldRow.getIndividualMeasurementStrategy(); + IndividualMeasurementStrategy newIndividualMeasurementStrategy = newRow.getIndividualMeasurementStrategy(); + if (ObjectUtils.notEqual(oldIndividualMeasurementStrategy, newIndividualMeasurementStrategy)) { + String change = String.format( + "Les caractéristiques à mesurer sont passées de %s à %s", + WaoUtils.l(locale, oldIndividualMeasurementStrategy), + WaoUtils.l(locale, newIndividualMeasurementStrategy) + ); + addChange(change); + } + } + + protected void compareSpecies() { + Species oldSpecies = oldRow.getSpecies(); + Species newSpecies = newRow.getSpecies(); + if (ObjectUtils.notEqual(oldSpecies, newSpecies)) { + String change = String.format( + "L'espèce est passée de %s à %s", + oldSpecies.getVernacularName(), + newSpecies.getVernacularName() + ); + addChange(change); + } + } } diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java index 24b9d68..a729ace 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java @@ -1,8 +1,13 @@ package fr.ifremer.wao.services.service; +import com.google.common.base.Optional; +import com.google.common.collect.Iterables; import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowLog; import fr.ifremer.wao.services.AbstractWaoServiceTest; import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.administration.UnknownBoatRegistrationCodesException; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -27,6 +32,7 @@ public class SclerochronologySamplingPlanServiceTest extends AbstractWaoServiceT @Before public void setUp() { + getApplicationContext().setDate(DateUtil.createDate(0, 30, 12, 15, 6, 2015)); service = newService(SclerochronologySamplingPlanService.class); fixtures = new SclerochronologyFixtures(newServiceContext()); } @@ -53,7 +59,6 @@ public class SclerochronologySamplingPlanServiceTest extends AbstractWaoServiceT @Test public void newSampleRowsFilterPeriodMustBeOnJanuaryToDecemberOfTheCurrentYear() { - applicationContext.setDate(DateUtil.createDate(15, 1, 2015)); fixtures.samplingPlan(); SampleRowsFilter filter = service.newSampleRowsFilter(fixtures.admin()); Assert.assertEquals(DateUtil.createDate(1, 1, 2015), filter.getPeriodFrom()); @@ -62,7 +67,6 @@ public class SclerochronologySamplingPlanServiceTest extends AbstractWaoServiceT @Test public void samplingPlan() { - applicationContext.setDate(DateUtil.createDate(15, 1, 2015)); fixtures.samplingPlan(); AuthenticatedWaoUser admin = fixtures.admin(); SampleRowsFilter filter = service.newSampleRowsFilter(admin); @@ -72,4 +76,49 @@ public class SclerochronologySamplingPlanServiceTest extends AbstractWaoServiceT Assert.assertEquals(3, samplingPlan.getFilterValues().getSclerochronologySamplingContexts().size()); Assert.assertEquals(2, samplingPlan.getFilterValues().getOrganisations().size()); } + + @Test + public void sampleRowModificationsAreLogged() { + + // dans le plan, on prend une ligne du plan + fixtures.samplingPlan(); + String sampleRowCode = "2015_S0001"; + String sampleRowId = service.getSampleRowDao().forCodeEquals(sampleRowCode).findUnique().getTopiaId(); + + // on la modifie en changeant diverses propriétés + UpdateSampleRowCommand updateSampleRowCommand = service.newUpdateSampleRowCommand(fixtures.admin(), Optional.of(sampleRowId)); + updateSampleRowCommand.getSampleRow().setSpecies( + Iterables.get(updateSampleRowCommand.getAllSpecies().values(), 2)); + updateSampleRowCommand.getSampleRow().setIndividualMeasurementStrategy( + Iterables.get(updateSampleRowCommand.getAllIndividualMeasurementStrategies().keySet(), 0)); + updateSampleRowCommand.getSampleRow().setSclerochronologySamplingContext( + Iterables.get(updateSampleRowCommand.getAllSclerochronologySamplingContexts().keySet(), 2)); + updateSampleRowCommand.getSampleRow().setSclerochronologySamplingContextInfo("note"); + updateSampleRowCommand.getSampleRowLog().setComment("test de modification"); + + try { + service.preValidate(fixtures.admin(), updateSampleRowCommand); + service.validate(fixtures.admin(), updateSampleRowCommand); + service.save(updateSampleRowCommand); + } catch (UnknownBoatRegistrationCodesException | SampleRowCodeMustBeUniqueException | SampleRowValidationException e) { + if (log.isDebugEnabled()) { + log.debug("unexpected exception", e); + } + Assert.fail("unexpected exception"); + } + + // on vérifie que les différentes modifications sont bien journalisées + SampleRow sampleRow = service.getSampleRowDao().forCodeEquals(sampleRowCode).findUnique(); + SampleRowLog sampleRowLog = Iterables.getOnlyElement(sampleRow.getSampleRowLog()); + + if (log.isDebugEnabled()) { + log.debug("log text is " + sampleRowLog.getLogText()); + } + + Assert.assertTrue(sampleRowLog.getLogText().contains("note")); + Assert.assertTrue(sampleRowLog.getLogText().contains("Échantillonnage à terre")); + Assert.assertTrue(sampleRowLog.getLogText().contains("Poids/Taille")); + Assert.assertTrue(sampleRowLog.getLogText().contains("Merlu")); + + } } \ No newline at end of file diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/WaoFixtures.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/WaoFixtures.java index 63e1885..7279bd3 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/WaoFixtures.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/WaoFixtures.java @@ -1,5 +1,6 @@ package fr.ifremer.wao.services.service; +import com.google.common.collect.Iterables; import fr.ifremer.wao.WaoTechnicalException; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.CompanyTopiaDao; @@ -9,6 +10,7 @@ import fr.ifremer.wao.entity.UserProfileImpl; import fr.ifremer.wao.entity.UserRole; import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.entity.WaoUserImpl; +import fr.ifremer.wao.entity.WaoUserTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; import fr.ifremer.wao.services.WaoServiceContext; import fr.ifremer.wao.services.service.administration.ReferentialService; @@ -42,16 +44,22 @@ public class WaoFixtures { } protected AuthenticatedWaoUser newAuthenticatedWaoUser(String login, ObsProgram obsProgram, UserRole userRole) { - WaoUser waoUser = new WaoUserImpl(); - waoUser.setOrganisation(ifremer()); - waoUser.setLogin(login); - waoUser.setActive(true); - UserProfile userProfile = new UserProfileImpl(); - userProfile.setUserRole(userRole); - userProfile.setObsProgram(obsProgram); - userProfile.setCanWrite(true); - waoUser.addUserProfile(userProfile); - return new AuthenticatedWaoUser(waoUser, userProfile); + WaoUserTopiaDao waoUserDao = serviceContext.getPersistenceContext().getWaoUserDao(); + WaoUser waoUser = waoUserDao.forLoginEquals(login).findUniqueOrNull(); + if (waoUser == null) { + waoUser = new WaoUserImpl(); + waoUser.setOrganisation(ifremer()); + waoUser.setLogin(login); + waoUser.setActive(true); + UserProfile userProfile = new UserProfileImpl(); + userProfile.setUserRole(userRole); + userProfile.setObsProgram(obsProgram); + userProfile.setCanWrite(true); + waoUser.addUserProfile(userProfile); + waoUserDao.create(waoUser); + serviceContext.getPersistenceContext().commit(); + } + return new AuthenticatedWaoUser(waoUser, Iterables.getOnlyElement(waoUser.getUserProfile())); } public Company ifremer() { -- 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/2263 in repository wao. See http://git.codelutin.com/wao.git commit a182c8a6bb2769f803bc54491143330e4cb9b2a3 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Dec 19 11:48:38 2014 +0100 Impact des données de test suite à changement de modèle CSV --- wao-services/src/test/resources/import/echantillonnage.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wao-services/src/test/resources/import/echantillonnage.csv b/wao-services/src/test/resources/import/echantillonnage.csv index 0073eab..cfddb59 100644 --- a/wao-services/src/test/resources/import/echantillonnage.csv +++ b/wao-services/src/test/resources/import/echantillonnage.csv @@ -1,4 +1,4 @@ -"PLAN_CODE";"SOCIETE_NOM";"PECHE_DIVISION";"PECHE_AUTRE";"METIER_CODE_DCF5";"METIER_MAILLAGE";"METIER_TAILLE";"METIER_AUTRE";"METIER_LIBELLE";"METIER_ESPECES";"PROGRAMME_CODE";"PROGRAMME_DEBUT";"PROGRAMME_FIN";"12/2009";"01/2010";"02/2010";"03/2010";"04/2010";"05/2010";"06/2010";"07/2010";"08/2010";"09/2010";"10/2010";"11/2010";"12/2010";"01/2011";"02/2011";"03/2011";"PLAN_DUREE_MOY";"PLAN_NB_OBSERV";"PLAN_COMMENT";"TAUX_COUVERTURE_APPLIQUE" +"PLAN_CODE";"ORGANISATION_NOM";"PECHE_DIVISION";"PECHE_AUTRE";"METIER_CODE_DCF5";"METIER_MAILLAGE";"METIER_TAILLE";"METIER_AUTRE";"METIER_LIBELLE";"METIER_ESPECES";"PROGRAMME_CODE";"PROGRAMME_DEBUT";"PROGRAMME_FIN";"12/2009";"01/2010";"02/2010";"03/2010";"04/2010";"05/2010";"06/2010";"07/2010";"08/2010";"09/2010";"10/2010";"11/2010";"12/2010";"01/2011";"02/2011";"03/2011";"PLAN_DUREE_MOY";"PLAN_NB_OBSERV";"PLAN_COMMENT";"TAUX_COUVERTURE_APPLIQUE" "2010_M0001";"IFREMER";"IId,I";;"DRB_ALG";;;;;;"MA-2009";"03/2010";"01/2011";;;;0;0;0;0;0;0;0;2;0;0;4;;;"1.5";1;"Un petit commentaire";5 "2010_M0002";"IFREMER";"IId";;"DRH_CAT,DRH_CRU";;;;"Fileyage";"poissons tubes";"MANY";"01/2008";"12/2008";;20;0;0;21;0;0;21;0;0;21;0;0;;;;1;1;;5 "2010_M0003";"IFREMER";"IId,IV";;"DRH";;;;"balottage en plein air";"divers choses visqueuses";"MA-2009";"03/2010";"01/2011";;;;0;22;0;0;25;0;0;21;0;0;25;;;2;1;;5 -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm