r1877 - trunk/wao-services/src/main/java/fr/ifremer/wao/services/service
Author: bleny Date: 2014-04-10 17:47:41 +0200 (Thu, 10 Apr 2014) New Revision: 1877 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1877 Log: refs #4483 fix multiple exceptions occuring on sample row creation Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-04-09 16:42:24 UTC (rev 1876) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-04-10 15:47:41 UTC (rev 1877) @@ -48,6 +48,7 @@ import fr.ifremer.wao.entity.FishingZoneTopiaDao; import fr.ifremer.wao.entity.LocationType; import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.Profession; import fr.ifremer.wao.entity.ProfessionImpl; import fr.ifremer.wao.entity.ProfessionTopiaDao; import fr.ifremer.wao.entity.SampleMonth; @@ -225,12 +226,20 @@ public void preValidate(AuthenticatedWaoUser authenticatedWaoUser, UpdateSampleRowCommand updateSampleRowCommand) throws UnknownBoatImmatriculationsException, UnknownFishingGearDcfCodeException, UnknownTargetSpeciesDcfCodeException, SampleRowCodeMustBeUniqueException { + SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); + + SampleRowTopiaDao dao = getSampleRowDao(); + List<SampleRow> existingSampleRowsForTheSameCode = dao.forCodeEquals(sampleRow.getCode()).findAll(); + if (existingSampleRowsForTheSameCode.size() > 1) { + throw new SampleRowCodeMustBeUniqueException(); + } else if (existingSampleRowsForTheSameCode.size() == 1 && !Iterables.getOnlyElement(existingSampleRowsForTheSameCode).equals(sampleRow)) { + throw new SampleRowCodeMustBeUniqueException(); + } + String elligibleBoatImmatriculations = updateSampleRowCommand.getElligibleBoatImmatriculations(); List<Boat> elligibleBoats = getReferentialService().getBoatsFromImmatriculations(elligibleBoatImmatriculations); - SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - for (Boat boat : elligibleBoats) { ElligibleBoat elligibleBoat = sampleRow.getElligibleBoatByBoat(boat); if (elligibleBoat == null) { @@ -245,14 +254,16 @@ } } - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - Boat boat = elligibleBoat.getBoat(); - boolean isNoLongerActive = !elligibleBoats.contains(boat); - if (isNoLongerActive) { - if (authenticatedWaoUser.isAdmin()) { - elligibleBoat.setGlobalActive(false); - } else if (authenticatedWaoUser.isCoordinator()) { - elligibleBoat.setCompanyActive(null); + if (sampleRow.isElligibleBoatNotEmpty()) { + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + Boat boat = elligibleBoat.getBoat(); + boolean isNoLongerActive = !elligibleBoats.contains(boat); + if (isNoLongerActive) { + if (authenticatedWaoUser.isAdmin()) { + elligibleBoat.setGlobalActive(false); + } else if (authenticatedWaoUser.isCoordinator()) { + elligibleBoat.setCompanyActive(null); + } } } } @@ -307,14 +318,6 @@ sampleMonthDao.delete(sampleMonth); } - SampleRowTopiaDao dao = getSampleRowDao(); - List<SampleRow> existingSampleRowsForTheSameCode = dao.forCodeEquals(sampleRow.getCode()).findAll(); - if (existingSampleRowsForTheSameCode.size() > 1) { - throw new SampleRowCodeMustBeUniqueException(); - } else if (existingSampleRowsForTheSameCode.size() == 1 && !Iterables.getOnlyElement(existingSampleRowsForTheSameCode).equals(sampleRow)) { - throw new SampleRowCodeMustBeUniqueException(); - } - } public void save(UpdateSampleRowCommand updateSampleRowCommand) { @@ -327,14 +330,24 @@ } ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - if (elligibleBoat.isPersisted()) { - elligibleBoatDao.update(elligibleBoat); - } else { - elligibleBoatDao.create(elligibleBoat); + if (sampleRow.isElligibleBoatNotEmpty()) { + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + if (elligibleBoat.isPersisted()) { + elligibleBoatDao.update(elligibleBoat); + } else { + elligibleBoatDao.create(elligibleBoat); + } } } + ProfessionTopiaDao professionDao = getProfessionDao(); + Profession profession = sampleRow.getProfession(); + if (profession.isPersisted()) { + professionDao.update(profession); + } else { + professionDao.create(profession); + } + SampleRowTopiaDao dao = getSampleRowDao(); if (sampleRow.isPersisted()) { dao.update(sampleRow);
participants (1)
-
bleny@users.forge.codelutin.com