r361 - in trunk/tutti-persistence/src: main/java/fr/ifremer/tutti/persistence/service main/resources test/java/fr/ifremer/tutti/persistence/service
Author: blavenier Date: 2013-02-07 19:51:36 +0100 (Thu, 07 Feb 2013) New Revision: 361 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/361 Log: Add - now store/get the fishingOperation.vessel (into OperationVesselAssociation in the database) Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-07 17:32:30 UTC (rev 360) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-07 18:51:36 UTC (rev 361) @@ -25,6 +25,7 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import com.google.common.collect.Sets; import fr.ifremer.adagio.core.dao.data.batch.denormalized.DenormalizedBatch; import fr.ifremer.adagio.core.dao.data.fishingArea.FishingArea; @@ -36,6 +37,9 @@ import fr.ifremer.adagio.core.dao.data.measure.VesselUseMeasurement; import fr.ifremer.adagio.core.dao.data.operation.FishingOperationDao; import fr.ifremer.adagio.core.dao.data.operation.Operation; +import fr.ifremer.adagio.core.dao.data.operation.OperationVesselAssociation; +import fr.ifremer.adagio.core.dao.data.operation.OperationVesselAssociationDao; +import fr.ifremer.adagio.core.dao.data.operation.OperationVesselAssociationPK; import fr.ifremer.adagio.core.dao.data.survey.fishingTrip.FishingTrip; import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruise; import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruiseDao; @@ -52,6 +56,7 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmImpl; import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValue; import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueImpl; +import fr.ifremer.adagio.core.dao.referential.vessel.VesselImpl; import fr.ifremer.adagio.core.service.referential.location.LocationService; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -59,6 +64,7 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; import fr.ifremer.tutti.persistence.entities.referential.Person; +import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; @@ -107,6 +113,9 @@ @Resource(name = "fishingOperationDao") protected FishingOperationDao fishingOperationDao; + @Resource(name = "operationVesselAssociationDao") + protected OperationVesselAssociationDao operationVesselAssociationDao; + @Resource(name = "locationService") protected LocationService locationService; @@ -190,6 +199,8 @@ fishingOperations.add(fishingOperation); + // TODO BLA: code utile juste pour les tests UI + //fishingOperations.add(getFishingOperation(source[0].toString())); } return fishingOperations; } @@ -325,6 +336,13 @@ localite.setId(localiteId.toString()); result.setLocation(localite); } + + // Vessel (the one with the catch batch) + String vesselCode = (String) source[colIndex++]; + if (vesselCode != null) { + Vessel vessel = referentialService.getVessel(vesselCode); + result.setVessel(vessel); + } // Retrieve environment caracteristics : getEnvironmentCaracteristics(id, result); @@ -621,7 +639,7 @@ } } else { // TODO BLA : Then parse the String when more than one number (ie "1,3") - // then and validate content + // and validate content } // Store into Gear Use Features @@ -677,6 +695,16 @@ // Vessel target.setVessel(fishingTrip.getVessel()); + + // Associated vessel + if (copyIfNull && source.getVessel() == null && target.getOperationVesselAssociations() != null) { + target.getOperationVesselAssociations().clear(); + } + else if(source.getVessel() != null + && source.getVessel().getId() != null) { + setOperationVesselAssociation(target, source.getVessel().getId()); + } + // Quality Flag : if (target.getQualityFlag() == null) { @@ -1189,4 +1217,51 @@ } return null; } + + protected void setOperationVesselAssociation(Operation target, String vesselCode) { + OperationVesselAssociation ova = null; + OperationVesselAssociationPK ovaPK = new OperationVesselAssociationPK(); + ovaPK.setVessel(load(VesselImpl.class, vesselCode)); + ovaPK.setOperation(target); + + // If vessel is equal as cruise vessel : do note store any VesselOperationAssociation entity + if (vesselCode.equals(target.getVessel().getCode())) { + removeAllOperationVesselAssociation(target); + return; + } + + // Retrieve existing association + for (Iterator<OperationVesselAssociation> iterator = target.getOperationVesselAssociations().iterator(); iterator.hasNext();) { + OperationVesselAssociation asso = iterator.next(); + if (asso.getOperationVesselAssociationPk().equals(ovaPK)) { + ova = asso; + break; + } + } + + // Create a new association + if (ova == null) { + ova = OperationVesselAssociation.Factory.newInstance(); + ova.setOperationVesselAssociationPk(ovaPK); + if (target.getOperationVesselAssociations() == null) { + target.setOperationVesselAssociations(Lists.newArrayList(ova)); + } + else { + removeAllOperationVesselAssociation(target); + target.getOperationVesselAssociations().add(ova); + } + } + + ova.setIsCatchOnOperationVessel(Boolean.FALSE); + } + + protected void removeAllOperationVesselAssociation(Operation target) { + if(target.getOperationVesselAssociations() != null) { + for (Iterator<OperationVesselAssociation> iterator = target.getOperationVesselAssociations().iterator(); iterator.hasNext();) { + OperationVesselAssociation asso = iterator.next(); + operationVesselAssociationDao.remove(asso); + } + target.getOperationVesselAssociations().clear(); + } + } } Modified: trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml =================================================================== --- trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-02-07 17:32:30 UTC (rev 360) +++ trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-02-07 18:51:36 UTC (rev 361) @@ -167,13 +167,14 @@ SELECT o.id AS id, o.name AS name, - guf.gear.label AS gearLabel, + g.label AS gearLabel, o.startDateTime AS startDateTime, (select vum.alphanumericalValue from VesselUseMeasurementImpl vum where vum.vesselUseFeatures.id = vuf.id and vum.pmfm.id=:pmfmIdStationNumber) AS stationNumber, (select gum.alphanumericalValue from GearUseMeasurementImpl gum where gum.gearUseFeatures.id = guf.id and gum.pmfm.id=:pmfmIdMultirigAggregation) AS multirigAggregation FROM FishingOperationImpl o LEFT OUTER JOIN o.gearUseFeatures guf + LEFT OUTER JOIN guf.gear g LEFT OUTER JOIN o.vesselUseFeatures vuf WHERE o.fishingTrip.scientificCruise.id=:cruiseId @@ -198,7 +199,8 @@ (select vp_end from VesselPositionImpl vp_end where vp_end.operation.id = o.id and vp_end.dateTime = o.endDateTime) AS endVesselPosition, max(case when (rl.locationLevel.id = :locationLevelIdStrata) then rl.id else null end) AS strataId, max(case when (rl.locationLevel.id = :locationLevelIdSubStrata) then rl.id else null end) AS subStrataId, - max(case when (rl.locationLevel.id = :locationLevelIdLocalite) then rl.id else null end) AS localiteId + max(case when (rl.locationLevel.id = :locationLevelIdLocalite) then rl.id else null end) AS localiteId, + max(case when (va.isCatchOnOperationVessel = false) then va.id.vessel.code else o.vessel.code end) as vesselCode FROM FishingOperationImpl o INNER JOIN o.gearUseFeatures guf @@ -206,6 +208,7 @@ LEFT OUTER JOIN guf.fishingAreas fa LEFT OUTER JOIN fa.regulationLocation fa2rl LEFT OUTER JOIN fa2rl.id.location rl + LEFT OUTER JOIN o.operationVesselAssociations va WHERE o.id=:fishingOperationId GROUP BY o.name Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-02-07 17:32:30 UTC (rev 360) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceTest.java 2013-02-07 18:51:36 UTC (rev 361) @@ -33,6 +33,8 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.FishingOperationLocation; import fr.ifremer.tutti.persistence.entities.referential.Gear; +import fr.ifremer.tutti.persistence.entities.referential.Vessel; + import org.junit.Before; import org.junit.ClassRule; import org.junit.Ignore; @@ -70,6 +72,8 @@ protected CruisePersistenceService cruiseService; protected Cruise cruise = null; + protected Gear cruiseGear = null; + protected Vessel notCruiseVessel = null; @Autowired(required = true) protected TuttiEnumerationFile enumeration; @@ -81,6 +85,28 @@ referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); programService = TuttiPersistenceServiceLocator.getProgramPersistenceService(); + // Duplicate an existing cruise, to attach new fishing operations + cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); + cruise.setId(null); + cruise.setName("Unit-test-" + System.currentTimeMillis()); + cruise.setBeginDate(new Date()); + cruise.setEndDate(null); + cruise.setMultirigNumber(2); + + // Keep only one gear in the cruise : (need for case n°4) + List<Gear> cruiseGears = cruise.getGear(); + assertNotNull(cruiseGears); + assertTrue(cruiseGears.size() > 0); + cruiseGear = cruiseGears.get(0); + assertNotNull(cruiseGear.getId()); + cruise.setGear(Lists.newArrayList(cruiseGear)); + + cruise = cruiseService.createCruise(cruise); + assertNotNull(cruise.getId()); + + // Find a vessel, different from the cruise vessel + notCruiseVessel = referentialService.getVessel(dbResource.getFixtures().fishingVesselCode()); + assertNotNull(notCruiseVessel.getId()); } @Test @@ -105,25 +131,7 @@ FishingOperation reloadedFishingOperation; FishingOperation createdFishingOperation; - // Duplicate an existing cruise, to attach new fishing operations - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); - cruise.setId(null); - cruise.setName("Unit-test-" + System.currentTimeMillis()); - cruise.setBeginDate(new Date()); - cruise.setEndDate(null); - cruise.setMultirigNumber(2); - // Keep only one gear in the cruise : (need for case n°4) - List<Gear> cruiseGears = cruise.getGear(); - assertNotNull(cruiseGears); - assertTrue(cruiseGears.size() > 0); - Gear cruiseGear = cruiseGears.get(0); - assertNotNull(cruiseGear.getId()); - cruise.setGear(Lists.newArrayList(cruiseGear)); - - cruise = cruiseService.createCruise(cruise); - assertNotNull(cruise.getId()); - - // Retrieve some environment caracteristics + // Retrieve some environment caracteristics List<Caracteristic> allEnvironmentCaracteristics = referentialService.getAllCaracteristic(); CaracteristicMap environmentCaracteristics = new CaracteristicMap(); CaracteristicMap environmentValuesOneEntry = new CaracteristicMap(); @@ -185,6 +193,7 @@ fishingOperation.setGearShootingStartDate(null); fishingOperation.setGearShootingEndDate(null); fishingOperation.setGear(null); + fishingOperation.setVessel(null); fishingOperation.setGearShootingStartLatitude(33.2541f); fishingOperation.setComment(null); @@ -224,6 +233,7 @@ fishingOperation.setFishingOperationValid(Boolean.TRUE); fishingOperation.setComment("Unit test createFishingOperation() - Part n°2 : All properties set"); fishingOperation.setGear(cruiseGear); + fishingOperation.setVessel(notCruiseVessel); fishingOperation.setEnvironmentCaracteristics(environmentCaracteristics); fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristics); @@ -244,6 +254,8 @@ reloadedFishingOperation = service.getFishingOperation(createdFishingOperation.getId()); assertNotNull(reloadedFishingOperation.getGear()); + assertNotNull(reloadedFishingOperation.getVessel()); + assertEquals(fishingOperation.getVessel().getId(), reloadedFishingOperation.getVessel().getId()); assertEquals(fishingOperation.getStationNumber(), reloadedFishingOperation.getStationNumber()); assertEquals(fishingOperation.getFishingOperationNumber(), reloadedFishingOperation.getFishingOperationNumber()); assertEquals(fishingOperation.getMultirigAggregation(), reloadedFishingOperation.getMultirigAggregation()); @@ -347,6 +359,7 @@ // - remove strata, substrata, localite // - remove some environment carateristics // - remove some gear shooting carateristics + // - change vessel (to same as cruise) // ----------------------------------------------------------------------------- fishingOperation.setId(reloadedFishingOperation.getId()); fishingOperation.setGearShootingStartLatitude(null); @@ -358,6 +371,7 @@ fishingOperation.setStrata(null); fishingOperation.setSubStrata(null); fishingOperation.setLocation(null); + fishingOperation.setVessel(cruise.getVessel(0)); fishingOperation.setEnvironmentCaracteristics(environmentValuesOneEntry); fishingOperation.setGearShootingCaracteristics(gearShootingCaracteristicsOneEntry); fishingOperation.setComment(fishingOperation.getComment() + "\n\nUnit test createFishingOperation() - Part n°5 : check if deleted sub items in DB");
participants (1)
-
blavenier@users.forge.codelutin.com