r500 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure tutti-persistence/src/main/resources tutti-persistence/src/main/resources/i18n tutti-persistence/src/main/xmi tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service tutti-persistence/
Author: tchemit Date: 2013-02-28 10:08:07 +0100 (Thu, 28 Feb 2013) New Revision: 500 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/500 Log: - remove BenthosBatch (use now speciesBatch api) (refs #1863) - remove SpeciesBatchPersistenceService, BenthosBatchPersistenceService, CatchBatchPersistenceService (refs #1863, ...) - rename some queries - refs #2025 (try with new highlighter; but still not working...) Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/InvalidBatchModelException.java Removed: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/batch/CatchBatchValidatorReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-ui-swing/src/main/filtered-resources/log4j.properties trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2013-02-28 09:08:07 UTC (rev 500) @@ -24,8 +24,8 @@ * #L% */ +import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -330,11 +330,13 @@ /** * Get the catchBatch from the fishing Operation id. * - * @param id id of the fihsing operation + * @param id id of the fihsing operation + * @param canRepair flag to try to repair the batch model in not in Tutti-awre format. * @return found catchbatch */ @Transactional(readOnly = false) - CatchBatch getCatchBatchFromFishingOperation(String id); + CatchBatch getCatchBatchFromFishingOperation(String id, + boolean canRepair) throws CatchBatchValidationException; /** * Create the given CatchBatch and return it. @@ -412,19 +414,47 @@ //-- Benthos Batch methods --// //------------------------------------------------------------------------// - List<BenthosBatch> getAllBenthosBatch(String fishingOperationId); + List<SpeciesBatch> getAllRootBenthosBatch(String fishingOperationId); - BenthosBatch getBenthosBatch(String id); - @Transactional(readOnly = false) - BenthosBatch createBenthosBatch(BenthosBatch bean); + SpeciesBatch createBenthosBatch(SpeciesBatch bean, String parentBatchId); @Transactional(readOnly = false) - BenthosBatch saveBenthosBatch(BenthosBatch bean); + SpeciesBatch saveBenthosBatch(SpeciesBatch bean); @Transactional(readOnly = false) void deleteBenthosBatch(String id); + @Transactional(readOnly = false) + void deleteBenthosSubBatch(String id); + + @Transactional(readOnly = false) + void changeBenthosBatchSpecies(String batchId, Species species); + + /** + * Get all frequencies for the given species batch. + * + * @param benthosBatchId the id of the species batch to seek. + * @return the list of frequencies for the given specues batch id + * @since 1.0 + */ + List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId); + + /** + * Save all given {@link SpeciesBatchFrequency} into the given + * {@code benthosBatchId}. If some are not existing then creates them. + * <p/> + * <strong>Note:</strong> This will as a side effect remove all previous frequency for this species batch. + * + * @param benthosBatchId id of the {@link SpeciesBatch} to use + * @param frequencies list of frequencies to create or update + * @return the persisted list of frequencies + * @since 1.0 + */ + @Transactional(readOnly = false) + List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, + List<SpeciesBatchFrequency> frequencies); + //------------------------------------------------------------------------// //-- Plancton Batch methods --// //------------------------------------------------------------------------// Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-02-28 09:08:07 UTC (rev 500) @@ -25,11 +25,9 @@ */ import com.google.common.collect.Maps; - import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.adagio.core.service.technical.CacheService; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -50,8 +48,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.Zone; import fr.ifremer.tutti.persistence.service.AccidentalBatchPersistenceService; -import fr.ifremer.tutti.persistence.service.BenthosBatchPersistenceService; -import fr.ifremer.tutti.persistence.service.CatchBatchPersistenceService; +import fr.ifremer.tutti.persistence.service.BatchPersistenceService; import fr.ifremer.tutti.persistence.service.CruisePersistenceService; import fr.ifremer.tutti.persistence.service.FishingOperationPersistenceService; import fr.ifremer.tutti.persistence.service.MacroWasteBatchPersistenceService; @@ -59,7 +56,6 @@ import fr.ifremer.tutti.persistence.service.ProgramPersistenceService; import fr.ifremer.tutti.persistence.service.ProtocolPersistenceService; import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService; -import fr.ifremer.tutti.persistence.service.SpeciesBatchPersistenceService; import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -93,15 +89,9 @@ protected FishingOperationPersistenceService fishingOperationService; @Autowired - protected CatchBatchPersistenceService catchBatchService; + protected BatchPersistenceService batchService; @Autowired - protected SpeciesBatchPersistenceService speciesBatchService; - - @Autowired - protected BenthosBatchPersistenceService benthosBatchService; - - @Autowired protected PlanktonBatchPersistenceService planktonBatchService; @Autowired @@ -135,10 +125,7 @@ programService.init(); cruiseService.init(); fishingOperationService.init(); - catchBatchService.init(); - speciesBatchService.init(); - benthosBatchService.init(); - benthosBatchService.init(); + batchService.init(); planktonBatchService.init(); macroWasteBatchService.init(); accidentalBatchService.init(); @@ -155,10 +142,7 @@ programService.close(); cruiseService.close(); fishingOperationService.close(); - catchBatchService.close(); - speciesBatchService.close(); - benthosBatchService.close(); - benthosBatchService.close(); + batchService.close(); planktonBatchService.close(); macroWasteBatchService.close(); accidentalBatchService.close(); @@ -457,24 +441,19 @@ //------------------------------------------------------------------------// @Override - public CatchBatch getCatchBatchFromFishingOperation(String id) { - try { - return catchBatchService.getCatchBatchFromFishingOperation(id, true); - } catch (CatchBatchValidationException e) { - // TODO Code lutin : throw exception and ask user : "Voulez convertir les donnees d'echantillonnage dans un format compatible tutti ?" - e.printStackTrace(); - return null; - } + public CatchBatch getCatchBatchFromFishingOperation(String id, + boolean canRepair) throws CatchBatchValidationException { + return batchService.getCatchBatchFromFishingOperation(id, canRepair); } @Override public CatchBatch createCatchBatch(CatchBatch bean) { - return catchBatchService.createCatchBatch(bean); + return batchService.createCatchBatch(bean); } @Override public CatchBatch saveCatchBatch(CatchBatch bean) { - return catchBatchService.saveCatchBatch(bean); + return batchService.saveCatchBatch(bean); } //------------------------------------------------------------------------// @@ -483,52 +462,42 @@ @Override public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) { - return speciesBatchService.getAllRootSpeciesBatch(fishingOperationId); + return batchService.getAllRootSpeciesBatch(fishingOperationId); } -// @Override -// public List<SpeciesBatch> getAllSpeciesBatch(String fishingOperationId) { -// return speciesBatchService.getAllSpeciesBatch(fishingOperationId); -// } - -// @Override -// public SpeciesBatch getSpeciesBatch(String id) { -// return speciesBatchService.getSpeciesBatch(id); -// } - @Override public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, String parentBatchId) { - return speciesBatchService.createSpeciesBatch(bean, parentBatchId); + return batchService.createSpeciesBatch(bean, parentBatchId); } @Override public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) { - return speciesBatchService.saveSpeciesBatch(bean); + return batchService.saveSpeciesBatch(bean); } @Override public void deleteSpeciesBatch(String id) { - speciesBatchService.deleteSpeciesBatch(id); + batchService.deleteSpeciesBatch(id); } @Override public void deleteSpeciesSubBatch(String id) { - speciesBatchService.deleteSpeciesSubBatch(id); + batchService.deleteSpeciesSubBatch(id); } @Override public void changeSpeciesBatchSpecies(String batchId, Species species) { - speciesBatchService.changeSpeciesBatchSpecies(batchId, species); + batchService.changeSpeciesBatchSpecies(batchId, species); } @Override public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(String speciesBatchId) { - return speciesBatchService.getAllSpeciesBatchFrequency(speciesBatchId); + return batchService.getAllSpeciesBatchFrequency(speciesBatchId); } @Override public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { - return speciesBatchService.saveSpeciesBatchFrequency(speciesBatchId, frequencies); + return batchService.saveSpeciesBatchFrequency(speciesBatchId, frequencies); } //------------------------------------------------------------------------// @@ -536,30 +505,46 @@ //------------------------------------------------------------------------// @Override - public List<BenthosBatch> getAllBenthosBatch(String fishingOperationId) { - return benthosBatchService.getAllBenthosBatch(fishingOperationId); + public List<SpeciesBatch> getAllRootBenthosBatch(String fishingOperationId) { + return batchService.getAllRootBenthosBatch(fishingOperationId); } @Override - public BenthosBatch getBenthosBatch(String id) { - return benthosBatchService.getBenthosBatch(id); + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, String parentBatchId) { + return batchService.createBenthosBatch(bean, parentBatchId); } @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean) { - return benthosBatchService.createBenthosBatch(bean); + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { + return batchService.saveBenthosBatch(bean); } @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { - return benthosBatchService.saveBenthosBatch(bean); + public void deleteBenthosBatch(String id) { + batchService.deleteBenthosBatch(id); } @Override - public void deleteBenthosBatch(String id) { - benthosBatchService.deleteBenthosBatch(id); + public void deleteBenthosSubBatch(String id) { + batchService.deleteBenthosSubBatch(id); } + @Override + public void changeBenthosBatchSpecies(String batchId, Species species) { + batchService.changeBenthosBatchSpecies(batchId, species); + } + + @Override + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) { + return batchService.getAllBenthosBatchFrequency(benthosBatchId); + } + + @Override + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, + List<SpeciesBatchFrequency> frequencies) { + return batchService.saveBenthosBatchFrequency(benthosBatchId, frequencies); + } + //------------------------------------------------------------------------// //-- Plancton Batch methods --// //------------------------------------------------------------------------// Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-02-28 09:08:07 UTC (rev 500) @@ -25,7 +25,6 @@ */ import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -307,7 +306,7 @@ } @Override - public CatchBatch getCatchBatchFromFishingOperation(String id) { + public CatchBatch getCatchBatchFromFishingOperation(String id, boolean canRepair) { throw new RuntimeException("method not implemented"); } @@ -362,31 +361,46 @@ } @Override - public List<BenthosBatch> getAllBenthosBatch(String fishingOperationId) { + public List<SpeciesBatch> getAllRootBenthosBatch(String fishingOperationId) { throw new RuntimeException("method not implemented"); } @Override - public BenthosBatch getBenthosBatch(String id) { + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, String parentBatchId) { throw new RuntimeException("method not implemented"); } @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean) { + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { throw new RuntimeException("method not implemented"); } @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { + public void deleteBenthosBatch(String id) { throw new RuntimeException("method not implemented"); } @Override - public void deleteBenthosBatch(String id) { + public void deleteBenthosSubBatch(String id) { throw new RuntimeException("method not implemented"); } @Override + public void changeBenthosBatchSpecies(String batchId, Species species) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) { + throw new RuntimeException("method not implemented"); + } + + @Override + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, List<SpeciesBatchFrequency> frequencies) { + throw new RuntimeException("method not implemented"); + } + + @Override public List<PlanktonBatch> getAllPlanktonBatch(String fishingOperationId) { throw new RuntimeException("method not implemented"); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceService.java 2013-02-28 09:08:07 UTC (rev 500) @@ -25,15 +25,210 @@ */ +import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; +import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; +import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.referential.Species; import org.springframework.transaction.annotation.Transactional; -import fr.ifremer.adagio.core.dao.data.batch.CatchBatch; -import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; +import java.util.List; @Transactional(readOnly = true) -public interface BatchPersistenceService extends CatchBatchPersistenceService, SpeciesBatchPersistenceService { +public interface + BatchPersistenceService extends TuttiPersistenceServiceImplementor { - void cleanEntity(CatchBatch catchBatch, boolean keepTotalWeight); + //------------------------------------------------------------------------// + //-- CatchBatch methods --// + //------------------------------------------------------------------------// - void setCatchBatchDao(CatchBatchExtendDao dao); + /** + * Used to initialize a catch when fixing it. + * + * @param catchBatch (original batch to fix) + * @param keepTotalWeight flag to keep weight assigned on catch batch + */ + void cleanEntity(fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, + boolean keepTotalWeight); + + /** + * Used to mock dao in unit tests. + * + * @param dao dao to use + */ + void setCatchBatchDao(CatchBatchExtendDao dao); + + /** + * Get the catchBatch from the fishing Operation id. + * + * @param fishingOperationId id of the fihsing operation + * @return found catchbatch + * @throws CatchBatchValidationException + */ + CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) throws CatchBatchValidationException; + + /** + * Get the catchBatch from the fishing Operation id. + * + * @param fishingOperationId id of the fihsing operation + * @return found catchbatch + * @throws CatchBatchValidationException + */ + @Transactional(readOnly = false) + CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId, + boolean tryToRepair) throws CatchBatchValidationException; + + /** + * Create the given CatchBatch and return it. + * + * @param bean catchBatch to create + * @return created catchBatch + */ + @Transactional(readOnly = false) + CatchBatch createCatchBatch(CatchBatch bean); + + /** + * Save the given catchBatch and return it. + * + * @param bean batch to save + * @return the saved catchBatch + */ + @Transactional(readOnly = false) + CatchBatch saveCatchBatch(CatchBatch bean); + + //------------------------------------------------------------------------// + //-- SpeciesBatch methods --// + //------------------------------------------------------------------------// + + /** + * Get all root {@link SpeciesBatch} for the given fishing operation. + * <p/> + * <strong>Note:</strong> All childs of the batch should be loaded here. + * + * @param fishingOperationId if of the fishing operation to seek + * @return the list of root {@link SpeciesBatch} + * @since 1.0 + */ + List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId); + + @Transactional(readOnly = false) + SpeciesBatch createSpeciesBatch(SpeciesBatch bean, String parentBatchId); + + @Transactional(readOnly = false) + SpeciesBatch saveSpeciesBatch(SpeciesBatch bean); + + @Transactional(readOnly = false) + void deleteSpeciesBatch(String id); + + @Transactional(readOnly = false) + void deleteSpeciesSubBatch(String id); + + /** + * Change the species in the given {@code batchId} and in all his + * sub batches. + * + * @param batchId id of the root species batch to treat + * @param species species to affect to all batches + */ + @Transactional(readOnly = false) + void changeSpeciesBatchSpecies(String batchId, Species species); + + //------------------------------------------------------------------------// + //-- SpeciesBatchFrequency methods (for species) --// + //------------------------------------------------------------------------// + + /** + * Get all frequencies for the given species batch. + * + * @param speciesBatchId the id of the species batch to seek. + * @return the list of frequencies for the given specues batch id + * @since 1.0 + */ + List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(String speciesBatchId); + + /** + * Save all given {@link SpeciesBatchFrequency} into the given + * {@code speciesBatchId}. If some are not existing then creates them. + * <p/> + * <strong>Note:</strong> This will as a side effect remove all previous frequency for this species batch. + * + * @param speciesBatchId id of the {@link SpeciesBatch} to use + * @param frequencies list of frequencies to create or update + * @return the persisted list of frequencies + * @since 1.0 + */ + @Transactional(readOnly = false) + List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, + List<SpeciesBatchFrequency> frequencies); + + + //------------------------------------------------------------------------// + //-- Benthos Batch methods --// + //------------------------------------------------------------------------// + + /** + * Get all root {@link SpeciesBatch} for the given fishing operation. + * <p/> + * <strong>Note:</strong> All childs of the batch should be loaded here. + * + * @param fishingOperationId if of the fishing operation to seek + * @return the list of root {@link SpeciesBatch} + * @since 1.0 + */ + List<SpeciesBatch> getAllRootBenthosBatch(String fishingOperationId); + + @Transactional(readOnly = false) + SpeciesBatch createBenthosBatch(SpeciesBatch bean, String parentBatchId); + + @Transactional(readOnly = false) + SpeciesBatch saveBenthosBatch(SpeciesBatch bean); + + @Transactional(readOnly = false) + void deleteBenthosBatch(String id); + + @Transactional(readOnly = false) + void deleteBenthosSubBatch(String id); + + /** + * Change the species in the given {@code batchId} and in all his + * sub batches. + * + * @param batchId id of the root Benthos batch to treat + * @param species species to affect to all batches + */ + @Transactional(readOnly = false) + void changeBenthosBatchSpecies(String batchId, Species species); + + //------------------------------------------------------------------------// + //-- SpeciesBatchFrequency methods (for benthos) --// + //------------------------------------------------------------------------// + + /** + * Get all frequencies for the given species batch. + * + * @param benthosBatchId the id of the species batch to seek. + * @return the list of frequencies for the given benthos batch id + * @since 1.0 + */ + List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId); + + /** + * Save all given {@link SpeciesBatchFrequency} into the given + * {@code benthosBatchId}. If some are not existing then creates them. + * <p/> + * <strong>Note:</strong> This will as a side effect remove all previous + * frequency for this benthos batch. + * + * @param benthosBatchId id of the {@link SpeciesBatch} to use + * @param frequencies list of frequencies to create or update + * @return the persisted list of frequencies + * @since 1.0 + */ + @Transactional(readOnly = false) + List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, + List<SpeciesBatchFrequency> frequencies); + + } \ No newline at end of file Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-02-28 09:08:07 UTC (rev 500) @@ -25,35 +25,12 @@ */ -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.FlushMode; -import org.hibernate.type.IntegerType; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.stereotype.Service; - import com.google.common.base.Preconditions; import com.google.common.collect.Lists; - import fr.ifremer.adagio.core.dao.data.batch.Batch; import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; import fr.ifremer.adagio.core.dao.data.batch.SortingBatchDao; -import fr.ifremer.adagio.core.dao.data.batch.denormalized.DenormalizedBatchDao; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidator; import fr.ifremer.adagio.core.dao.data.measure.Measurement; @@ -75,10 +52,28 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.Species; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.FlushMode; +import org.hibernate.type.IntegerType; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + @Service("batchPersistenceService") public class BatchPersistenceServiceImpl - extends AbstractPersistenceService implements BatchPersistenceService { + extends AbstractPersistenceService implements BatchPersistenceService { /** Logger. */ private static final Log log = @@ -87,9 +82,6 @@ @Resource(name = "referentialPersistenceService") protected ReferentialPersistenceService referentialService; - @Resource(name = "denormalizedBatchDao") - protected DenormalizedBatchDao denormalizedBatchDao; - @Resource(name = "sortingBatchDao") protected SortingBatchDao sortingBatchDao; @@ -98,7 +90,7 @@ @Resource(name = "scientificCruiseCatchBatchValidator") protected CatchBatchValidator catchBatchValidator; - + @Override public void init() { super.init(); @@ -111,9 +103,13 @@ super.close(); } + //------------------------------------------------------------------------// + //-- CatchBatch methods --// + //------------------------------------------------------------------------// + @Override public CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) throws CatchBatchValidationException { - return getCatchBatchFromFishingOperation(fishingOperationId, false); + return getCatchBatchFromFishingOperation(fishingOperationId, false); } @Override @@ -147,76 +143,95 @@ SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); if (inertBatch != null) { - result.setSpeciesTotalInertWeight(inertBatch.getWeight()); + result.setSpeciesTotalInertWeight(inertBatch.getWeight()); } // Alive no itemized SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); if (livingNotItemizedBatch != null) { - result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); + result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); } } - // TODO : Benthos, Plancton... + // Benthos + SortingBatch benthosBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + + result.setBenthosTotalSampleSortedWeight(benthosBatch.getWeight()); + result.setBenthosTotalSortedWeight(benthosBatch.getWeightBeforeSampling()); + + // TODO : Plancton... } // Hors Vrac SortingBatch horsVracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID); if (horsVracBatch != null) { - result.setCatchTotalUnsortedWeight(horsVracBatch.getWeight()); - { - // Species - SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - - result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight()); - - // TODO : Benthos, Plancton... - } + result.setCatchTotalUnsortedWeight(horsVracBatch.getWeight()); + { + // Species + SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + + result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight()); + + SortingBatch benthosBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + + result.setBenthosTotalUnsortedWeight(benthosBatch.getWeight()); + + + // TODO : Plancton... + } } // Non trié SortingBatch unsortedBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID); if (unsortedBatch != null) { - result.setCatchTotalRejectedWeight(unsortedBatch.getWeight()); + result.setCatchTotalRejectedWeight(unsortedBatch.getWeight()); } return result; } - + @Override - public void cleanEntity(fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, - boolean keepTotalWeight) { - - // TODO BL : voir si nécessaire : - for (Iterator<Batch> iterator = catchBatch.getChildBatchs().iterator(); iterator.hasNext();) { - Batch batch = (Batch) iterator.next(); - catchBatchDao.removeWithChildren(batch.getId()); - } - catchBatch.getChildBatchs().clear(); - - // Create a new tutti bean CatchBatch, need for method beanToEntity() + public void cleanEntity(fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, + boolean keepTotalWeight) { + + Preconditions.checkNotNull(catchBatch); + Preconditions.checkNotNull(catchBatch.getChildBatchs()); + + for (Batch batch : catchBatch.getChildBatchs()) { + catchBatchDao.removeWithChildren(batch.getId()); + } + catchBatch.getChildBatchs().clear(); + + // Create a new tutti bean CatchBatch, need for method beanToEntity() fr.ifremer.tutti.persistence.entities.data.CatchBatch bean = new fr.ifremer.tutti.persistence.entities.data.CatchBatch(); - bean.setId(catchBatch.getId().toString()); - - // Link the bean to a fake fishingOperation, need in the preconditions for method beanToEntity() - FishingOperation fishingOperation = new FishingOperation(); - fishingOperation.setId(catchBatch.getFishingOperation().getId().toString()); - bean.setFishingOperation(fishingOperation); + bean.setId(catchBatch.getId().toString()); - // If need, copy the total weight, to be sure beanToEntity() will restore it - if (keepTotalWeight) { - bean.setCatchTotalWeight(catchBatch.getWeight()); - } - + // Link the bean to a fake fishingOperation, need in the preconditions for method beanToEntity() + FishingOperation fishingOperation = new FishingOperation(); + fishingOperation.setId(catchBatch.getFishingOperation().getId().toString()); + bean.setFishingOperation(fishingOperation); + + // If need, copy the total weight, to be sure beanToEntity() will restore it + if (keepTotalWeight) { + bean.setCatchTotalWeight(catchBatch.getWeight()); + } + beanToEntity(bean, catchBatch, true); } - - + @Override + public void setCatchBatchDao(CatchBatchExtendDao catchBatchDao) { + this.catchBatchDao = catchBatchDao; + } + + + @Override public CatchBatch createCatchBatch(CatchBatch bean) { Preconditions.checkNotNull(bean); Preconditions.checkArgument(bean.getId() == null); @@ -240,7 +255,7 @@ return bean; } - + @Override @CacheEvict(value = "batchTree", key = "#bean.fishingOperation.id") public CatchBatch saveCatchBatch(CatchBatch bean) { @@ -262,6 +277,10 @@ return bean; } + //------------------------------------------------------------------------// + //-- SpeciesBatch methods --// + //------------------------------------------------------------------------// + @Override public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) { @@ -275,13 +294,13 @@ SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - for (Iterator<Batch> iterator = vracSpeciesBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { - SortingBatch source = (SortingBatch) iterator.next(); + for (Batch batch1 : vracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch1; // evict some special batches : Life (or Biota) and Inert if (source.getReferenceTaxon() != null - && enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId()) == false - && enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId()) == false) { + && !enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId()) + && !enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId())) { SpeciesBatch target = new SpeciesBatch(); entityToBean(source, target); @@ -294,77 +313,16 @@ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (horsVracSpeciesBatch != null) { - for (Iterator<Batch> iterator = horsVracSpeciesBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { - SortingBatch source = (SortingBatch) iterator.next(); - - SpeciesBatch target = new SpeciesBatch(); - - entityToBean(source, target); - result.add(target); - } - } + for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; - return result; - } + SpeciesBatch target = new SpeciesBatch(); - protected SpeciesBatch entityToBean(SortingBatch source, SpeciesBatch target) { - - target.setId(source.getId().toString()); - - // Individual count - target.setNumber(source.getIndividualCount()); - - // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight - if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { - target.setSampleCategoryWeight(source.getWeight()); - } else { - target.setWeight(source.getWeight()); - target.setSampleCategoryWeight(source.getWeightBeforeSampling()); - } - - // Comments - target.setComment(source.getComments()); - - // Sample category type (only one is applied) - SortingMeasurement sm = null; - if (source.getSortingMeasurements().size() == 1) { - sm = source.getSortingMeasurements().iterator().next(); - } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { - sm = catchBatchDao.getInheritedSortingMeasurement(source, enumeration.PMFM_ID_SORTED_UNSORTED); - } - if (sm != null) { - SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(sm.getPmfm().getId()); - if (sampleCategory != null) { - setSampleCategoryQualitative(target, sm.getPmfm().getId(), sm.getNumericalValue(), sm.getAlphanumericalValue(), sm.getQualitativeValue().getId()); + entityToBean(source, target); + result.add(target); } } - - // Species - Integer referenceTaxonId = source.getInheritedReferenceTaxonId(); - if (referenceTaxonId == null && source.getReferenceTaxon() != null) { - referenceTaxonId = source.getReferenceTaxon().getId(); - } - if (referenceTaxonId != null) { - // TODO : add cache on getSpeciesByReferenceTaxonId - Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId); - target.setSpecies(species); - } - - if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) { - List<SpeciesBatch> targetChilds = Lists.newArrayList(); - for (Iterator<Batch> iterator = source.getChildBatchs().iterator(); iterator.hasNext(); ) { - SortingBatch sourceChild = (SortingBatch) iterator.next(); - SpeciesBatch targetChild = new SpeciesBatch(); - entityToBean(sourceChild, targetChild); - if (targetChild.getSampleCategoryValue() != null) { - targetChilds.add(targetChild); - targetChild.setParentBatch(target); - } - } - target.setChildBatchs(targetChilds); - } - - return target; + return result; } @Override @@ -428,10 +386,12 @@ getCurrentSession().flush(); } + @Override public void deleteSpeciesSubBatch(String id) { deleteSpeciesBatch(id); } + @Override public void changeSpeciesBatchSpecies(String batchId, Species species) { Preconditions.checkNotNull(batchId); Preconditions.checkNotNull(species); @@ -447,6 +407,11 @@ Preconditions.checkArgument(rowUpdated == 1, "Unable to update operation, to be linked with catch batch."); } + //------------------------------------------------------------------------// + //-- SpeciesBatchFrequency methods --// + //------------------------------------------------------------------------// + + @Override public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency( String speciesBatchId) { List<SpeciesBatchFrequency> results = Lists.newArrayList(); @@ -460,8 +425,8 @@ SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(speciesBatchId)); - for (Iterator<Batch> iterator = sortingBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { - SortingBatch source = (SortingBatch) iterator.next(); + for (Batch batch : sortingBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; SpeciesBatchFrequency target = new SpeciesBatchFrequency(); entityToBean(source, target); @@ -470,35 +435,24 @@ return results; } - protected void entityToBean(SortingBatch source, SpeciesBatchFrequency target) { + @Override + public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency( + String speciesBatchId, + List<SpeciesBatchFrequency> frequencies) { + Preconditions.checkNotNull(speciesBatchId); + Preconditions.checkNotNull(frequencies); - target.setId(source.getId().toString()); + // Check that all frequencies have the same length PMFM (before doing any db call) + String pmfmId = null; + for (SpeciesBatchFrequency source : frequencies) { - target.setNumber(source.getIndividualCount()); - target.setWeight(source.getWeight()); - target.setComment(source.getComments()); - - // Length step category - if (source.getSortingMeasurements().size() == 1) { - SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); - if (sm.getPmfm() != null && sm.getPmfm().getId() != null) { - Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(sm.getPmfm().getId()); - target.setLengthStepCaracteristic(lengthStepCaracteristic); + if (pmfmId == null) { + pmfmId = source.getLengthStepCaracteristic().getId(); + } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { + throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); } - - // Length - target.setLengthStep(sm.getNumericalValue()); } - } - public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency( - String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { - Preconditions.checkNotNull(speciesBatchId); - Preconditions.checkNotNull(frequencies); - - if (frequencies.size() == 0) { - return frequencies; - } getCurrentSession().setFlushMode(FlushMode.COMMIT); Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(speciesBatchId)); @@ -513,26 +467,259 @@ // Remember child ids, to remove unchanged item (see at bottom in this method) List<Integer> notUpdatedChildIds = Lists.newArrayList(); - for (Iterator<Batch> iterator = parentBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { - SortingBatch sortingBatch = (SortingBatch) iterator.next(); + for (Batch batch : parentBatch.getChildBatchs()) { + SortingBatch sortingBatch = (SortingBatch) batch; notUpdatedChildIds.add(sortingBatch.getId()); } short rankOrder = 0; - String pmfmId = null; List<SortingBatch> batchsToUpdate = Lists.newArrayList(); for (SpeciesBatchFrequency source : frequencies) { rankOrder++; - // Check that all frequencies have the same length PMFM + // Not existing batch + SortingBatch target; + if (source.getId() == null) { + target = SortingBatch.Factory.newInstance(); + + // Fill the sorting batch from the source + beanToEntity(source, target, parentBatch, rankOrder, true); + + // Create the targeted batch, then update the source id + sortingBatchDao.create(target); + source.setId(target.getId().toString()); + } + + // Existing batch + else { + target = sortingBatchDao.load(Integer.valueOf(source.getId())); + + // Fill the sorting batch from the source + beanToEntity(source, target, parentBatch, rankOrder, true); + + // Add the batch into a list (will be update later, using this list) + batchsToUpdate.add(target); + + notUpdatedChildIds.remove(target.getId()); + } + } + + // If some batchs need to be update, do it + if (batchsToUpdate.size() > 0) { + sortingBatchDao.update(batchsToUpdate); + } + + if (notUpdatedChildIds.size() > 0) { + for (Integer batchId : notUpdatedChildIds) { + catchBatchDao.removeWithChildren(batchId); + } + } + + getCurrentSession().flush(); + + return frequencies; + } + + //------------------------------------------------------------------------// + //-- Benthos Batch methods --// + //------------------------------------------------------------------------// + + @Override + public List<SpeciesBatch> getAllRootBenthosBatch(String fishingOperationId) { + // Load batch tree + Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId)); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + + List<SpeciesBatch> result = new ArrayList<SpeciesBatch>(); + + // Vrac / Benthos + SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + for (Batch batch1 : vracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch1; + + // evict some special batches : Life (or Biota) and Inert + if (source.getReferenceTaxon() != null + && !enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId()) + && !enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId())) { + SpeciesBatch target = new SpeciesBatch(); + + entityToBean(source, target); + result.add(target); + } + } + + // Hors-Vrac / Benthos + SortingBatch horsVracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + if (horsVracSpeciesBatch != null) { + for (Batch batch : horsVracSpeciesBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + + SpeciesBatch target = new SpeciesBatch(); + + entityToBean(source, target); + result.add(target); + } + } + return result; + } + + @Override + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, + String parentBatchId) { + Preconditions.checkNotNull(bean); + Preconditions.checkArgument(bean.getId() == null); + Preconditions.checkNotNull(bean.getSpecies()); + Preconditions.checkNotNull(bean.getSpecies().getId()); + Preconditions.checkNotNull(bean.getFishingOperation()); + Preconditions.checkNotNull(bean.getFishingOperation().getId()); + + getCurrentSession().setFlushMode(FlushMode.COMMIT); + + // Load full batch tree + Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(bean.getFishingOperation().getId())); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + + SortingBatch batch = SortingBatch.Factory.newInstance(); + beanToEntity(bean, batch, parentBatchId, catchBatch, true); + batch = sortingBatchDao.create(batch); + + bean.setId(String.valueOf(batch.getId())); + + getCurrentSession().flush(); + + return bean; + } + + @Override + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { + Preconditions.checkNotNull(bean); + Preconditions.checkNotNull(bean.getId()); + + // Load full batch tree + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(bean.getId())); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + + getCurrentSession().setFlushMode(FlushMode.COMMIT); + + SortingBatch batch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(bean.getId())); + String parentBatchId = null; + if (bean.getParentBatch() != null) { + parentBatchId = bean.getParentBatch().getId(); + } + beanToEntity(bean, batch, parentBatchId, catchBatch, true); + sortingBatchDao.update(batch); + getCurrentSession().flush(); + + return bean; + } + + @Override + public void deleteBenthosBatch(String id) { + Preconditions.checkNotNull(id); + + getCurrentSession().setFlushMode(FlushMode.COMMIT); + + catchBatchDao.removeWithChildren(Integer.valueOf(id)); + + getCurrentSession().flush(); + } + + @Override + public void deleteBenthosSubBatch(String id) { + deleteBenthosBatch(id); + } + + @Override + public void changeBenthosBatchSpecies(String batchId, Species species) { + + Preconditions.checkNotNull(batchId); + Preconditions.checkNotNull(species); + Preconditions.checkNotNull(species.getReferenceTaxonId()); + + if (log.isDebugEnabled()) { + log.debug("Changing species for batch id=" + batchId); + } + + int rowUpdated = queryUpdate("updateBatchSpecies", + "batchId", IntegerType.INSTANCE, Integer.valueOf(batchId), + "referenceTaxonId", IntegerType.INSTANCE, species.getReferenceTaxonId()); + Preconditions.checkArgument(rowUpdated == 1, "Unable to update operation, to be linked with catch batch."); + } + + //------------------------------------------------------------------------// + //-- SpeciesBatchFrequency methods (for benthos) --// + //------------------------------------------------------------------------// + + @Override + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) { + List<SpeciesBatchFrequency> results = Lists.newArrayList(); + + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(benthosBatchId)); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + + if (catchBatchId == null) { + return results; + } + + SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(benthosBatchId)); + + for (Batch batch : sortingBatch.getChildBatchs()) { + SortingBatch source = (SortingBatch) batch; + SpeciesBatchFrequency target = new SpeciesBatchFrequency(); + + entityToBean(source, target); + results.add(target); + } + return results; + } + + @Override + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, + List<SpeciesBatchFrequency> frequencies) { + Preconditions.checkNotNull(benthosBatchId); + Preconditions.checkNotNull(frequencies); + + // Check that all frequencies have the same length PMFM (before doing any db call) + String pmfmId = null; + for (SpeciesBatchFrequency source : frequencies) { + if (pmfmId == null) { - source.getLengthStepCaracteristic().getId(); + pmfmId = source.getLengthStepCaracteristic().getId(); } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); } + } + getCurrentSession().setFlushMode(FlushMode.COMMIT); + + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(benthosBatchId)); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + + if (catchBatch == null) { + return frequencies; + } + + // Retrieve parent + SortingBatch parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(benthosBatchId)); + + // Remember child ids, to remove unchanged item (see at bottom in this method) + List<Integer> notUpdatedChildIds = Lists.newArrayList(); + for (Batch batch : parentBatch.getChildBatchs()) { + SortingBatch sortingBatch = (SortingBatch) batch; + notUpdatedChildIds.add(sortingBatch.getId()); + } + + short rankOrder = 0; + List<SortingBatch> batchsToUpdate = Lists.newArrayList(); + for (SpeciesBatchFrequency source : frequencies) { + rankOrder++; + // Not existing batch - SortingBatch target = null; + SortingBatch target; if (source.getId() == null) { target = SortingBatch.Factory.newInstance(); @@ -564,8 +751,7 @@ } if (notUpdatedChildIds.size() > 0) { - for (Iterator<Integer> iterator = notUpdatedChildIds.iterator(); iterator.hasNext(); ) { - Integer batchId = iterator.next(); + for (Integer batchId : notUpdatedChildIds) { catchBatchDao.removeWithChildren(batchId); } } @@ -575,10 +761,94 @@ return frequencies; } - // ------------------------------------------------------------------------// - // -- Internal methods --// - // ------------------------------------------------------------------------// + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected SpeciesBatch entityToBean(SortingBatch source, + SpeciesBatch target) { + + target.setId(source.getId().toString()); + + // Individual count + target.setNumber(source.getIndividualCount()); + + // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight + if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { + target.setSampleCategoryWeight(source.getWeight()); + } else { + target.setWeight(source.getWeight()); + target.setSampleCategoryWeight(source.getWeightBeforeSampling()); + } + + // Comments + target.setComment(source.getComments()); + + // Sample category type (only one is applied) + SortingMeasurement sm = null; + if (source.getSortingMeasurements().size() == 1) { + sm = source.getSortingMeasurements().iterator().next(); + } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { + sm = catchBatchDao.getInheritedSortingMeasurement(source, enumeration.PMFM_ID_SORTED_UNSORTED); + } + if (sm != null) { + SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(sm.getPmfm().getId()); + if (sampleCategory != null) { + setSampleCategoryQualitative(target, sm.getPmfm().getId(), sm.getNumericalValue(), sm.getAlphanumericalValue(), sm.getQualitativeValue().getId()); + } + } + + // Species + Integer referenceTaxonId = source.getInheritedReferenceTaxonId(); + if (referenceTaxonId == null && source.getReferenceTaxon() != null) { + referenceTaxonId = source.getReferenceTaxon().getId(); + } + if (referenceTaxonId != null) { + // TODO : add cache on getSpeciesByReferenceTaxonId + Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId); + target.setSpecies(species); + } + + if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) { + List<SpeciesBatch> targetChilds = Lists.newArrayList(); + for (Batch batch : source.getChildBatchs()) { + SortingBatch sourceChild = (SortingBatch) batch; + SpeciesBatch targetChild = new SpeciesBatch(); + entityToBean(sourceChild, targetChild); + if (targetChild.getSampleCategoryValue() != null) { + targetChilds.add(targetChild); + targetChild.setParentBatch(target); + } + } + target.setChildBatchs(targetChilds); + } + + return target; + } + + protected void entityToBean(SortingBatch source, + SpeciesBatchFrequency target) { + + target.setId(source.getId().toString()); + + target.setNumber(source.getIndividualCount()); + target.setWeight(source.getWeight()); + target.setComment(source.getComments()); + + // Length step category + if (source.getSortingMeasurements().size() == 1) { + SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); + if (sm.getPmfm() != null && sm.getPmfm().getId() != null) { + Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(sm.getPmfm().getId()); + target.setLengthStepCaracteristic(lengthStepCaracteristic); + } + + // Length + target.setLengthStep(sm.getNumericalValue()); + } + } + protected void beanToEntity(SpeciesBatch source, SortingBatch target, String parentBatchId, @@ -612,10 +882,8 @@ // Start rank order at 3, because of special batches 'Biota' and 'Inert' short rankOrder = (short) 3; if (source.getParentBatch() != null && source.getParentBatch().getChildBatchs() != null) { - // TODO BL : vérifier cela (est-ce que l'item est ajouté à son père AVANT d'être passé au service ?) rankOrder += (short) source.getParentBatch().getChildBatchs().size(); - } - else if (target.getParentBatch() != null && target.getParentBatch().getChildBatchs() != null){ + } else if (target.getParentBatch() != null && target.getParentBatch().getChildBatchs() != null) { rankOrder += (short) target.getParentBatch().getChildBatchs().size(); } target.setRankOrder(rankOrder); @@ -629,11 +897,11 @@ // Nothing to do : will be removed later, using notChangedSortingMeasurements } else if (source.getSampleCategoryWeight() != null && source.getWeight() == null) { QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true); + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true); notChangedQuantificationMeasurements.remove(quantificationMeasurement); } else if (source.getWeight() != null && source.getSampleCategoryWeight() == null) { QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); notChangedQuantificationMeasurements.remove(quantificationMeasurement); } @@ -647,7 +915,7 @@ target.setSamplingRatioText(samplingRatioText); target.setSamplingRatio(source.getWeight() / source.getSampleCategoryWeight()); QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); notChangedQuantificationMeasurements.remove(quantificationMeasurement); } @@ -659,7 +927,7 @@ // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch) if (!pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId, - source.getSampleCategoryType(), source.getSampleCategoryValue()); + source.getSampleCategoryType(), source.getSampleCategoryValue()); notChangedSortingMeasurements.remove(sortingMeasurement); } } @@ -709,15 +977,15 @@ } } - public void setBatchParents(SpeciesBatch source, SortingBatch target, String parentBatchIdStr, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { + protected void setBatchParents(SpeciesBatch source, SortingBatch target, String parentBatchIdStr, + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { Preconditions.checkNotNull(target); Preconditions.checkNotNull(source.getFishingOperation()); Preconditions.checkNotNull(source.getFishingOperation().getId()); // Load existing parent and root - SortingBatch parentBatch = null; + SortingBatch parentBatch; if (parentBatchIdStr != null) { parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); } @@ -753,7 +1021,7 @@ target.setRootBatch(catchBatch); } - Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { + protected Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { if (value == null) return null; Integer qualitativeValueId = null; @@ -834,7 +1102,7 @@ // Nothing to do : will be removed later, using notChangedSortingMeasurements } else if (source.getWeight() != null) { QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); notChangedQuantificationMeasurements.remove(quantificationMeasurement); } @@ -844,7 +1112,7 @@ } else if (source.getLengthStepCaracteristic() != null && source.getLengthStep() != null) { Integer pmfmId = Integer.valueOf(source.getLengthStepCaracteristic().getId()); SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId, pmfmId, - source.getLengthStep()); + source.getLengthStep()); notChangedSortingMeasurements.remove(sortingMeasurement); } @@ -939,7 +1207,7 @@ // Nothing to do : will be removed later, using notChangedQuantificationMeasurements } else if (source.getCatchTotalWeight() != null) { QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getCatchTotalWeight(), true); + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getCatchTotalWeight(), true); notChangedQuantificationMeasurements.remove(quantificationMeasurement); } @@ -1181,7 +1449,7 @@ batchReferenceWeight = sampleWeight; } QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); notChangedQuantificationMeasurements.remove(quantificationMeasurement); } @@ -1248,7 +1516,7 @@ batchReferenceWeight = sampleWeight; } QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); notChangedQuantificationMeasurements.remove(quantificationMeasurement); } @@ -1269,14 +1537,14 @@ // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?) return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT; } - - public void setMeasurement(Measurement measurement, Caracteristic caracteristic, Serializable value) { + + protected void setMeasurement(Measurement measurement, Caracteristic caracteristic, Serializable value) { if (caracteristic.getCaracteristicType() == CaracteristicType.TEXT) { measurement.setAlphanumericalValue((String) value); } else if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) { measurement.setNumericalValue((Float) value); } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE) { - Integer qvId = null; + Integer qvId; if (value instanceof CaracteristicQualitativeValue) { qvId = Integer.valueOf(((CaracteristicQualitativeValue) value).getId()); } else if (value instanceof Integer) { @@ -1291,7 +1559,7 @@ } } - public SortingMeasurement setSortingMeasurement( + protected SortingMeasurement setSortingMeasurement( SortingBatch sortingBatch, Integer recorderDepartmentId, SampleCategoryEnum sampleCategory, Serializable value) { Preconditions.checkNotNull(sampleCategory); @@ -1306,7 +1574,7 @@ return sortingMeasurement; } - public SortingMeasurement setSortingMeasurement( + protected SortingMeasurement setSortingMeasurement( SortingBatch sortingBatch, Integer recorderDepartmentId, Integer pmfmId, Serializable value) { Preconditions.checkNotNull(pmfmId); @@ -1319,7 +1587,7 @@ return sortingMeasurement; } - public Integer sampleCategory2PmfmId(SampleCategoryEnum sampleCategory) { + protected Integer sampleCategory2PmfmId(SampleCategoryEnum sampleCategory) { Integer pmfmId = null; if (sampleCategory == SampleCategoryEnum.sortedUnsorted) { pmfmId = enumeration.PMFM_ID_SORTED_UNSORTED; @@ -1338,11 +1606,4 @@ return pmfmId; } - /** - * Need for JMock injection, in unit test - * @param catchBatchDao - */ - public void setCatchBatchDao(CatchBatchExtendDao catchBatchDao) { - this.catchBatchDao = catchBatchDao; - } } \ No newline at end of file Deleted: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceService.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,54 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -/** - * CRUD of {@link BenthosBatch} entity. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Transactional(readOnly = true) -public interface BenthosBatchPersistenceService extends TuttiPersistenceServiceImplementor { - - List<BenthosBatch> getAllBenthosBatch(String fishingOperationId); - - BenthosBatch getBenthosBatch(String id); - - @Transactional(readOnly = false) - BenthosBatch createBenthosBatch(BenthosBatch bean); - - @Transactional(readOnly = false) - BenthosBatch saveBenthosBatch(BenthosBatch bean); - - @Transactional(readOnly = false) - void deleteBenthosBatch(String id); -} Deleted: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,72 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Service("benthosBatchPersistenceService") -public class BenthosBatchPersistenceServiceImpl extends AbstractPersistenceService implements BenthosBatchPersistenceService { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(BenthosBatchPersistenceServiceImpl.class); - - @Override - public List<BenthosBatch> getAllBenthosBatch(String fishingOperationId) { - List<BenthosBatch> result = Lists.newArrayList(); - - // TODO - return result; - } - - @Override - public BenthosBatch getBenthosBatch(String id) { - return null; - } - - @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean) { - return null; - } - - @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { - return null; - } - - @Override - public void deleteBenthosBatch(String id) { - } -} Deleted: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceService.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,77 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; -import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import org.springframework.transaction.annotation.Transactional; - -/** - * CRUD of {@link CatchBatch} entity. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0 - */ -@Transactional(readOnly = true) -public interface CatchBatchPersistenceService extends TuttiPersistenceServiceImplementor { - - /** - * Get the catchBatch from the fishing Operation id. - * - * @param id id of the fihsing operation - * @return found catchbatch - * @throws CatchBatchValidationException - */ - CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) throws CatchBatchValidationException; - - /** - * Get the catchBatch from the fishing Operation id. - * - * @param id id of the fihsing operation - * @return found catchbatch - * @throws CatchBatchValidationException - */ - @Transactional(readOnly = false) - CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId, boolean tryToRepair) throws CatchBatchValidationException; - - /** - * Create the given CatchBatch and return it. - * - * @param bean catchBatch to create - * @return created catchBatch - */ - @Transactional(readOnly = false) - CatchBatch createCatchBatch(CatchBatch bean); - - /** - * Save the given catchBatch and return it. - * - * @param bean batch to save - * @return the saved catchBatch - */ - @Transactional(readOnly = false) - CatchBatch saveCatchBatch(CatchBatch bean); -} Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CruisePersistenceServiceImpl.java 2013-02-28 09:08:07 UTC (rev 500) @@ -24,32 +24,13 @@ * #L% */ -import java.sql.Timestamp; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import javax.annotation.Resource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.type.IntegerType; -import org.hibernate.type.StringType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.stereotype.Service; - import com.google.common.base.Preconditions; import com.google.common.collect.Lists; - +import com.google.common.collect.Sets; import fr.ifremer.adagio.core.dao.administration.programStrategy.ProgramDao; import fr.ifremer.adagio.core.dao.administration.user.PersonDao; +import fr.ifremer.adagio.core.dao.administration.user.PersonImpl; +import fr.ifremer.adagio.core.dao.data.measure.SurveyMeasurement; import fr.ifremer.adagio.core.dao.data.survey.fishingTrip.FishingTrip; import fr.ifremer.adagio.core.dao.data.survey.fishingTrip.ObservedFishingTrip; import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruise; @@ -58,11 +39,15 @@ import fr.ifremer.adagio.core.dao.data.vessel.feature.physical.GearPhysicalFeaturesExtendDao; import fr.ifremer.adagio.core.dao.referential.QualityFlag; import fr.ifremer.adagio.core.dao.referential.QualityFlagDao; +import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl; import fr.ifremer.adagio.core.dao.referential.gear.GearDao; import fr.ifremer.adagio.core.dao.referential.location.Location; import fr.ifremer.adagio.core.dao.referential.location.LocationDao; +import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm; import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmDao; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmImpl; import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueDao; +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueImpl; import fr.ifremer.adagio.core.dao.referential.vessel.VesselDao; import fr.ifremer.adagio.core.dao.technical.synchronization.SynchronizationStatus; import fr.ifremer.tutti.persistence.entities.data.Cruise; @@ -71,7 +56,26 @@ import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Vessel; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.type.IntegerType; +import org.hibernate.type.StringType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.sql.Timestamp; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + /** * @author tchemit <chemit@codelutin.com> * @since 0.3 @@ -150,7 +154,8 @@ Object[] source = queryUnique( "cruise", "cruiseId", IntegerType.INSTANCE, Integer.valueOf(id), - "countryLocationLevelId", IntegerType.INSTANCE, enumeration.LOCATION_LEVEL_ID_COUNTRY); + "countryLocationLevelId", IntegerType.INSTANCE, enumeration.LOCATION_LEVEL_ID_COUNTRY, + "pmfmIdSurveyPart", IntegerType.INSTANCE, enumeration.PMFM_ID_SURVEY_PART); if (source == null) { return null; @@ -253,6 +258,9 @@ } } + // load surverPart + result.setSurveyPart((String)source[12]); + // get secondary gears from fishingOperation (first load from Allegro DB only) if (result.getGear() == null) { Iterator<Object[]> list = queryList( @@ -315,10 +323,11 @@ protected void cruiseToEntity(Cruise source, ScientificCruise target, boolean copyIfNull) { StringBuilder miscDataBuffer = new StringBuilder(); - QualityFlag qualityFlagNotQualified = qualityFlagDao.load(enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED); + QualityFlag qualityFlagNotQualified = load( + QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED); // Retrieve entities : FishingTrip - ObservedFishingTrip fishingTrip = null; + ObservedFishingTrip fishingTrip; if (target.getFishingTrips() == null || target.getFishingTrips().size() == 0) { fishingTrip = ObservedFishingTrip.Factory.newInstance(); if (target.getFishingTrips() == null) { @@ -438,14 +447,15 @@ if (source.getHeadOfMission().size() > 0) { Person managerPerson = source.getHeadOfMission().get(0); if (managerPerson.getId() != null) { - target.setManagerPerson(personDao.load(Integer.valueOf(managerPerson.getId()))); + //TODO TC supprimer les xxxDAO.load par load(xxx,) + target.setManagerPerson(load(PersonImpl.class, Integer.valueOf(managerPerson.getId()))); } } } // Optional values in UI, but mandatory in DB if (target.getManagerPerson() == null) { - target.setManagerPerson(personDao.load(enumeration.PERSON_ID_UNKNOWN_RECORDER_PERSON)); + target.setManagerPerson(load(PersonImpl.class, enumeration.PERSON_ID_UNKNOWN_RECORDER_PERSON)); } // Default values : @@ -490,6 +500,12 @@ fishingTrip.setReturnLocation(locationCountry); } + //TODO Serie partiel (ajouter SurveyMeasurement dans fishingtrip) + + //TODO Creer un psfm serie partielle (voir avec vincent + benoit) (PmfmId.SURVEY_PART) + + setSurveyMeasurement(fishingTrip, enumeration.PMFM_ID_SURVEY_PART, null, source.getSurveyPart(), null); + // Gear if (copyIfNull && source.isGearEmpty() && fishingTrip.getGearPhysicalFeatures() != null) { fishingTrip.getGearPhysicalFeatures().clear(); @@ -516,9 +532,9 @@ // Trawl net (store in Gear Physical features) if (copyIfNull && source.getMultirigNumber() == null) { - gearPhysicalFeaturesDao.removeGearPhysicalMeasurement(guf, enumeration.PMFM_ID_MULTIRIG_NUMBER); + gearPhysicalFeaturesDao.removeGearPhysicalMeasurement(guf, enumeration.PMFM_ID_MULTIRIG_NUMBER); } else { - gearPhysicalFeaturesDao.setGearPhysicalMeasurement(target, guf, enumeration.PMFM_ID_MULTIRIG_NUMBER, Float.valueOf(source.getMultirigNumber()), null, null); + gearPhysicalFeaturesDao.setGearPhysicalMeasurement(target, guf, enumeration.PMFM_ID_MULTIRIG_NUMBER, Float.valueOf(source.getMultirigNumber()), null, null); } } @@ -554,4 +570,54 @@ return persons; } + + // adapt to surveyMeasurement + protected SurveyMeasurement getSurveyMeasurement(FishingTrip scientificCruise, + Integer pmfmId, + boolean createIfNotExists) { + SurveyMeasurement gearUseMeasurement = null; + + for (SurveyMeasurement vum : scientificCruise.getSurveyMeasurements()) { + if (pmfmId.equals(vum.getPmfm().getId())) { + gearUseMeasurement = vum; + break; + } + } + + if (gearUseMeasurement == null) { + if (!createIfNotExists) { + return null; + } + gearUseMeasurement = SurveyMeasurement.Factory.newInstance(); + if (scientificCruise.getSurveyMeasurements() == null) { + scientificCruise.setSurveyMeasurements(Sets.newHashSet(gearUseMeasurement)); + } else { + scientificCruise.getSurveyMeasurements().add(gearUseMeasurement); + } + gearUseMeasurement.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); + gearUseMeasurement.setDepartment(scientificCruise.getRecorderDepartment()); + Pmfm pmfm = (Pmfm) getCurrentSession().load(PmfmImpl.class, pmfmId); + gearUseMeasurement.setPmfm(pmfm); + } + + return gearUseMeasurement; + } + + protected SurveyMeasurement setSurveyMeasurement(FishingTrip scientificCruise, + Integer pmfmId, + Float numericalValue, + String alphanumericalValue, + Integer qualitativevalueId) { + SurveyMeasurement vesselUseMeasurement = getSurveyMeasurement(scientificCruise, pmfmId, true); + + if (alphanumericalValue != null) { + vesselUseMeasurement.setAlphanumericalValue(alphanumericalValue); + } else if (numericalValue != null) { + vesselUseMeasurement.setNumericalValue(numericalValue); + } else if (qualitativevalueId != null) { + vesselUseMeasurement.setQualitativeValue(load(QualitativeValueImpl.class, qualitativevalueId)); + } + + return vesselUseMeasurement; + } } 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-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-28 09:08:07 UTC (rev 500) @@ -24,34 +24,9 @@ * #L% */ -import java.io.Serializable; -import java.sql.Timestamp; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import javax.annotation.Resource; - -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.FlushMode; -import org.hibernate.type.IntegerType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.stereotype.Service; - 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; import fr.ifremer.adagio.core.dao.data.fishingArea.FishingArea2RegulationLocation; @@ -92,7 +67,29 @@ 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 org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.FlushMode; +import org.hibernate.type.IntegerType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.io.Serializable; +import java.sql.Timestamp; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + /** * @author tchemit <chemit@codelutin.com> * @since 0.3 @@ -104,7 +101,6 @@ private static final Log log = LogFactory.getLog(FishingOperationPersistenceServiceImpl.class); - @Autowired protected ReferentialPersistenceService referentialService; @@ -170,7 +166,7 @@ } if (fishingOperationNumberStr.matches("\\d+")) { fishingOperation.setFishingOperationNumber(Integer.valueOf(fishingOperationNumberStr)); - } + } } // If not found, compute it using a counter (see "order by startDateTime" in HQL query) @@ -189,7 +185,7 @@ } // Multirig Aggregation - String multirigAggregation = (String) source[colIndex++]; + String multirigAggregation = (String) source[colIndex]; if (multirigAggregation != null) { fishingOperation.setMultirigAggregation(multirigAggregation); } @@ -333,17 +329,17 @@ } // Vessel (the one with the catch batch) - String vesselCode = (String) source[colIndex++]; + String vesselCode = (String) source[colIndex]; if (vesselCode != null) { Vessel vessel = referentialService.getVessel(vesselCode); result.setVessel(vessel); } - // Retrieve environment caracteristics : - getEnvironmentCaracteristics(id, result); + // Retrieve gear shooting caracteristics + getGearUseCaracteristics(id, result); - // Retrieve gear shooting caracteristics : - getGearShootingCaracteristics(id, result); + // TODO-TC Retrieve environment caracteristics with protocol + getVesselUseCaracteristics(id, result); return result; } @@ -352,9 +348,17 @@ @Override public FishingOperation createFishingOperation(FishingOperation bean) { Preconditions.checkNotNull(bean); + Preconditions.checkArgument(bean.getId() == null); Preconditions.checkNotNull(bean.getCruise()); Preconditions.checkNotNull(bean.getCruise().getId()); + //TODO-TC Voir si il n'y a pas d'autre données obligatoires + if (bean.getGearShootingStartDate() != null && bean.getGearShootingEndDate() != null) { + + //make sure not same date + Preconditions.checkArgument(!bean.getGearShootingStartDate().equals(bean.getGearShootingEndDate())); + } + getCurrentSession().setFlushMode(FlushMode.COMMIT); fr.ifremer.adagio.core.dao.data.operation.FishingOperation fishingOperation = fr.ifremer.adagio.core.dao.data.operation.FishingOperation.Factory.newInstance(); beanToEntity(bean, fishingOperation, true); @@ -370,9 +374,12 @@ Preconditions.checkNotNull(bean.getId()); Preconditions.checkNotNull(bean.getCruise()); Preconditions.checkNotNull(bean.getCruise().getId()); + //TODO-TC Voir si il n'y a pas d'autre données obligatoires if (bean.getGearShootingStartDate() != null && bean.getGearShootingEndDate() != null) { - Preconditions.checkArgument(bean.getGearShootingStartDate().equals(bean.getGearShootingEndDate()) == false); + + //make sure not same date + Preconditions.checkArgument(!bean.getGearShootingStartDate().equals(bean.getGearShootingEndDate())); } getCurrentSession().clear(); @@ -391,10 +398,10 @@ //-- Internal methods --// //------------------------------------------------------------------------// - protected void getEnvironmentCaracteristics(String fishingOperationId, FishingOperation result) { + protected void getVesselUseCaracteristics(String fishingOperationId, FishingOperation result) { // retrieve fishing operation caracteristics Iterator<Object[]> list = queryList( - "fishingOperationEnvironment", + "fishingOperationVesselUseFeatures", "fishingOperationId", IntegerType.INSTANCE, Integer.valueOf(fishingOperationId) ); @@ -419,12 +426,11 @@ // Haul valid ? else if (enumeration.PMFM_ID_HAUL_VALID.equals(pmfmId)) { - if (qualitativeValueId != null) { - result.setFishingOperationValid(enumeration.QUALITATIVE_HAUL_VALID_YES.equals(qualitativeValueId)); - } - else { - result.setFishingOperationValid(null); - } + if (qualitativeValueId != null) { + result.setFishingOperationValid(enumeration.QUALITATIVE_HAUL_VALID_YES.equals(qualitativeValueId)); + } else { + result.setFishingOperationValid(null); + } } // Station Number : @@ -434,6 +440,9 @@ // Environment caracteristic else { + + //TODO Split en fonction du protocole + Caracteristic environmentCaracteristic = referentialService.getCaracteristic(pmfmId); Serializable value = null; if (environmentCaracteristic.getCaracteristicType() == CaracteristicType.NUMBER) { @@ -457,10 +466,10 @@ } } - protected void getGearShootingCaracteristics(String fishingOperationId, FishingOperation result) { + protected void getGearUseCaracteristics(String fishingOperationId, FishingOperation result) { // retrieve fishing operation caracteristics Iterator<Object[]> list = queryList( - "fishingOperationGearShooting", + "fishingOperationGearUseFeatures", "fishingOperationId", IntegerType.INSTANCE, Integer.valueOf(fishingOperationId) ); @@ -489,7 +498,7 @@ } else if (gearShootingCaracteristic.getCaracteristicType() == CaracteristicType.TEXT) { value = alphanumericalValue; } else if (gearShootingCaracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE) { - for (CaracteristicQualitativeValue qv : gearShootingCaracteristic.getQualitativeValue()) { + for (CaracteristicQualitativeValue qv : gearShootingCaracteristic.getQualitativeValue()) { if (qualitativeValueId == Integer.parseInt(qv.getId())) { value = qv; break; @@ -595,6 +604,8 @@ // Retrieve entities : Fishing Area FishingArea fishingArea; + List<FishingArea2RegulationLocation> notChangedRegulationLocation; + if (CollectionUtils.isEmpty(gearUseFeatures.getFishingAreas())) { fishingArea = FishingArea.Factory.newInstance(); if (gearUseFeatures.getFishingAreas() == null) { @@ -604,19 +615,14 @@ gearUseFeatures.getFishingAreas().add(fishingArea); fishingArea.setGearUseFeatures(gearUseFeatures); } + notChangedRegulationLocation = Lists.newArrayList(); } else { fishingArea = gearUseFeatures.getFishingAreas().iterator().next(); + + notChangedRegulationLocation = Lists.newArrayList(fishingArea.getRegulationLocation()); // Reset all other fishing areas } - // Retrieve entities : CatchBatch - /*CatchBatch catchBatch = target.getCatchBatch(); - if (catchBatch == null) { - catchBatch = CatchBatch.Factory.newInstance(); - catchBatch.setFishingOperation(target); - target.setCatchBatch(catchBatch); - }*/ - // Retrieve multirig number, from Gear physical features int cruiseMultirigCount = 1; // default value if (gearPhysicalFeatures != null) { @@ -852,6 +858,8 @@ } } + //TODO Add also *other + hydrologic* caracteristics + // Recorder persons StringBuilder miscDataBuffer = new StringBuilder(); if (copyIfNull && (source.getSaisisseur() == null || source.getSaisisseur().size() == 0)) { @@ -878,7 +886,7 @@ // Removed unecessary *UseMeasurement : --- // ---------------------------------------------------------------- - // Gear shooting Caracteristics + // Gear use Caracteristics CaracteristicMap gearShootingCaracteristics = source.getGearShootingCaracteristics(); if (copyIfNull && gearShootingCaracteristics == null || gearShootingCaracteristics.size() == 0) { // Nothing to do : will be removed later, using notChangedGearUseMeasurements @@ -914,15 +922,21 @@ statisticalLocationId = locationService.getLocationIdByLatLong(source.getGearShootingEndLatitude(), source.getGearShootingEndLongitude()); } + //TODO Do a notchange area and remove it at then end // Strata : if (copyIfNull && (source.getStrata() == null || source.getStrata().getId() == null)) { - // TODO remove from fishing Area ? + + // will be removed using notChangedRegulationLocation + } else if (source.getStrata() != null && source.getStrata().getId() != null) { FishingArea2RegulationLocation fa2rl = FishingArea2RegulationLocation.Factory.newInstance(); FishingArea2RegulationLocationPK fa2rlPK = new FishingArea2RegulationLocationPK(); fa2rl.setFishingArea2RegulationLocationPk(fa2rlPK); fa2rlPK.setFishingArea(fishingArea); fa2rlPK.setLocation(load(LocationImpl.class, Integer.valueOf(source.getStrata().getId()))); + + //TODO Make this work + notChangedRegulationLocation.remove(fa2rl); if (fishingArea.getRegulationLocation() == null) { fishingArea.setRegulationLocation(Sets.newHashSet(fa2rl)); } else { @@ -935,13 +949,19 @@ // Sub-Strata : if (copyIfNull && (source.getSubStrata() == null || source.getSubStrata().getId() == null)) { - // TODO remove from fishing Area ? + + // will be removed using notChangedRegulationLocation + } else if (source.getSubStrata() != null && source.getSubStrata().getId() != null) { FishingArea2RegulationLocation fa2rl = FishingArea2RegulationLocation.Factory.newInstance(); FishingArea2RegulationLocationPK fa2rlPK = new FishingArea2RegulationLocationPK(); fa2rl.setFishingArea2RegulationLocationPk(fa2rlPK); fa2rlPK.setFishingArea(fishingArea); fa2rlPK.setLocation(load(LocationImpl.class, Integer.valueOf(source.getSubStrata().getId()))); + + //TODO Make this work + notChangedRegulationLocation.remove(fa2rl); + if (fishingArea.getRegulationLocation() == null) { fishingArea.setRegulationLocation(Sets.newHashSet(fa2rl)); } else { @@ -954,13 +974,18 @@ // Localite : if (copyIfNull && (source.getLocation() == null || source.getLocation().getId() == null)) { - // TODO remove from fishing Area ? + + // will be removed using notChangedRegulationLocation + } else if (source.getLocation() != null && source.getLocation().getId() != null) { FishingArea2RegulationLocation fa2rl = FishingArea2RegulationLocation.Factory.newInstance(); FishingArea2RegulationLocationPK fa2rlPK = new FishingArea2RegulationLocationPK(); fa2rl.setFishingArea2RegulationLocationPk(fa2rlPK); fa2rlPK.setFishingArea(fishingArea); fa2rlPK.setLocation(load(LocationImpl.class, Integer.valueOf(source.getLocation().getId()))); + + //TODO Make this work + notChangedRegulationLocation.remove(fa2rl); if (fishingArea.getRegulationLocation() == null) { fishingArea.setRegulationLocation(Sets.newHashSet(fa2rl)); } else { @@ -971,6 +996,9 @@ } } + //TODO Test well if not removed use fishingArea2RegulationLocationDAO... + fishingArea.getRegulationLocation().removeAll(notChangedRegulationLocation); + // Fishing Area location (should be a statistical location) if (copyIfNull && statisticalLocationId == null) { gearUseFeatures.getFishingAreas().remove(fishingArea); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-28 09:08:07 UTC (rev 500) @@ -244,8 +244,8 @@ List<Vessel> result = Lists.newArrayList(); while (list.hasNext()) { Object[] source = list.next(); - Vessel target = loadVessel(source); - target.setScientificVessel(true); + Vessel target = loadVessel(source, true); + result.add(target); } return result; @@ -263,7 +263,7 @@ List<Vessel> result = Lists.newArrayList(); while (list.hasNext()) { Object[] source = list.next(); - Vessel target = loadVessel(source); + Vessel target = loadVessel(source, false); target.setScientificVessel(false); result.add(target); } @@ -284,7 +284,7 @@ ); Vessel result; if (source.hasNext()) - result = loadVessel(source.next()); + result = loadVessel(source.next(), false); else result = null; return result; @@ -299,8 +299,7 @@ List<Gear> result = Lists.newArrayList(); while (sources.hasNext()) { Object[] source = sources.next(); - Gear target = loadGear(source); - target.setScientificGear(true); + Gear target = loadGear(source, true); result.add(target); } return result; @@ -314,8 +313,7 @@ List<Gear> result = Lists.newArrayList(); while (sources.hasNext()) { Object[] source = sources.next(); - Gear target = loadGear(source); - target.setScientificGear(false); + Gear target = loadGear(source, false); result.add(target); } return result; @@ -354,7 +352,7 @@ "gear", "gearId", IntegerType.INSTANCE, gearId); - Gear result = source == null ? null : loadGear(source); + Gear result = source == null ? null : loadGear(source, true); return result; } @@ -774,12 +772,13 @@ return target; } - protected Vessel loadVessel(Object[] source) { + protected Vessel loadVessel(Object[] source, boolean scientificVessel) { Vessel target = new Vessel(); target.setId((String) source[0]); target.setRegistrationCode((String) source[1]); target.setInternationalRegistrationCode((String) source[2]); target.setName((String) source[3]); + target.setScientificVessel(scientificVessel); setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[4], target); return target; } @@ -794,11 +793,13 @@ return target; } - protected Gear loadGear(Object[] source) { + protected Gear loadGear(Object[] source, boolean scientificGear) { Gear result = new Gear(); result.setId(String.valueOf(source[0])); result.setLabel((String) source[1]); result.setName((String) source[2]); + result.setScientificGear(scientificGear); + setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[3], result); return result; } @@ -885,6 +886,8 @@ @CachePut(value = "referentSpecies") protected List<Species> putToSpeciesReferentCache(List<Species> species) { + + return species; } Deleted: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceService.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,102 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -/** - * CRUD of {@link SpeciesBatch} entity. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Transactional(readOnly = true) -public interface SpeciesBatchPersistenceService extends TuttiPersistenceServiceImplementor { - - /** - * Get all root {@link SpeciesBatch} for the given fishing operation. - * <p/> - * <strong>Note:</strong> All childs of the batch should be loaded here. - * - * @param fishingOperationId if of the fishing operation to seek - * @return the list of root {@link SpeciesBatch} - * @since 1.0 - */ - List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId); - - /** - * Get all frequencies for the given species batch. - * - * @param speciesBatchId the id of the species batch to seek. - * @return the list of frequencies for the given specues batch id - * @since 1.0 - */ - List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency( - String speciesBatchId); - - @Transactional(readOnly = false) - SpeciesBatch createSpeciesBatch(SpeciesBatch bean, String parentBatchId); - - @Transactional(readOnly = false) - SpeciesBatch saveSpeciesBatch(SpeciesBatch bean); - - @Transactional(readOnly = false) - void deleteSpeciesBatch(String id); - - @Transactional(readOnly = false) - void deleteSpeciesSubBatch(String id); - - /** - * Change the species in the given {@code batchId} and in all his - * sub batches. - * - * @param batchId id of the root species batch to treat - * @param species species to affect to all batches - */ - @Transactional(readOnly = false) - void changeSpeciesBatchSpecies(String batchId, Species species); - - /** - * Save all given {@link SpeciesBatchFrequency} into the given - * {@code speciesBatchId}. If some are not existing then creates them. - * <p/> - * <strong>Note:</strong> This will as a side effect remove all previous frequency for this species batch. - * - * @param speciesBatchId id of the {@link SpeciesBatch} to use - * @param frequencies list of frequencies to create or update - * @return the persisted list of frequencies - * @since 1.0 - */ - @Transactional(readOnly = false) - List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(String speciesBatchId, - List<SpeciesBatchFrequency> frequencies); - -} Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-02-28 09:08:07 UTC (rev 500) @@ -128,6 +128,9 @@ @Value("${QualitativeValueId.SORTING_TYPE_SPECIES}") public final Integer QUALITATIVE_ID_SORTING_TYPE_SPECIES = null; + @Value("${QualitativeValueId.SORTING_TYPE_BENTHOS}") + public final Integer QUALITATIVE_ID_SORTING_TYPE_BENTHOS = null; + @Value("${StatusCode.ENABLE}") public final String STATUS_VALID_CODE = null; @@ -182,6 +185,9 @@ @Value("${PmfmId.AGE}") public final Integer PMFM_ID_AGE = null; + @Value("${PmfmId.SURVEY_PART}") + public final Integer PMFM_ID_SURVEY_PART = null; + @Value("${ProgramCode.SCIENTIFIC_CRUISE_PREFIX}") public final String PROGRAM_CODE_SCIENTIFIC_CRUISE_PREFIX = null; Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiPersistenceServiceLocator.java 2013-02-28 09:08:07 UTC (rev 500) @@ -85,21 +85,6 @@ BatchPersistenceService.class); } - public static CatchBatchPersistenceService getCatchBatchPersistenceService() { - return getPersistenceService("batchPersistenceService", - CatchBatchPersistenceService.class); - } - - public static SpeciesBatchPersistenceService getSpeciesBatchPersistenceService() { - return getPersistenceService("batchPersistenceService", - SpeciesBatchPersistenceService.class); - } - - public static BenthosBatchPersistenceService getBenthosBatchPersistenceService() { - return getPersistenceService("benthosBatchPersistenceService", - BenthosBatchPersistenceService.class); - } - public static PlanktonBatchPersistenceService getPlanktonBatchPersistenceService() { return getPersistenceService("planktonBatchPersistenceService", PlanktonBatchPersistenceService.class); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java 2013-02-28 09:08:07 UTC (rev 500) @@ -26,6 +26,7 @@ import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; import java.util.Collection; import java.util.HashSet; @@ -95,31 +96,33 @@ protected void validate(Collection<Batch> batchs, List<CatchBatchValidationError> errors, int treeLevel) { + //TODO finishi i18n + // Vrac SortingBatch vracBatch = catchBatchDao.getSortingBatch(batchs, "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID); if (vracBatch == null) { - addError(errors, "tutti.persistence.batch.validation.vracNotFound", null); + addError(errors, n_("tutti.persistence.batch.validation.vracNotFound"), null); } else { // Vrac > Species SortingBatch speciesBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (speciesBatch == null) { - addError(errors, "tutti.persistence.batch.validation.vracSpeciesNotFound", null); + addError(errors, n_("tutti.persistence.batch.validation.vracSpeciesNotFound"), null); } else { // Vrac > Species > Inert SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); if (inertBatch == null) { - addWarning(errors, "tutti.persistence.batch.validation.vracSpeciesInertNotFound"); + addWarning(errors, n_("tutti.persistence.batch.validation.vracSpeciesInertNotFound")); } // Vrac > Species > Alive no itemized SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); if (livingNotItemizedBatch == null) { - addWarning(errors, "tutti.persistence.batch.validation.vracSpeciesLifeNotFound"); + addWarning(errors, n_("tutti.persistence.batch.validation.vracSpeciesLifeNotFound")); } } @@ -131,14 +134,14 @@ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID); if (horsVracBatch == null) { - addWarning(errors, "tutti.persistence.batch.validation.horsVracSpeciesNotFound"); + addWarning(errors, n_("tutti.persistence.batch.validation.horsVracSpeciesNotFound")); } else { // Hors Vrac > Species SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (speciesBatch == null) { - addWarning(errors, "tutti.persistence.batch.validation.horsVracSpeciesNotFound"); + addWarning(errors, n_("tutti.persistence.batch.validation.horsVracSpeciesNotFound")); } // TODO : Benthos, Plancton... @@ -149,7 +152,7 @@ "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID); if (unsortedBatch == null) { - addWarning(errors, "tutti.persistence.batch.validation.unsortedNotFound"); + addWarning(errors,n_( "tutti.persistence.batch.validation.unsortedNotFound")); } // May be, the tree is an old structure @@ -157,31 +160,30 @@ boolean allBatchHasSpecies = true; boolean allBatchHasVrac = true; boolean someBatchHasSortingMeasurement = false; - for (Iterator<Batch> iterator = batchs.iterator(); iterator.hasNext();) { - SortingBatch batch = (SortingBatch) iterator.next(); - if (allBatchHasSpecies && batch.getReferenceTaxon() == null) { - allBatchHasSpecies = false; - break; - } - if (allBatchHasVrac && batch.getSortingMeasurements() != null) { - if (batch.getSortingMeasurements().size() > 1) { - allBatchHasVrac = false; - someBatchHasSortingMeasurement = true; - } - else if (batch.getSortingMeasurements().size() == 1) { - someBatchHasSortingMeasurement = true; - SortingMeasurement sm = batch.getSortingMeasurements().iterator().next(); - if (enumeration.PMFM_ID_SORTED_UNSORTED.equals(sm.getPmfm().getId()) == false - || sm.getQualitativeValue() == null - || enumeration.QUALITATIVE_VRAC_ID.equals(sm.getQualitativeValue().getId()) == false) { - allBatchHasVrac = false; - } - } - } - } + for (Batch batch1 : batchs) { + SortingBatch batch = (SortingBatch) batch1; + if (allBatchHasSpecies && batch.getReferenceTaxon() == null) { + allBatchHasSpecies = false; + break; + } + if (allBatchHasVrac && batch.getSortingMeasurements() != null) { + if (batch.getSortingMeasurements().size() > 1) { + allBatchHasVrac = false; + someBatchHasSortingMeasurement = true; + } else if (batch.getSortingMeasurements().size() == 1) { + someBatchHasSortingMeasurement = true; + SortingMeasurement sm = batch.getSortingMeasurements().iterator().next(); + if (!enumeration.PMFM_ID_SORTED_UNSORTED.equals(sm.getPmfm().getId()) + || sm.getQualitativeValue() == null + || !enumeration.QUALITATIVE_VRAC_ID.equals(sm.getQualitativeValue().getId())) { + allBatchHasVrac = false; + } + } + } + } if (allBatchHasSpecies && !someBatchHasSortingMeasurement) { errors.clear(); - addError(errors, "tutti.persistence.batch.validation.onlySpeciesBatchStructure", new CatchBatchQuickFix() { + addError(errors,n_( "tutti.persistence.batch.validation.onlySpeciesBatchStructure"), new CatchBatchQuickFix() { @Override public CatchBatch repair(CatchBatch catchBatch) { return ScientificCruiseCatchBatchValidator.this.repairHistoricalData(catchBatch, false); @@ -190,7 +192,7 @@ } else if (allBatchHasSpecies && someBatchHasSortingMeasurement && allBatchHasVrac) { errors.clear(); - addError(errors, "tutti.persistence.batch.validation.onlySpeciesBatchStructure", new CatchBatchQuickFix() { + addError(errors, n_("tutti.persistence.batch.validation.onlySpeciesBatchStructure"), new CatchBatchQuickFix() { @Override public CatchBatch repair(CatchBatch catchBatch) { return ScientificCruiseCatchBatchValidator.this.repairHistoricalData(catchBatch, true); @@ -228,29 +230,30 @@ } // For all species batch : set the batch 'Vrac>Species' as new parent - for (Iterator<Batch> iterator = speciesBatchChilds.iterator(); iterator.hasNext();) { - SortingBatch batch = (SortingBatch) iterator.next(); - batch.setParentBatch(speciesBatch); + for (Batch speciesBatchChild : speciesBatchChilds) { + SortingBatch batch = (SortingBatch) speciesBatchChild; + batch.setParentBatch(speciesBatch); - if (batchHasVracSortingMeasurement) { - // Remove redundant 'Vrac' sorting measurement - SortingMeasurement sm = catchBatchDao.getSortingMeasurement(batch, enumeration.PMFM_ID_SORTED_UNSORTED, null, false); - batch.getSortingMeasurements().remove(sm); - } + if (batchHasVracSortingMeasurement) { + // Remove redundant 'Vrac' sorting measurement + SortingMeasurement sm = catchBatchDao.getSortingMeasurement(batch, enumeration.PMFM_ID_SORTED_UNSORTED, null, false); + batch.getSortingMeasurements().remove(sm); + } - batch.setExhaustiveInventory(Boolean.TRUE); + batch.setExhaustiveInventory(Boolean.TRUE); - // Add an offset into the rank order, because of special batchs 'Biota' (=live) and 'Inert' - short rankOrder = (short)(batch.getRankOrder().shortValue() + 2); - batch.setRankOrder(rankOrder); + // Add an offset into the rank order, because of special batchs 'Biota' (=live) and 'Inert' + short rankOrder = (short) (batch.getRankOrder().shortValue() + 2); + batch.setRankOrder(rankOrder); - // Reset comments if set to "taxon" - if (batch.getComments() != null && "taxon".equals(batch.getComments())) { - batch.setComments(null); - } + //TODO What to do with weird comments! categorie_individu + // Reset comments if set to "taxon" + if (batch.getComments() != null && "taxon".equals(batch.getComments())) { + batch.setComments(null); + } - speciesBatch.getChildBatchs().add(batch); - } + speciesBatch.getChildBatchs().add(batch); + } // Save mofidifications : catchBatchDao.update(catchBatch); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java 2013-02-28 09:08:07 UTC (rev 500) @@ -124,7 +124,7 @@ } else if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER) { measurement.setNumericalValue((Float) value); } else if (caracteristic.getCaracteristicType() == CaracteristicType.QUALITATIVE) { - Integer qvId = null; + Integer qvId; if (value instanceof CaracteristicQualitativeValue) { qvId = Integer.valueOf(((CaracteristicQualitativeValue) value).getId()); } else if (value instanceof Integer) { Modified: trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties =================================================================== --- trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties 2013-02-28 09:08:07 UTC (rev 500) @@ -14,6 +14,7 @@ tutti.option.persistence.protocol.directory.description=Répertoire où sont conservés les protocoles tutti.persistence.batch.validation.horsVracNotFound=Lot 'Hors Vrac' non trouvé, ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.horsVracSpeciesNotFound=Batch 'Hors Vrac > Espèces' non trouvé ou configuré avec d'autres critères de classement. +tutti.persistence.batch.validation.onlySpeciesBatchStructure= tutti.persistence.batch.validation.unsortedNotFound=Batch 'Hors Vrac > Espèces' non trouvé ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.vracNotFound=Lot 'Vrac' non trouvé, ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.vracSpeciesInertNotFound=Lot 'Vrac > Espèces > Inerte' non trouvé, ou configuré avec d'autres critères de classement. Modified: trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml =================================================================== --- trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-02-28 09:08:07 UTC (rev 500) @@ -118,7 +118,8 @@ sc.vessel.code AS vesselCode, mp.id AS managerId, sc.comments AS scientificCruiseComments, - ft.comments AS fishingTripComments + ft.comments AS fishingTripComments, + (select sm.alphanumericalValue from SurveyMeasurementImpl sm where sm.fishingTrip.id=ft.id and sm.pmfm.id= :pmfmIdSurveyPart) AS surveyPart, FROM ScientificCruiseImpl sc LEFT OUTER JOIN sc.fishingTrips ft @@ -130,6 +131,7 @@ AND lh.locationHierarchyPk.location.id = ft.departureLocation.id ]]> <query-param name="cruiseId" type="java.lang.Integer"/> + <query-param name="pmfmIdSurveyPart" type="java.lang.Integer"/> <query-param name="countryLocationLevelId" type="java.lang.Integer"/> </query> @@ -210,21 +212,21 @@ max(g.id) AS gearId, (select vp_start from VesselPositionImpl vp_start where vp_start.operation.id = o.id and vp_start.dateTime = o.startDateTime) AS startVesselPosition, (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 (va.isCatchOnOperationVessel = false) then va.id.vessel.code else o.vessel.code end) as vesselCode - FROM - FishingOperationImpl o - INNER JOIN o.gearUseFeatures guf - LEFT OUTER JOIN guf.gear g - 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 + 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 (va.isCatchOnOperationVessel = false) then va.id.vessel.code else o.vessel.code end) as vesselCode + FROM + FishingOperationImpl o + INNER JOIN o.gearUseFeatures guf + LEFT OUTER JOIN guf.gear g + 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 ]]> <query-param name="fishingOperationId" type="java.lang.Integer"/> <query-param name="locationLevelIdStrata" type="java.lang.Integer"/> @@ -235,21 +237,21 @@ <query name="fishingOperationRankOrder"> <![CDATA[ SELECT - count(o1.id)+1 as fishingOperationRankOrder + count(o1.id) + 1 as fishingOperationRankOrder FROM FishingOperationImpl o1, FishingOperationImpl o2 WHERE - o1.fishingTrip.id=o2.fishingTrip.id - and o1.startDateTime < o2.startDateTime - and o2.id = :fishingOperationId + o1.fishingTrip.id = o2.fishingTrip.id + AND o1.startDateTime < o2.startDateTime + AND o2.id = :fishingOperationId ]]> <query-param name="fishingOperationId" type="java.lang.Integer"/> </query> - <query name="fishingOperationEnvironment"> + <query name="fishingOperationVesselUseFeatures"> <![CDATA[ SELECT vum.pmfm.id as pmfmId, @@ -265,7 +267,7 @@ <query-param name="fishingOperationId" type="java.lang.Integer"/> </query> - <query name="fishingOperationGearShooting"> + <query name="fishingOperationGearUseFeatures"> <![CDATA[ SELECT gum.pmfm.id as pmfmId, Modified: trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties =================================================================== --- trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties 2013-02-28 09:08:07 UTC (rev 500) @@ -315,19 +315,22 @@ # radiale LocationLevelId.RADIALE=305 +# Catégorie Sex PmfmId.SEX=196 +# Catégorie classe de tri PmfmId.SIZE_CATEGORY=198 +# Catégorie Age PmfmId.AGE=1430 - # Catégorie maturité PmfmId.MATURITY=174 - # Catégorie macro-déchet PmfmId.MARINE_LITTER_TYPE=1421 - # Classe de taille macro-déchet PmfmId.MARINE_LITTER_SIZE_CATEGORY=1422 +# TODO Alphanumeric = true A creer (dans les enumerations Allegro) +PmfmId.SURVEY_PART=-192 + # TODO A creer (dans les enumerations Allegro) PmfmId.STATION_NUMBER=1243 # TODO A creer (dans les enumerations Allegro) Modified: trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo =================================================================== (Binary files differ) Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -47,7 +47,7 @@ import static org.junit.Assert.fail; /** - * To test {@link CatchBatchPersistenceService} for read operation. + * To test {@link BatchPersistenceService} for read operation. * * @author tchemit <chemit@codelutin.com> * @since 1.0 @@ -89,13 +89,24 @@ @Test public void getAllRootSpeciesBatch(/*String fishingOperationId*/) { + //TODO Do me! } @Test public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) { + //TODO Do me! + } + @Test + public void getAllRootBenthosBatch(/*String fishingOperationId*/) { + //TODO Do me! } + @Test + public void getAllBenthosBatchFrequency(/*String benthosBatchId*/) { + //TODO Do me! + } + public static void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { assertNotNull(actualBatch); assertNotNull(actualBatch.getId()); @@ -127,7 +138,9 @@ } } - public static void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) { + public static void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, + List<SpeciesBatchFrequency> actualFrequencies, + boolean assertIdEquals) { assertNotNull(actualFrequencies); assertEquals(expectedFrequencies.size(), actualFrequencies.size()); @@ -161,11 +174,13 @@ } } - public static SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { + public static SpeciesBatch getSpeciesBatch(String fishingOperationId, + String speciesBatchId) { return getSpeciesBatch(speciesBatchId, TuttiPersistenceServiceLocator.getBatchPersistenceService().getAllRootSpeciesBatch(fishingOperationId)); } - public static SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { + public static SpeciesBatch getSpeciesBatch(String speciesBatchId, + List<SpeciesBatch> speciesBatchs) { if (speciesBatchs == null) { return null; } Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -24,27 +24,8 @@ * #L% */ -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.springframework.dao.DataRetrievalFailureException; - import com.google.common.collect.Lists; import com.google.common.collect.Maps; - import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.tutti.persistence.DatabaseResource; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; @@ -57,587 +38,833 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.Species; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.springframework.dao.DataRetrievalFailureException; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** - * To test {@link CatchBatchPersistenceService} for write operation. - * + * To test {@link BatchPersistenceService} for write operation. + * * @author tchemit <chemit@codelutin.com> * @since 1.0 */ public class BatchPersistenceServiceWriteTest { - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); - protected BatchPersistenceService service; + protected BatchPersistenceService service; - protected CruisePersistenceService cruiseService; + protected CruisePersistenceService cruiseService; - protected FishingOperationPersistenceService fishingOperationService; + protected FishingOperationPersistenceService fishingOperationService; - protected CatchBatchPersistenceService catchBatchService; + protected ReferentialPersistenceService referentialService; - protected ReferentialPersistenceService referentialService; - /* * Entities prepared in setUp() : * */ - protected Cruise cruise; + protected Cruise cruise; - protected FishingOperation fishingOperationNoCatchBatch; + protected FishingOperation fishingOperationNoCatchBatch; - protected FishingOperation fishingOperationWithEmptyBatch; + protected FishingOperation fishingOperationWithEmptyBatch; - protected CatchBatch catchBacth; + protected CatchBatch catchBacth; - protected List<Species> species; + protected List<Species> species; - protected Caracteristic sortedUnsortedPMFM; + protected Caracteristic sortedUnsortedPMFM; - protected CaracteristicQualitativeValue horsVracQualitativeValue; + protected CaracteristicQualitativeValue horsVracQualitativeValue; - protected CaracteristicQualitativeValue vracQualitativeValue; + protected CaracteristicQualitativeValue vracQualitativeValue; - protected Caracteristic maturityPMFM; + protected Caracteristic maturityPMFM; - protected CaracteristicQualitativeValue firstMaturityQualitativeValue; + protected CaracteristicQualitativeValue firstMaturityQualitativeValue; - protected Caracteristic sexPMFM; + protected Caracteristic sexPMFM; - protected CaracteristicQualitativeValue maleQualitativeValue; + protected CaracteristicQualitativeValue maleQualitativeValue; - protected CaracteristicQualitativeValue femaleQualitativeValue; + protected CaracteristicQualitativeValue femaleQualitativeValue; - protected CaracteristicQualitativeValue unkQualitativeValue; + protected CaracteristicQualitativeValue unkQualitativeValue; - protected Caracteristic frequencyPMFM; + protected Caracteristic frequencyPMFM; - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getBatchPersistenceService(); - cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); + @Before + public void setUp() throws Exception { + service = TuttiPersistenceServiceLocator.getBatchPersistenceService(); + cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); + fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); + referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - species = referentialService.getAllSpecies(); - assertNotNull(species); - assertTrue(species.size() > 2); + species = referentialService.getAllSpecies(); + assertNotNull(species); + assertTrue(species.size() > 2); - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); - cruise.setId(null); - Calendar calendar = new GregorianCalendar(); - cruise.setBeginDate(calendar.getTime()); - cruise.setYear(calendar.get(Calendar.YEAR)); - calendar.add(Calendar.MONTH, 1); // add one month - cruise.setEndDate(calendar.getTime()); - cruise = cruiseService.createCruise(cruise); + cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); + cruise.setId(null); + Calendar calendar = new GregorianCalendar(); + cruise.setBeginDate(calendar.getTime()); + cruise.setYear(calendar.get(Calendar.YEAR)); + calendar.add(Calendar.MONTH, 1); // add one month + cruise.setEndDate(calendar.getTime()); + cruise = cruiseService.createCruise(cruise); - // Create a first operation, with no cacth batch : to test CatchBatch insert/update : - List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); - assertNotNull(fishingOperations); - assertTrue(fishingOperations.size() > 0); - fishingOperationNoCatchBatch = fishingOperations.get(0); - fishingOperationNoCatchBatch = fishingOperationService.getFishingOperation(fishingOperationNoCatchBatch.getId()); - fishingOperationNoCatchBatch.setId(null); - fishingOperationNoCatchBatch.setCruise(cruise); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 1); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperationNoCatchBatch.setGearShootingStartDate(calendar.getTime()); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperationNoCatchBatch.setGearShootingEndDate(calendar.getTime()); - fishingOperationNoCatchBatch = fishingOperationService.createFishingOperation(fishingOperationNoCatchBatch); + // Create a first operation, with no cacth batch : to test CatchBatch insert/update : + List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); + assertNotNull(fishingOperations); + assertTrue(fishingOperations.size() > 0); + fishingOperationNoCatchBatch = fishingOperations.get(0); + fishingOperationNoCatchBatch = fishingOperationService.getFishingOperation(fishingOperationNoCatchBatch.getId()); + fishingOperationNoCatchBatch.setId(null); + fishingOperationNoCatchBatch.setCruise(cruise); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 1); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperationNoCatchBatch.setGearShootingStartDate(calendar.getTime()); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 10); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperationNoCatchBatch.setGearShootingEndDate(calendar.getTime()); + fishingOperationNoCatchBatch = fishingOperationService.createFishingOperation(fishingOperationNoCatchBatch); - // Create a second operation, with no cacth batch : to test CatchBatch insert/update : - fishingOperationWithEmptyBatch = fishingOperations.get(1); - fishingOperationWithEmptyBatch = fishingOperationService.getFishingOperation(fishingOperationWithEmptyBatch.getId()); - fishingOperationWithEmptyBatch.setId(null); - fishingOperationWithEmptyBatch.setCruise(cruise); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 11); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperationWithEmptyBatch.setGearShootingStartDate(calendar.getTime()); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 12); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperationWithEmptyBatch.setGearShootingEndDate(calendar.getTime()); - fishingOperationWithEmptyBatch = fishingOperationService.createFishingOperation(fishingOperationWithEmptyBatch); + // Create a second operation, with no cacth batch : to test CatchBatch insert/update : + fishingOperationWithEmptyBatch = fishingOperations.get(1); + fishingOperationWithEmptyBatch = fishingOperationService.getFishingOperation(fishingOperationWithEmptyBatch.getId()); + fishingOperationWithEmptyBatch.setId(null); + fishingOperationWithEmptyBatch.setCruise(cruise); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 11); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperationWithEmptyBatch.setGearShootingStartDate(calendar.getTime()); + calendar.setTime(new Date()); + calendar.set(Calendar.HOUR_OF_DAY, 12); + calendar.set(Calendar.MILLISECOND, 0); + fishingOperationWithEmptyBatch.setGearShootingEndDate(calendar.getTime()); + fishingOperationWithEmptyBatch = fishingOperationService.createFishingOperation(fishingOperationWithEmptyBatch); - catchBacth = new CatchBatch(); - catchBacth.setFishingOperation(fishingOperationWithEmptyBatch); - catchBacth = catchBatchService.createCatchBatch(catchBacth); + catchBacth = new CatchBatch(); + catchBacth.setFishingOperation(fishingOperationWithEmptyBatch); + catchBacth = service.createCatchBatch(catchBacth); - sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic(); - horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0); - vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1); - maturityPMFM = referentialService.getMaturityCaracteristic(); - firstMaturityQualitativeValue = maturityPMFM.getQualitativeValue(0); - sexPMFM = referentialService.getSexCaracteristic(); - maleQualitativeValue = sexPMFM.getQualitativeValue(1); - femaleQualitativeValue = sexPMFM.getQualitativeValue(2); - unkQualitativeValue = sexPMFM.getQualitativeValue(3); + sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic(); + horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0); + vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1); + maturityPMFM = referentialService.getMaturityCaracteristic(); + firstMaturityQualitativeValue = maturityPMFM.getQualitativeValue(0); + sexPMFM = referentialService.getSexCaracteristic(); + maleQualitativeValue = sexPMFM.getQualitativeValue(1); + femaleQualitativeValue = sexPMFM.getQualitativeValue(2); + unkQualitativeValue = sexPMFM.getQualitativeValue(3); - List<Caracteristic> cara = referentialService.getAllCaracteristic(); - for (Caracteristic caracteristic : cara) { - if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER - && caracteristic.getPrecision() != null - && caracteristic.getPrecision() == 0.5f) { - frequencyPMFM = caracteristic; - break; - } - } - assertNotNull("no numerical PMFM with a precision has been found. Could not define a PMFM for batch frequencies.", frequencyPMFM); + List<Caracteristic> cara = referentialService.getAllCaracteristic(); + for (Caracteristic caracteristic : cara) { + if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER + && caracteristic.getPrecision() != null + && caracteristic.getPrecision() == 0.5f) { + frequencyPMFM = caracteristic; + break; + } + } + assertNotNull("no numerical PMFM with a precision has been found. Could not define a PMFM for batch frequencies.", frequencyPMFM); - } + } - @Test - public void createAndSaveCatchBatch() throws Exception { - CatchBatch catchBatch; + @Test + public void createAndSaveCatchBatch() throws Exception { + CatchBatch catchBatch; - catchBatch = new CatchBatch(); - catchBatch.setFishingOperation(fishingOperationNoCatchBatch); + catchBatch = new CatchBatch(); + catchBatch.setFishingOperation(fishingOperationNoCatchBatch); - // ----------------------------------------------------------------------------- - // 1. Test with only mandatory properties - // ----------------------------------------------------------------------------- + // ----------------------------------------------------------------------------- + // 1. Test with only mandatory properties + // ----------------------------------------------------------------------------- - // Create and reload (test round trip) - assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); + // Create and reload (test round trip) + assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); - // ----------------------------------------------------------------------------- - // 2. Test with all properties - // ----------------------------------------------------------------------------- - catchBatch.setId(null); - // total weight : 100kg - catchBatch.setCatchTotalWeight(75f); - // Vrac : - { - // note : poids trie par la balance tremis (thalassa) (init par pupitri) - catchBatch.setCatchTotalSortedTremisWeight(50f); - // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la - // table de tri (Sum(Si) - catchBatch.setCatchTotalSortedCarousselWeight(45f); + // ----------------------------------------------------------------------------- + // 2. Test with all properties + // ----------------------------------------------------------------------------- + catchBatch.setId(null); + // total weight : 100kg + catchBatch.setCatchTotalWeight(75f); + // Vrac : + { + // note : poids trie par la balance tremis (thalassa) (init par pupitri) + catchBatch.setCatchTotalSortedTremisWeight(50f); + // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la + // table de tri (Sum(Si) + catchBatch.setCatchTotalSortedCarousselWeight(45f); - // Species - { - catchBatch.setSpeciesTotalSortedWeight(12f); - catchBatch.setSpeciesTotalSampleSortedWeight(8f); - catchBatch.setSpeciesTotalLivingNotItemizedWeight(0.2f); - catchBatch.setSpeciesTotalInertWeight(0.1f); - } - } - // Hors Vrac : 10kg - { - catchBatch.setCatchTotalUnsortedWeight(10f); + // Species + { + catchBatch.setSpeciesTotalSortedWeight(12f); + catchBatch.setSpeciesTotalSampleSortedWeight(8f); + catchBatch.setSpeciesTotalLivingNotItemizedWeight(0.2f); + catchBatch.setSpeciesTotalInertWeight(0.1f); + } + } + // Hors Vrac : 10kg + { + catchBatch.setCatchTotalUnsortedWeight(10f); - // Species - { - catchBatch.setSpeciesTotalUnsortedWeight(10f); - } - } - // Rejet : 15kg - catchBatch.setCatchTotalRejectedWeight(15f); + // Species + { + catchBatch.setSpeciesTotalUnsortedWeight(10f); + } + } + // Rejet : 15kg + catchBatch.setCatchTotalRejectedWeight(15f); - // Create and reload (test round trip) - assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); + // Create and reload (test round trip) + assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); - // ----------------------------------------------------------------------------- - // 2. Test save after modification - // ----------------------------------------------------------------------------- - catchBatch.setCatchTotalSortedTremisWeight(null); - catchBatch.setCatchTotalSortedCarousselWeight(null); - catchBatch.setSpeciesTotalSortedWeight(null); - catchBatch.setSpeciesTotalSampleSortedWeight(null); - catchBatch.setCatchTotalUnsortedWeight(null); - catchBatch.setSpeciesTotalUnsortedWeight(null); + // ----------------------------------------------------------------------------- + // 2. Test save after modification + // ----------------------------------------------------------------------------- + catchBatch.setCatchTotalSortedTremisWeight(null); + catchBatch.setCatchTotalSortedCarousselWeight(null); + catchBatch.setSpeciesTotalSortedWeight(null); + catchBatch.setSpeciesTotalSampleSortedWeight(null); + catchBatch.setCatchTotalUnsortedWeight(null); + catchBatch.setSpeciesTotalUnsortedWeight(null); - assertSaveAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); - } + assertSaveAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); + } - @Test - public void createAndSaveSpeciesBatchAndFrequencies() { - SpeciesBatch esp1Batch = null; - SpeciesBatch esp2Batch = null; - SpeciesBatch frequenciesParentBatch = null; - SpeciesBatch batch = null; - Species taxon1 = species.get(0); - Species taxon2 = species.get(1); + @Test + public void createAndSaveSpeciesBatchAndFrequencies() { + SpeciesBatch esp1Batch; + SpeciesBatch esp2Batch; + SpeciesBatch frequenciesParentBatch; + SpeciesBatch batch; + Species taxon1 = species.get(0); + Species taxon2 = species.get(1); - // ----------------------------------------------------------------------------- - // 1. Test with only mandatory properties - // ----------------------------------------------------------------------------- - // batch : "ESP1 - Vrac/5" - batch = new SpeciesBatch(); - batch.setParentBatch(null); - batch.setFishingOperation(fishingOperationNoCatchBatch); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setSampleCategoryWeight(5f); + // ----------------------------------------------------------------------------- + // 1. Test with only mandatory properties + // ----------------------------------------------------------------------------- + // batch : "ESP1 - Vrac/5" + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setFishingOperation(fishingOperationNoCatchBatch); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setSampleCategoryWeight(5f); - assertCreateAndReloadSpeciesBatch(batch, null); + assertCreateAndReloadSpeciesBatch(batch, null); - // Save ESP1 batch - esp1Batch = batch; + // Save ESP1 batch + esp1Batch = batch; - // ----------------------------------------------------------------------------- - // 2. Test child "Male/2" - // ----------------------------------------------------------------------------- - // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp1Batch); - batch.setSpecies(taxon1); - batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7"); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(maleQualitativeValue); - batch.setSampleCategoryWeight(2f); - batch.setWeight(1f); - batch.setNumber(7); + // ----------------------------------------------------------------------------- + // 2. Test child "Male/2" + // ----------------------------------------------------------------------------- + // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp1Batch); + batch.setSpecies(taxon1); + batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7"); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(maleQualitativeValue); + batch.setSampleCategoryWeight(2f); + batch.setWeight(1f); + batch.setNumber(7); - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); + assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - // ----------------------------------------------------------------------------- - // 3. Test child "Female/2" - // ----------------------------------------------------------------------------- - // Batch : ESP1 - Vrac/5 Female/3 Nombre/14 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp1Batch); - batch.setSpecies(taxon1); - batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14"); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(femaleQualitativeValue); - batch.setSampleCategoryWeight(3f); - batch.setWeight(null); - batch.setNumber(14); + // ----------------------------------------------------------------------------- + // 3. Test child "Female/2" + // ----------------------------------------------------------------------------- + // Batch : ESP1 - Vrac/5 Female/3 Nombre/14 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp1Batch); + batch.setSpecies(taxon1); + batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14"); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(femaleQualitativeValue); + batch.setSampleCategoryWeight(3f); + batch.setWeight(null); + batch.setNumber(14); - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); + assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - // ----------------------------------------------------------------------------- - // 4. Test : ESP2 - Vrac/7 - // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 - // ----------------------------------------------------------------------------- - // batch : "ESP2 - Vrac/7 " - batch = new SpeciesBatch(); - batch.setParentBatch(null); - batch.setSpecies(taxon2); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setSampleCategoryWeight(7f); + // ----------------------------------------------------------------------------- + // 4. Test : ESP2 - Vrac/7 + // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 + // ----------------------------------------------------------------------------- + // batch : "ESP2 - Vrac/7 " + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setSpecies(taxon2); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setSampleCategoryWeight(7f); - assertCreateAndReloadSpeciesBatch(batch, null); - esp2Batch = batch; + assertCreateAndReloadSpeciesBatch(batch, null); + esp2Batch = batch; - // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp2Batch); - batch.setSpecies(taxon2); - batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11"); - batch.setSampleCategoryType(SampleCategoryEnum.maturity); - batch.setSampleCategoryValue(firstMaturityQualitativeValue); - batch.setSampleCategoryWeight(2f); - batch.setWeight(1f); - batch.setNumber(11); + // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp2Batch); + batch.setSpecies(taxon2); + batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11"); + batch.setSampleCategoryType(SampleCategoryEnum.maturity); + batch.setSampleCategoryValue(firstMaturityQualitativeValue); + batch.setSampleCategoryWeight(2f); + batch.setWeight(1f); + batch.setNumber(11); - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); + assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - // ----------------------------------------------------------------------------- - // 5. Test save after modifications - // ----------------------------------------------------------------------------- - // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99 - batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99"); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(unkQualitativeValue); - batch.setSampleCategoryWeight(1.75f); - batch.setWeight(1.11f); - batch.setFishingOperation(fishingOperationWithEmptyBatch); - batch.setNumber(99); + // ----------------------------------------------------------------------------- + // 5. Test save after modifications + // ----------------------------------------------------------------------------- + // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99 + batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99"); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(unkQualitativeValue); + batch.setSampleCategoryWeight(1.75f); + batch.setWeight(1.11f); + batch.setFishingOperation(fishingOperationWithEmptyBatch); + batch.setNumber(99); - // Save and reload, then check - SpeciesBatch savedBatch = service.saveSpeciesBatch(batch); - assertSpeciesBatch(savedBatch, batch, false); - SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), savedBatch.getId()); - assertSpeciesBatch(savedBatch, reloadedBatch, true); + // Save and reload, then check + SpeciesBatch savedBatch = service.saveSpeciesBatch(batch); + assertSpeciesBatch(savedBatch, batch, false); + SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), savedBatch.getId()); + assertSpeciesBatch(savedBatch, reloadedBatch, true); - // Save batch for later - frequenciesParentBatch = batch; + // Save batch for later + frequenciesParentBatch = batch; - // ----------------------------------------------------------------------------- - // 6. Test change species - // ----------------------------------------------------------------------------- - esp2Batch.setSpecies(taxon1); - service.changeSpeciesBatchSpecies(esp2Batch.getId(), taxon1); - assertSpeciesBatch(savedBatch, batch, false); - reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp2Batch.getId()); - assertSpeciesBatch(esp2Batch, reloadedBatch, true); + // ----------------------------------------------------------------------------- + // 6. Test change species + // ----------------------------------------------------------------------------- + esp2Batch.setSpecies(taxon1); + service.changeSpeciesBatchSpecies(esp2Batch.getId(), taxon1); + assertSpeciesBatch(savedBatch, batch, false); + reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp2Batch.getId()); + assertSpeciesBatch(esp2Batch, reloadedBatch, true); - // ----------------------------------------------------------------------------- - // 7. Test get all root species - // ----------------------------------------------------------------------------- - List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperationWithEmptyBatch.getId()); - assertNotNull(rootSpeciesBatch); - assertEquals(2, rootSpeciesBatch.size()); - assertNotNull(rootSpeciesBatch.get(0).getChildBatchs()); - assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0); - assertNotNull(rootSpeciesBatch.get(1).getChildBatchs()); - assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0); + // ----------------------------------------------------------------------------- + // 7. Test get all root species + // ----------------------------------------------------------------------------- + List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperationWithEmptyBatch.getId()); + assertNotNull(rootSpeciesBatch); + assertEquals(2, rootSpeciesBatch.size()); + assertNotNull(rootSpeciesBatch.get(0).getChildBatchs()); + assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0); + assertNotNull(rootSpeciesBatch.get(1).getChildBatchs()); + assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0); - // ----------------------------------------------------------------------------- - // 8. Test batch frequency creation - // ----------------------------------------------------------------------------- + // ----------------------------------------------------------------------------- + // 8. Test batch frequency creation + // ----------------------------------------------------------------------------- - List<SpeciesBatchFrequency> frequencies = Lists.newArrayList(); - float lengthStep = 0.5f; - for (float length = lengthStep; length < lengthStep * 20; length += lengthStep) { - SpeciesBatchFrequency frequency = new SpeciesBatchFrequency(); - frequency.setLengthStep(length); - frequency.setNumber((int) (length * 2)); - frequency.setWeight(0.01f * length * 2); - frequency.setLengthStepCaracteristic(frequencyPMFM); - frequency.setBatch(frequenciesParentBatch); - frequency.setComment("comments"); - frequencies.add(frequency); - } - List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId()); + List<SpeciesBatchFrequency> frequencies = Lists.newArrayList(); + float lengthStep = 0.5f; + for (float length = lengthStep; length < lengthStep * 20; length += lengthStep) { + SpeciesBatchFrequency frequency = new SpeciesBatchFrequency(); + frequency.setLengthStep(length); + frequency.setNumber((int) (length * 2)); + frequency.setWeight(0.01f * length * 2); + frequency.setLengthStepCaracteristic(frequencyPMFM); + frequency.setBatch(frequenciesParentBatch); + frequency.setComment("comments"); + frequencies.add(frequency); + } + List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId()); - // ----------------------------------------------------------------------------- - // 9. Test batch frequency update - // ----------------------------------------------------------------------------- - // Update some batchs (1cm, 2cm, etc) - for (SpeciesBatchFrequency speciesBatchFrequency : createdFrequencies) { - float length = speciesBatchFrequency.getLengthStep(); - if ((float) (int) length == length) { - speciesBatchFrequency.setNumber(12); - speciesBatchFrequency.setComment(null); - } - } - // And remove the last item (should be deleted in DB) - createdFrequencies.remove(createdFrequencies.size() - 1); - List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies); - assertBatchFrequencies(createdFrequencies, savedFrequencies, true); - } + // ----------------------------------------------------------------------------- + // 9. Test batch frequency update + // ----------------------------------------------------------------------------- + // Update some batchs (1cm, 2cm, etc) + for (SpeciesBatchFrequency speciesBatchFrequency : createdFrequencies) { + float length = speciesBatchFrequency.getLengthStep(); + if ((float) (int) length == length) { + speciesBatchFrequency.setNumber(12); + speciesBatchFrequency.setComment(null); + } + } + // And remove the last item (should be deleted in DB) + createdFrequencies.remove(createdFrequencies.size() - 1); + List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies); + assertBatchFrequencies(createdFrequencies, savedFrequencies, true); + } - @Test - public void deleteSpeciesBatch(/* String id */) { - SpeciesBatch esp1Batch; - SpeciesBatch batch; - Species taxon1 = species.get(0); + @Test + public void deleteSpeciesBatch(/* String id */) { + SpeciesBatch esp1Batch; + SpeciesBatch batch; + Species taxon1 = species.get(0); - // ----------------------------------------------------------------------------- - // 1. Create two batchs (parent + child), then remove the parent batch - // ----------------------------------------------------------------------------- - // batch : ESP1 Vrac/5 - batch = new SpeciesBatch(); - batch.setParentBatch(null); - batch.setFishingOperation(fishingOperationWithEmptyBatch); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setSampleCategoryWeight(5f); - assertCreateAndReloadSpeciesBatch(batch, null); - esp1Batch = batch; + // ----------------------------------------------------------------------------- + // 1. Create two batchs (parent + child), then remove the parent batch + // ----------------------------------------------------------------------------- + // batch : ESP1 Vrac/5 + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setFishingOperation(fishingOperationWithEmptyBatch); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setSampleCategoryWeight(5f); + assertCreateAndReloadSpeciesBatch(batch, null); + esp1Batch = batch; - // batch : ESP1 Vrac/5 Male/2 - batch = new SpeciesBatch(); - batch.setParentBatch(esp1Batch); - batch.setFishingOperation(fishingOperationWithEmptyBatch); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(maleQualitativeValue); - batch.setSampleCategoryWeight(2f); - assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId()); + // batch : ESP1 Vrac/5 Male/2 + batch = new SpeciesBatch(); + batch.setParentBatch(esp1Batch); + batch.setFishingOperation(fishingOperationWithEmptyBatch); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(maleQualitativeValue); + batch.setSampleCategoryWeight(2f); + assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId()); - // Try to remove - service.deleteSpeciesBatch(esp1Batch.getId()); + // Try to remove + service.deleteSpeciesBatch(esp1Batch.getId()); - // Check if remove - try { - batch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp1Batch.getId()); - assertNull(batch); - } catch (DataRetrievalFailureException drfe) { - assertNotNull(drfe); - } - } + // Check if remove + try { + batch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp1Batch.getId()); + assertNull(batch); + } catch (DataRetrievalFailureException drfe) { + assertNotNull(drfe); + } + } - protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) { - batch.setFishingOperation(fishingOperationWithEmptyBatch); - // Create batch - SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId); - assertSpeciesBatch(batch, createdBatch, false); + @Test + public void createAndSaveBenthosBatchAndFrequencies() { + SpeciesBatch esp1Batch; + SpeciesBatch esp2Batch; + SpeciesBatch frequenciesParentBatch; + SpeciesBatch batch; + Species taxon1 = species.get(0); + Species taxon2 = species.get(1); - // then reload (for round trip check) - SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), createdBatch.getId()); - if (parentBatchId == null) { - assertNull(reloadedBatch.getParentBatch()); - } else { - assertNotNull(reloadedBatch.getParentBatch()); - assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId()); - } - assertSpeciesBatch(createdBatch, reloadedBatch, false); + // ----------------------------------------------------------------------------- + // 1. Test with only mandatory properties + // ----------------------------------------------------------------------------- + // batch : "ESP1 - Vrac/5" + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setFishingOperation(fishingOperationNoCatchBatch); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setSampleCategoryWeight(5f); - batch.setId(createdBatch.getId()); - } + assertCreateAndReloadBenthosBatch(batch, null); - protected void assertCreateAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) { - CatchBatch createdCatchBatch = service.createCatchBatch(catchBatch); - assertNotNull(createdCatchBatch); - assertNotNull(createdCatchBatch.getId()); - assertCatchBatch(catchBatch, createdCatchBatch, false); + // Save ESP1 batch + esp1Batch = batch; - CatchBatch reloadedCatchBatch = null; - try { - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); - } catch (CatchBatchValidationException e) { - Assert.fail(e.getMessage()); - } - assertCatchBatch(createdCatchBatch, reloadedCatchBatch, true); + // ----------------------------------------------------------------------------- + // 2. Test child "Male/2" + // ----------------------------------------------------------------------------- + // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp1Batch); + batch.setSpecies(taxon1); + batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7"); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(maleQualitativeValue); + batch.setSampleCategoryWeight(2f); + batch.setWeight(1f); + batch.setNumber(7); - catchBatch.setId(createdCatchBatch.getId()); - } + assertCreateAndReloadBenthosBatch(batch, batch.getParentBatch().getId()); - protected void assertSaveAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) { - CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch); - assertNotNull(savedCatchBatch); - assertNotNull(savedCatchBatch.getId()); - assertCatchBatch(catchBatch, savedCatchBatch, false); + // ----------------------------------------------------------------------------- + // 3. Test child "Female/2" + // ----------------------------------------------------------------------------- + // Batch : ESP1 - Vrac/5 Female/3 Nombre/14 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp1Batch); + batch.setSpecies(taxon1); + batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14"); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(femaleQualitativeValue); + batch.setSampleCategoryWeight(3f); + batch.setWeight(null); + batch.setNumber(14); - CatchBatch reloadedCatchBatch = null; - try { - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); - } catch (CatchBatchValidationException e) { - Assert.fail(e.getMessage()); - } - assertCatchBatch(savedCatchBatch, reloadedCatchBatch, true); - } + assertCreateAndReloadBenthosBatch(batch, batch.getParentBatch().getId()); - protected void assertCatchBatch(CatchBatch expectedCatchBatch, CatchBatch actualCatchBatch, boolean assertIdEquals) { - if (expectedCatchBatch == null) { - assertNull(actualCatchBatch); - return; - } + // ----------------------------------------------------------------------------- + // 4. Test : ESP2 - Vrac/7 + // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 + // ----------------------------------------------------------------------------- + // batch : "ESP2 - Vrac/7 " + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setSpecies(taxon2); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setSampleCategoryWeight(7f); - assertNotNull(actualCatchBatch); - if (assertIdEquals) { - assertEquals(expectedCatchBatch.getId(), actualCatchBatch.getId()); - } - assertEquals(expectedCatchBatch.getCatchTotalWeight(), actualCatchBatch.getCatchTotalWeight()); - assertEquals(expectedCatchBatch.getCatchTotalSortedCarousselWeight(), actualCatchBatch.getCatchTotalSortedCarousselWeight()); - assertEquals(expectedCatchBatch.getCatchTotalSortedTremisWeight(), actualCatchBatch.getCatchTotalSortedTremisWeight()); - assertEquals(expectedCatchBatch.getCatchTotalUnsortedWeight(), actualCatchBatch.getCatchTotalUnsortedWeight()); + assertCreateAndReloadBenthosBatch(batch, null); + esp2Batch = batch; - assertEquals(expectedCatchBatch.getSpeciesTotalSampleSortedWeight(), actualCatchBatch.getSpeciesTotalSampleSortedWeight()); - assertEquals(expectedCatchBatch.getSpeciesTotalSortedWeight(), actualCatchBatch.getSpeciesTotalSortedWeight()); - assertEquals(expectedCatchBatch.getSpeciesTotalUnsortedWeight(), actualCatchBatch.getSpeciesTotalUnsortedWeight()); - assertEquals(expectedCatchBatch.getSpeciesTotalInertWeight(), actualCatchBatch.getSpeciesTotalInertWeight()); - assertEquals(expectedCatchBatch.getSpeciesTotalLivingNotItemizedWeight(), actualCatchBatch.getSpeciesTotalLivingNotItemizedWeight()); - } + // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 + batch = new SpeciesBatch(); + batch.setId(null); + batch.setParentBatch(esp2Batch); + batch.setSpecies(taxon2); + batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11"); + batch.setSampleCategoryType(SampleCategoryEnum.maturity); + batch.setSampleCategoryValue(firstMaturityQualitativeValue); + batch.setSampleCategoryWeight(2f); + batch.setWeight(1f); + batch.setNumber(11); - protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { - assertNotNull(actualBatch); - assertNotNull(actualBatch.getId()); - if (assertIdEquals && expectedBatch.getId() != null) { - assertEquals(expectedBatch.getId(), actualBatch.getId()); - } - assertEquals(expectedBatch.getWeight(), actualBatch.getWeight()); - assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType()); - if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { - assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() - + "> but was <null>", - actualBatch.getSampleCategoryValue()); - assertEquals( - ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(), - ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId()); - } else { - assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue()); - } - assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight()); - assertEquals(expectedBatch.getNumber(), actualBatch.getNumber()); - assertEquals(expectedBatch.getComment(), actualBatch.getComment()); + assertCreateAndReloadBenthosBatch(batch, batch.getParentBatch().getId()); - // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method - // (Because getSpeciesBatch(id) could not always retrieve the species) - if (expectedBatch.getSpecies() != null && ( - expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted - || actualBatch.getSpecies() != null)) { - assertNotNull(actualBatch.getSpecies()); - assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); - } - } + // ----------------------------------------------------------------------------- + // 5. Test save after modifications + // ----------------------------------------------------------------------------- + // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99 + batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99"); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(unkQualitativeValue); + batch.setSampleCategoryWeight(1.75f); + batch.setWeight(1.11f); + batch.setFishingOperation(fishingOperationWithEmptyBatch); + batch.setNumber(99); - protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) { + // Save and reload, then check + SpeciesBatch savedBatch = service.saveBenthosBatch(batch); + assertSpeciesBatch(savedBatch, batch, false); + SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), savedBatch.getId()); + assertSpeciesBatch(savedBatch, reloadedBatch, true); - // Create batch - List<SpeciesBatchFrequency> createdFrequencies = service.saveSpeciesBatchFrequency(parentBatchId, frequencies); - assertBatchFrequencies(frequencies, createdFrequencies, false); + // Save batch for later + frequenciesParentBatch = batch; - // then reload (for round trip check) - List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllSpeciesBatchFrequency(parentBatchId); - assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true); + // ----------------------------------------------------------------------------- + // 6. Test change species + // ----------------------------------------------------------------------------- + esp2Batch.setSpecies(taxon1); + service.changeSpeciesBatchSpecies(esp2Batch.getId(), taxon1); + assertSpeciesBatch(savedBatch, batch, false); + reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), esp2Batch.getId()); + assertSpeciesBatch(esp2Batch, reloadedBatch, true); - return createdFrequencies; - } + // ----------------------------------------------------------------------------- + // 7. Test get all root species + // ----------------------------------------------------------------------------- + List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperationWithEmptyBatch.getId()); + assertNotNull(rootSpeciesBatch); + assertEquals(2, rootSpeciesBatch.size()); + assertNotNull(rootSpeciesBatch.get(0).getChildBatchs()); + assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0); + assertNotNull(rootSpeciesBatch.get(1).getChildBatchs()); + assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0); - protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, - boolean assertIdEquals) { - assertNotNull(actualFrequencies); - assertEquals(expectedFrequencies.size(), actualFrequencies.size()); + // ----------------------------------------------------------------------------- + // 8. Test batch frequency creation + // ----------------------------------------------------------------------------- - // Store actual batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); - for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) { - expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - } + List<SpeciesBatchFrequency> frequencies = Lists.newArrayList(); + float lengthStep = 0.5f; + for (float length = lengthStep; length < lengthStep * 20; length += lengthStep) { + SpeciesBatchFrequency frequency = new SpeciesBatchFrequency(); + frequency.setLengthStep(length); + frequency.setNumber((int) (length * 2)); + frequency.setWeight(0.01f * length * 2); + frequency.setLengthStepCaracteristic(frequencyPMFM); + frequency.setBatch(frequenciesParentBatch); + frequency.setComment("comments"); + frequencies.add(frequency); + } + List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId()); - // Store expected batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); - for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) { - assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), - actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); - actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - assertNotNull(speciesBatchFrequency.getId()); - } + // ----------------------------------------------------------------------------- + // 9. Test batch frequency update + // ----------------------------------------------------------------------------- + // Update some batchs (1cm, 2cm, etc) + for (SpeciesBatchFrequency speciesBatchFrequency : createdFrequencies) { + float length = speciesBatchFrequency.getLengthStep(); + if ((float) (int) length == length) { + speciesBatchFrequency.setNumber(12); + speciesBatchFrequency.setComment(null); + } + } + // And remove the last item (should be deleted in DB) + createdFrequencies.remove(createdFrequencies.size() - 1); + List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies); + assertBatchFrequencies(createdFrequencies, savedFrequencies, true); + } - for (Float lengthStep : expectedLengthMap.keySet()) { - SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); - SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); - if (assertIdEquals) { - assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); - } - assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic()); - assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId()); - assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber()); - assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight()); - assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment()); - // assertNotNull(expectedBatchFrequency.getBatch()); - // assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId()); - } - } + @Test + public void deleteBenthosBatch(/* String id */) { + SpeciesBatch esp1Batch; + SpeciesBatch batch; + Species taxon1 = species.get(0); - protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { - return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId)); - } + // ----------------------------------------------------------------------------- + // 1. Create two batchs (parent + child), then remove the parent batch + // ----------------------------------------------------------------------------- + // batch : ESP1 Vrac/5 + batch = new SpeciesBatch(); + batch.setParentBatch(null); + batch.setFishingOperation(fishingOperationWithEmptyBatch); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); + batch.setSampleCategoryValue(vracQualitativeValue); + batch.setSampleCategoryWeight(5f); + assertCreateAndReloadBenthosBatch(batch, null); + esp1Batch = batch; - protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { - if (speciesBatchs == null) { - return null; - } - for (SpeciesBatch speciesBatch : speciesBatchs) { - if (speciesBatchId.equals(speciesBatch.getId())) { - return speciesBatch; - } - if (speciesBatch.getChildBatchs() != null) { - speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs()); - if (speciesBatch != null) { - return speciesBatch; - } - } - } - return null; - } + // batch : ESP1 Vrac/5 Male/2 + batch = new SpeciesBatch(); + batch.setParentBatch(esp1Batch); + batch.setFishingOperation(fishingOperationWithEmptyBatch); + batch.setSpecies(taxon1); + batch.setSampleCategoryType(SampleCategoryEnum.sex); + batch.setSampleCategoryValue(maleQualitativeValue); + batch.setSampleCategoryWeight(2f); + assertCreateAndReloadBenthosBatch(batch, esp1Batch.getId()); + + // Try to remove + service.deleteBenthosBatch(esp1Batch.getId()); + + // Check if remove + try { + batch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), esp1Batch.getId()); + assertNull(batch); + } catch (DataRetrievalFailureException drfe) { + assertNotNull(drfe); + } + } + + protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) { + batch.setFishingOperation(fishingOperationWithEmptyBatch); + + // Create batch + SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId); + assertSpeciesBatch(batch, createdBatch, false); + + // then reload (for round trip check) + SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperationWithEmptyBatch.getId(), createdBatch.getId()); + if (parentBatchId == null) { + assertNull(reloadedBatch.getParentBatch()); + } else { + assertNotNull(reloadedBatch.getParentBatch()); + assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId()); + } + assertSpeciesBatch(createdBatch, reloadedBatch, false); + + batch.setId(createdBatch.getId()); + } + + protected void assertCreateAndReloadBenthosBatch(SpeciesBatch batch, String parentBatchId) { + batch.setFishingOperation(fishingOperationWithEmptyBatch); + + // Create batch + SpeciesBatch createdBatch = service.createBenthosBatch(batch, parentBatchId); + assertSpeciesBatch(batch, createdBatch, false); + + // then reload (for round trip check) + SpeciesBatch reloadedBatch = getBenthosBatch(fishingOperationWithEmptyBatch.getId(), createdBatch.getId()); + if (parentBatchId == null) { + assertNull(reloadedBatch.getParentBatch()); + } else { + assertNotNull(reloadedBatch.getParentBatch()); + assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId()); + } + assertSpeciesBatch(createdBatch, reloadedBatch, false); + + batch.setId(createdBatch.getId()); + } + + protected void assertCreateAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) { + CatchBatch createdCatchBatch = service.createCatchBatch(catchBatch); + assertNotNull(createdCatchBatch); + assertNotNull(createdCatchBatch.getId()); + assertCatchBatch(catchBatch, createdCatchBatch, false); + + CatchBatch reloadedCatchBatch = null; + try { + reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); + } catch (CatchBatchValidationException e) { + Assert.fail(e.getMessage()); + } + assertCatchBatch(createdCatchBatch, reloadedCatchBatch, true); + + catchBatch.setId(createdCatchBatch.getId()); + } + + protected void assertSaveAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) { + CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch); + assertNotNull(savedCatchBatch); + assertNotNull(savedCatchBatch.getId()); + assertCatchBatch(catchBatch, savedCatchBatch, false); + + CatchBatch reloadedCatchBatch = null; + try { + reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); + } catch (CatchBatchValidationException e) { + Assert.fail(e.getMessage()); + } + assertCatchBatch(savedCatchBatch, reloadedCatchBatch, true); + } + + protected void assertCatchBatch(CatchBatch expectedCatchBatch, CatchBatch actualCatchBatch, boolean assertIdEquals) { + if (expectedCatchBatch == null) { + assertNull(actualCatchBatch); + return; + } + + assertNotNull(actualCatchBatch); + if (assertIdEquals) { + assertEquals(expectedCatchBatch.getId(), actualCatchBatch.getId()); + } + assertEquals(expectedCatchBatch.getCatchTotalWeight(), actualCatchBatch.getCatchTotalWeight()); + assertEquals(expectedCatchBatch.getCatchTotalSortedCarousselWeight(), actualCatchBatch.getCatchTotalSortedCarousselWeight()); + assertEquals(expectedCatchBatch.getCatchTotalSortedTremisWeight(), actualCatchBatch.getCatchTotalSortedTremisWeight()); + assertEquals(expectedCatchBatch.getCatchTotalUnsortedWeight(), actualCatchBatch.getCatchTotalUnsortedWeight()); + + assertEquals(expectedCatchBatch.getSpeciesTotalSampleSortedWeight(), actualCatchBatch.getSpeciesTotalSampleSortedWeight()); + assertEquals(expectedCatchBatch.getSpeciesTotalSortedWeight(), actualCatchBatch.getSpeciesTotalSortedWeight()); + assertEquals(expectedCatchBatch.getSpeciesTotalUnsortedWeight(), actualCatchBatch.getSpeciesTotalUnsortedWeight()); + assertEquals(expectedCatchBatch.getSpeciesTotalInertWeight(), actualCatchBatch.getSpeciesTotalInertWeight()); + assertEquals(expectedCatchBatch.getSpeciesTotalLivingNotItemizedWeight(), actualCatchBatch.getSpeciesTotalLivingNotItemizedWeight()); + } + + protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { + assertNotNull(actualBatch); + assertNotNull(actualBatch.getId()); + if (assertIdEquals && expectedBatch.getId() != null) { + assertEquals(expectedBatch.getId(), actualBatch.getId()); + } + assertEquals(expectedBatch.getWeight(), actualBatch.getWeight()); + assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType()); + if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { + assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() + + "> but was <null>", + actualBatch.getSampleCategoryValue()); + assertEquals( + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(), + ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId()); + } else { + assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue()); + } + assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight()); + assertEquals(expectedBatch.getNumber(), actualBatch.getNumber()); + assertEquals(expectedBatch.getComment(), actualBatch.getComment()); + + // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method + // (Because getSpeciesBatch(id) could not always retrieve the species) + if (expectedBatch.getSpecies() != null && ( + expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted + || actualBatch.getSpecies() != null)) { + assertNotNull(actualBatch.getSpecies()); + assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); + } + } + + protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) { + + // Create batch + List<SpeciesBatchFrequency> createdFrequencies = service.saveSpeciesBatchFrequency(parentBatchId, frequencies); + assertBatchFrequencies(frequencies, createdFrequencies, false); + + // then reload (for round trip check) + List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllSpeciesBatchFrequency(parentBatchId); + assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true); + + return createdFrequencies; + } + + protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, + boolean assertIdEquals) { + assertNotNull(actualFrequencies); + assertEquals(expectedFrequencies.size(), actualFrequencies.size()); + + // Store actual batches into a map, using the length as key + Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) { + expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); + } + + // Store expected batches into a map, using the length as key + Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); + for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) { + assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), + actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); + actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); + assertNotNull(speciesBatchFrequency.getId()); + } + + for (Float lengthStep : expectedLengthMap.keySet()) { + SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); + SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); + if (assertIdEquals) { + assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); + } + assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic()); + assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId()); + assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber()); + assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight()); + assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment()); + // assertNotNull(expectedBatchFrequency.getBatch()); + // assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId()); + } + } + + protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { + return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId)); + } + + protected SpeciesBatch getBenthosBatch(String fishingOperationId, String speciesBatchId) { + return getSpeciesBatch(speciesBatchId, service.getAllRootBenthosBatch(fishingOperationId)); + } + + protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { + if (speciesBatchs == null) { + return null; + } + for (SpeciesBatch speciesBatch : speciesBatchs) { + if (speciesBatchId.equals(speciesBatch.getId())) { + return speciesBatch; + } + if (speciesBatch.getChildBatchs() != null) { + speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs()); + if (speciesBatch != null) { + return speciesBatch; + } + } + } + return null; + } } Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceReadTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,61 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -/** - * To test {@link BenthosBatchPersistenceService} for read operation. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class BenthosBatchPersistenceServiceReadTest { - - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.readDb(); - - protected BenthosBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService(); - } - - @Test - public void getAllBenthosBatch(/*String fishingOperationId*/) { - - } - - @Test - public void getBenthosBatch(/*String id*/) { - - } -} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceWriteTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,65 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -/** - * To test {@link BenthosBatchPersistenceService} for write operation. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class BenthosBatchPersistenceServiceWriteTest { - - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.writeDb(); - - protected BenthosBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getBenthosBatchPersistenceService(); - } - - @Test - public void createBenthosBatch(/*BenthosBatch bean*/) { - - } - - @Test - public void saveBenthosBatch(/*BenthosBatch bean*/) { - - } - - @Test - public void deleteBenthosBatch(/*String id*/) { - } -} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceReadTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,58 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -/** - * To test {@link CatchBatchPersistenceService} for read operation. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0 - */ -@Ignore -public class CatchBatchPersistenceServiceReadTest { - - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.readDb(); - - protected CatchBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); - } - - @Test - public void getCatchBatchFromFishingOperation() throws Exception { - - //TODO - } - -} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,204 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * To test {@link CatchBatchPersistenceService} for write operation. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.0 - */ -public class CatchBatchPersistenceServiceWriteTest { - - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.writeDb(); - - protected CatchBatchPersistenceService service; - - protected CruisePersistenceService cruiseService; - - protected FishingOperationPersistenceService fishingOperationService; - - protected ReferentialPersistenceService referentialService; - - protected Cruise cruise; - - protected FishingOperation fishingOperation; - - protected List<Species> species; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); - cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); - cruise.setId(null); - Calendar calendar = new GregorianCalendar(); - cruise.setBeginDate(calendar.getTime()); - cruise.setYear(calendar.get(Calendar.YEAR)); - calendar.add(Calendar.MONTH, 1); // add one month - cruise.setEndDate(calendar.getTime()); - cruise = cruiseService.createCruise(cruise); - - List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); - assertNotNull(fishingOperations); - assertTrue(fishingOperations.size() > 0); - fishingOperation = fishingOperations.get(0); - fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId()); - fishingOperation.setId(null); - fishingOperation.setCruise(cruise); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 1); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingStartDate(calendar.getTime()); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingEndDate(calendar.getTime()); - - fishingOperation = fishingOperationService.createFishingOperation(fishingOperation); - } - - @Test - public void changeSpeciesBatchSpecies() { - //TODO - } - - @Test - public void createAndSaveCatchBatch() throws Exception { - CatchBatch catchBatch; - CatchBatch createdCatchBatch; - CatchBatch reloadedCatchBatch; - - catchBatch = new CatchBatch(); - catchBatch.setFishingOperation(fishingOperation); - - // ----------------------------------------------------------------------------- - // 1. Test with only mandatory properties - // ----------------------------------------------------------------------------- - - // Create and reload (test round trip) - createdCatchBatch = service.createCatchBatch(catchBatch); - assertNotNull(createdCatchBatch); - assertNotNull(createdCatchBatch.getId()); - - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); - assertNotNull(reloadedCatchBatch); - assertEquals(createdCatchBatch.getId(), reloadedCatchBatch.getId()); - - // ----------------------------------------------------------------------------- - // 2. Test with all properties - // ----------------------------------------------------------------------------- - catchBatch.setId(null); - // total weight : 100kg - catchBatch.setCatchTotalWeight(75f); - // Vrac : - { - // note : poids trie par la balance tremis (thalassa) (init par pupitri) - catchBatch.setCatchTotalSortedTremisWeight(50f); - // note : poids vrac caroussel (thalassa) (init par pupitri) (vrac trie) ou bien "poids trié fournie par la table de tri (Sum(Si) - catchBatch.setCatchTotalSortedCarousselWeight(45f); - - // Species - { - catchBatch.setSpeciesTotalSortedWeight(12f); - catchBatch.setSpeciesTotalSampleSortedWeight(8f); - } - } - // Hors Vrac : 10kg - { - catchBatch.setCatchTotalUnsortedWeight(10f); - - // Species - { - catchBatch.setSpeciesTotalUnsortedWeight(10f); - } - } - // Rejet : 15kg - catchBatch.setCatchTotalRejectedWeight(15f); - - // Create and reload (test round trip) - createdCatchBatch = service.createCatchBatch(catchBatch); - assertNotNull(createdCatchBatch); - assertNotNull(createdCatchBatch.getId()); - - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); - assertNotNull(reloadedCatchBatch); - assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight()); - assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight()); - - assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight()); - - // ----------------------------------------------------------------------------- - // 2. Test save after modification - // ----------------------------------------------------------------------------- - catchBatch.setCatchTotalSortedTremisWeight(null); - catchBatch.setCatchTotalSortedCarousselWeight(null); - catchBatch.setSpeciesTotalSortedWeight(null); - catchBatch.setSpeciesTotalSampleSortedWeight(null); - catchBatch.setCatchTotalUnsortedWeight(null); - catchBatch.setSpeciesTotalUnsortedWeight(null); - CatchBatch savedCatchBatch = service.saveCatchBatch(catchBatch); - assertNotNull(savedCatchBatch); - assertNotNull(savedCatchBatch.getId()); - - reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); - assertNotNull(reloadedCatchBatch); - assertEquals(createdCatchBatch.getCatchTotalWeight(), reloadedCatchBatch.getCatchTotalWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedCarousselWeight(), reloadedCatchBatch.getCatchTotalSortedCarousselWeight()); - assertEquals(createdCatchBatch.getCatchTotalSortedTremisWeight(), reloadedCatchBatch.getCatchTotalSortedTremisWeight()); - assertEquals(createdCatchBatch.getCatchTotalUnsortedWeight(), reloadedCatchBatch.getCatchTotalUnsortedWeight()); - - assertEquals(createdCatchBatch.getSpeciesTotalSampleSortedWeight(), reloadedCatchBatch.getSpeciesTotalSampleSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalSortedWeight(), reloadedCatchBatch.getSpeciesTotalSortedWeight()); - assertEquals(createdCatchBatch.getSpeciesTotalUnsortedWeight(), reloadedCatchBatch.getSpeciesTotalUnsortedWeight()); - } - -} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceReadTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,159 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Maps; -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; - -/** - * To test {@link SpeciesBatchPersistenceService} for read operation. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Ignore -public class SpeciesBatchPersistenceServiceReadTest { - - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.readDb(); - - protected SpeciesBatchPersistenceService service; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService(); - } - - @Test - public void getAllRootSpeciesBatch(/*String fishingOperationId*/) { - } - - @Test - public void getAllSpeciesBatchFrequency(/*String speciesBatchId*/) { - - } - - protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { - assertNotNull(actualBatch); - assertNotNull(actualBatch.getId()); - if (assertIdEquals && expectedBatch.getId() != null) { - assertEquals(expectedBatch.getId(), actualBatch.getId()); - } - assertEquals(expectedBatch.getWeight(), actualBatch.getWeight()); - assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType()); - if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { - assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() + "> but was <null>", - actualBatch.getSampleCategoryValue()); - assertEquals( - ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(), - ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId()); - } else { - assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue()); - } - assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight()); - assertEquals(expectedBatch.getNumber(), actualBatch.getNumber()); - assertEquals(expectedBatch.getComment(), actualBatch.getComment()); - - // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method - // (Because getSpeciesBatch(id) could not always retrieve the species) - if (expectedBatch.getSpecies() != null && ( - expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted - || actualBatch.getSpecies() != null)) { - assertNotNull(actualBatch.getSpecies()); - assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); - } - } - - protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) { - assertNotNull(actualFrequencies); - assertEquals(expectedFrequencies.size(), actualFrequencies.size()); - - // Store actual batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); - for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) { - expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - } - - // Store expected batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); - for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) { - assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); - actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - assertNotNull(speciesBatchFrequency.getId()); - } - - for (Float lengthStep : expectedLengthMap.keySet()) { - SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); - SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); - if (assertIdEquals) { - assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); - } - assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic()); - assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId()); - assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber()); - assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight()); - assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment()); - //assertNotNull(expectedBatchFrequency.getBatch()); - //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId()); - } - } - - protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { - return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId)); - } - - protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { - if (speciesBatchs == null) { - return null; - } - for (SpeciesBatch speciesBatch : speciesBatchs) { - if (speciesBatchId.equals(speciesBatch.getId())) { - return speciesBatch; - } - if (speciesBatch.getChildBatchs() != null) { - speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs()); - if (speciesBatch != null) { - return speciesBatch; - } - } - } - return null; - } -} Deleted: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceWriteTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,507 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence API - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import fr.ifremer.tutti.persistence.DatabaseResource; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.dao.DataRetrievalFailureException; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -/** - * To test {@link SpeciesBatchPersistenceService} for write operation. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -public class SpeciesBatchPersistenceServiceWriteTest { - - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.writeDb(); - - protected SpeciesBatchPersistenceService service; - - protected CruisePersistenceService cruiseService; - - protected FishingOperationPersistenceService fishingOperationService; - - protected CatchBatchPersistenceService catchBatchService; - - protected ReferentialPersistenceService referentialService; - - protected Cruise cruise; - - protected FishingOperation fishingOperation; - - protected CatchBatch catchBacth; - - protected List<Species> species; - - protected Caracteristic sortedUnsortedPMFM; - - protected CaracteristicQualitativeValue horsVracQualitativeValue; - - protected CaracteristicQualitativeValue vracQualitativeValue; - - protected Caracteristic maturityPMFM; - - protected CaracteristicQualitativeValue firstMaturityQualitativeValue; - - protected Caracteristic sexPMFM; - - protected CaracteristicQualitativeValue maleQualitativeValue; - - protected CaracteristicQualitativeValue femaleQualitativeValue; - - protected CaracteristicQualitativeValue unkQualitativeValue; - - protected Caracteristic frequencyPMFM; - - protected String speciesBacthId = null; - - @Before - public void setUp() throws Exception { - service = TuttiPersistenceServiceLocator.getSpeciesBatchPersistenceService(); - cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); - - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); - cruise.setId(null); - Calendar calendar = new GregorianCalendar(); - cruise.setBeginDate(calendar.getTime()); - cruise.setYear(calendar.get(Calendar.YEAR)); - calendar.add(Calendar.MONTH, 1); // add one month - cruise.setEndDate(calendar.getTime()); - cruise = cruiseService.createCruise(cruise); - - List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); - assertNotNull(fishingOperations); - assertTrue(fishingOperations.size() > 0); - fishingOperation = fishingOperations.get(0); - fishingOperation = fishingOperationService.getFishingOperation(fishingOperation.getId()); - fishingOperation.setId(null); - fishingOperation.setCruise(cruise); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 1); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingStartDate(calendar.getTime()); - calendar.setTime(new Date()); - calendar.set(Calendar.HOUR_OF_DAY, 10); - calendar.set(Calendar.MILLISECOND, 0); - fishingOperation.setGearShootingEndDate(calendar.getTime()); - - fishingOperation = fishingOperationService.createFishingOperation(fishingOperation); - - catchBacth = new CatchBatch(); - catchBacth.setFishingOperation(fishingOperation); - catchBacth = catchBatchService.createCatchBatch(catchBacth); - - species = referentialService.getAllSpecies(); - assertNotNull(species); - assertTrue(species.size() > 2); - - sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic(); - horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0); - vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1); - maturityPMFM = referentialService.getMaturityCaracteristic(); - firstMaturityQualitativeValue = maturityPMFM.getQualitativeValue(0); - sexPMFM = referentialService.getSexCaracteristic(); - maleQualitativeValue = sexPMFM.getQualitativeValue(1); - femaleQualitativeValue = sexPMFM.getQualitativeValue(2); - unkQualitativeValue = sexPMFM.getQualitativeValue(3); - - - List<Caracteristic> cara = referentialService.getAllCaracteristic(); - for (Caracteristic caracteristic : cara) { - if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER - && caracteristic.getPrecision() != null - && caracteristic.getPrecision() == 0.5f) { - frequencyPMFM = caracteristic; - break; - } - } - assertNotNull("no numerical PMFM with a precision has been found. Could not define a PMFM for batch frequencies.", frequencyPMFM); - } - - @Test - public void createSpeciesBatch(/*SpeciesBatch bean, String parentBatchId*/) { - SpeciesBatch esp1Batch = null; - SpeciesBatch esp2Batch = null; - SpeciesBatch frequenciesParentBatch = null; - SpeciesBatch batch = null; - Species taxon1 = species.get(0); - Species taxon2 = species.get(1); - - // ----------------------------------------------------------------------------- - // 1. Test with only mandatory properties - // ----------------------------------------------------------------------------- - // batch : "ESP1 - Vrac/5" - batch = new SpeciesBatch(); - batch.setParentBatch(null); - batch.setFishingOperation(fishingOperation); - // TODO TC : add link between Speciesbatch and CatchBatch - //batch.setCatchBatch(catchBatch); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setSampleCategoryWeight(5f); - - assertCreateAndReloadSpeciesBatch(batch, null); - - // Save ESP1 batch - esp1Batch = batch; - - // ----------------------------------------------------------------------------- - // 2. Test child "Male/2" - // ----------------------------------------------------------------------------- - // Batch : ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp1Batch); - batch.setSpecies(taxon1); - batch.setComment("ESP1 - Vrac/5 Male/2 ss-ech/1 Nombre/7"); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(maleQualitativeValue); - batch.setSampleCategoryWeight(2f); - batch.setWeight(1f); - batch.setNumber(7); - - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - - // ----------------------------------------------------------------------------- - // 3. Test child "Female/2" - // ----------------------------------------------------------------------------- - // Batch : ESP1 - Vrac/5 Female/3 Nombre/14 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp1Batch); - batch.setSpecies(taxon1); - batch.setComment("ESP1 - Vrac/5 Female/3 Nombre/14"); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(femaleQualitativeValue); - batch.setSampleCategoryWeight(3f); - batch.setWeight(null); - batch.setNumber(14); - - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - - // ----------------------------------------------------------------------------- - // 4. Test : ESP2 - Vrac/7 - // \- ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 - // ----------------------------------------------------------------------------- - // batch : "ESP2 - Vrac/7 " - batch = new SpeciesBatch(); - batch.setParentBatch(null); - // TODO TC : add link between Speciesbatch and CatchBatch - //batch.setCatchBatch(catchBatch); - batch.setSpecies(taxon2); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setSampleCategoryWeight(7f); - - assertCreateAndReloadSpeciesBatch(batch, null); - esp2Batch = batch; - - // Batch : ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11 - batch = new SpeciesBatch(); - batch.setId(null); - batch.setParentBatch(esp2Batch); - batch.setSpecies(taxon2); - batch.setComment("ESP2 - Vrac/7 UNK/2 ss-ech/1 Nombre/11"); - batch.setSampleCategoryType(SampleCategoryEnum.maturity); - batch.setSampleCategoryValue(firstMaturityQualitativeValue); - batch.setSampleCategoryWeight(2f); - batch.setWeight(1f); - batch.setNumber(11); - - assertCreateAndReloadSpeciesBatch(batch, batch.getParentBatch().getId()); - - // ----------------------------------------------------------------------------- - // 5. Test save after modifications - // ----------------------------------------------------------------------------- - // Batch : ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99 - batch.setComment("ESP2 - Vrac/7 UNK/1.75 ss-ech/1.11 Nombre/99"); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(unkQualitativeValue); - batch.setSampleCategoryWeight(1.75f); - batch.setWeight(1.11f); - batch.setFishingOperation(fishingOperation); - batch.setNumber(99); - - // Save and reload, then check - SpeciesBatch savedBatch = service.saveSpeciesBatch(batch); - assertSpeciesBatch(savedBatch, batch, false); - SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), savedBatch.getId()); - assertSpeciesBatch(reloadedBatch, savedBatch, true); - - // Save batch for later - frequenciesParentBatch = batch; - - // ----------------------------------------------------------------------------- - // 6. Test get all root species - // ----------------------------------------------------------------------------- - List<SpeciesBatch> rootSpeciesBatch = service.getAllRootSpeciesBatch(fishingOperation.getId()); - assertNotNull(rootSpeciesBatch); - assertEquals(2, rootSpeciesBatch.size()); - assertNotNull(rootSpeciesBatch.get(0).getChildBatchs()); - assertTrue(rootSpeciesBatch.get(0).getChildBatchs().size() > 0); - assertNotNull(rootSpeciesBatch.get(1).getChildBatchs()); - assertTrue(rootSpeciesBatch.get(1).getChildBatchs().size() > 0); - - // ----------------------------------------------------------------------------- - // 8. Test batch frequency creation - // ----------------------------------------------------------------------------- - - List<SpeciesBatchFrequency> frequencies = Lists.newArrayList(); - float lengthStep = 0.5f; - for (float length = lengthStep; length < lengthStep * 20; length += lengthStep) { - SpeciesBatchFrequency frequency = new SpeciesBatchFrequency(); - frequency.setLengthStep(length); - frequency.setNumber((int) (length * 2)); - frequency.setWeight(0.01f * length * 2); - frequency.setLengthStepCaracteristic(frequencyPMFM); - frequency.setBatch(frequenciesParentBatch); - frequency.setComment("comments"); - frequencies.add(frequency); - } - List<SpeciesBatchFrequency> createdFrequencies = assertCreateAndReloadSpeciesBatchFrequency(frequencies, frequenciesParentBatch.getId()); - - // ----------------------------------------------------------------------------- - // 9. Test batch frequency update - // ----------------------------------------------------------------------------- - // Update some batchs (1cm, 2cm, etc) - for (SpeciesBatchFrequency speciesBatchFrequency : createdFrequencies) { - float length = speciesBatchFrequency.getLengthStep(); - if ((float) (int) length == length) { - speciesBatchFrequency.setNumber(12); - speciesBatchFrequency.setComment(null); - } - } - List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies); - assertBatchFrequencies(createdFrequencies, savedFrequencies, true); - } - - @Test - @Ignore - public void saveSpeciesBatch(/*SpeciesBatch bean*/) { - - } - - @Test - public void deleteSpeciesBatch(/*String id*/) { - SpeciesBatch esp1Batch; - SpeciesBatch childBatch = null; - SpeciesBatch batch; - Species taxon1 = species.get(0); - - // ----------------------------------------------------------------------------- - // 1. Create two batchs (parent + child), then remove the parent batch - // ----------------------------------------------------------------------------- - // batch : ESP1 Vrac/5 - batch = new SpeciesBatch(); - batch.setParentBatch(null); - batch.setFishingOperation(fishingOperation); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sortedUnsorted); - batch.setSampleCategoryValue(vracQualitativeValue); - batch.setSampleCategoryWeight(5f); - assertCreateAndReloadSpeciesBatch(batch, null); - esp1Batch = batch; - - // batch : ESP1 Vrac/5 Male/2 - batch = new SpeciesBatch(); - batch.setParentBatch(esp1Batch); - batch.setFishingOperation(fishingOperation); - batch.setSpecies(taxon1); - batch.setSampleCategoryType(SampleCategoryEnum.sex); - batch.setSampleCategoryValue(maleQualitativeValue); - batch.setSampleCategoryWeight(2f); - assertCreateAndReloadSpeciesBatch(batch, esp1Batch.getId()); - - // Try to remove - service.deleteSpeciesBatch(esp1Batch.getId()); - - // Check if remove - try { - batch = getSpeciesBatch(fishingOperation.getId(), esp1Batch.getId()); - assertNull(batch); - } catch (DataRetrievalFailureException drfe) { - assertNotNull(drfe); - } - } - - @Test - @Ignore - public void deleteSpeciesSubBatch(/*String id*/) { - // Idem deleteSpeciesBatch - } - - protected void assertCreateAndReloadSpeciesBatch(SpeciesBatch batch, String parentBatchId) { - batch.setFishingOperation(fishingOperation); - - // Create batch - SpeciesBatch createdBatch = service.createSpeciesBatch(batch, parentBatchId); - assertSpeciesBatch(batch, createdBatch, false); - - // then reload (for round trip check) - SpeciesBatch reloadedBatch = getSpeciesBatch(fishingOperation.getId(), createdBatch.getId()); - if (parentBatchId == null) { - assertNull(reloadedBatch.getParentBatch()); - } else { - assertNotNull(reloadedBatch.getParentBatch()); - assertEquals(parentBatchId, reloadedBatch.getParentBatch().getId()); - } - assertSpeciesBatch(createdBatch, reloadedBatch, false); - - batch.setId(createdBatch.getId()); - } - - protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { - assertNotNull(actualBatch); - assertNotNull(actualBatch.getId()); - if (assertIdEquals && expectedBatch.getId() != null) { - assertEquals(expectedBatch.getId(), actualBatch.getId()); - } - assertEquals(expectedBatch.getWeight(), actualBatch.getWeight()); - assertEquals(expectedBatch.getSampleCategoryType(), actualBatch.getSampleCategoryType()); - if (expectedBatch.getSampleCategoryValue() != null && expectedBatch.getSampleCategoryValue() instanceof CaracteristicQualitativeValue) { - assertNotNull("Bad sampleCategoryValue : expected <" + ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId() + "> but was <null>", - actualBatch.getSampleCategoryValue()); - assertEquals( - ((CaracteristicQualitativeValue) expectedBatch.getSampleCategoryValue()).getId(), - ((CaracteristicQualitativeValue) actualBatch.getSampleCategoryValue()).getId()); - } else { - assertEquals(expectedBatch.getSampleCategoryValue(), actualBatch.getSampleCategoryValue()); - } - assertEquals(expectedBatch.getSampleCategoryWeight(), actualBatch.getSampleCategoryWeight()); - assertEquals(expectedBatch.getNumber(), actualBatch.getNumber()); - assertEquals(expectedBatch.getComment(), actualBatch.getComment()); - - // Check species only if Vrac/HorsVrac or if batch has been load throw getAllxxx method - // (Because getSpeciesBatch(id) could not always retrieve the species) - if (expectedBatch.getSpecies() != null && ( - expectedBatch.getSampleCategoryType() == SampleCategoryEnum.sortedUnsorted - || actualBatch.getSpecies() != null)) { - assertNotNull(actualBatch.getSpecies()); - assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); - } - } - - protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) { - - // Create batch - List<SpeciesBatchFrequency> createdFrequencies = service.saveSpeciesBatchFrequency(parentBatchId, frequencies); - assertBatchFrequencies(frequencies, createdFrequencies, false); - - // then reload (for round trip check) - List<SpeciesBatchFrequency> reloadedFrequencies = service.getAllSpeciesBatchFrequency(parentBatchId); - assertBatchFrequencies(createdFrequencies, reloadedFrequencies, true); - - return createdFrequencies; - } - - protected void assertBatchFrequencies(List<SpeciesBatchFrequency> expectedFrequencies, List<SpeciesBatchFrequency> actualFrequencies, boolean assertIdEquals) { - assertNotNull(actualFrequencies); - assertEquals(expectedFrequencies.size(), actualFrequencies.size()); - - // Store actual batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> expectedLengthMap = Maps.newHashMap(); - for (SpeciesBatchFrequency speciesBatchFrequency : expectedFrequencies) { - expectedLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - } - - // Store expected batches into a map, using the length as key - Map<Float, SpeciesBatchFrequency> actualLengthMap = Maps.newHashMap(); - for (SpeciesBatchFrequency speciesBatchFrequency : actualFrequencies) { - assertFalse("Duplicate lengthStep found in batchFrequencies, for length=" + speciesBatchFrequency.getLengthStep(), actualLengthMap.containsKey(speciesBatchFrequency.getLengthStep())); - actualLengthMap.put(speciesBatchFrequency.getLengthStep(), speciesBatchFrequency); - assertNotNull(speciesBatchFrequency.getId()); - } - - for (Float lengthStep : expectedLengthMap.keySet()) { - SpeciesBatchFrequency expectedBatchFrequency = expectedLengthMap.get(lengthStep); - SpeciesBatchFrequency actualBatchFrequency = actualLengthMap.get(lengthStep); - if (assertIdEquals) { - assertEquals(expectedBatchFrequency.getId(), actualBatchFrequency.getId()); - } - assertNotNull(expectedBatchFrequency.getLengthStepCaracteristic()); - assertEquals(expectedBatchFrequency.getLengthStepCaracteristic().getId(), actualBatchFrequency.getLengthStepCaracteristic().getId()); - assertEquals(expectedBatchFrequency.getNumber(), actualBatchFrequency.getNumber()); - assertEquals(expectedBatchFrequency.getWeight(), actualBatchFrequency.getWeight()); - assertEquals(expectedBatchFrequency.getComment(), actualBatchFrequency.getComment()); - //assertNotNull(expectedBatchFrequency.getBatch()); - //assertEquals(expectedBatchFrequency.getBatch().getId(), actualBatchFrequency.getBatch().getId()); - } - } - - protected SpeciesBatch getSpeciesBatch(String fishingOperationId, String speciesBatchId) { - return getSpeciesBatch(speciesBatchId, service.getAllRootSpeciesBatch(fishingOperationId)); - } - - protected SpeciesBatch getSpeciesBatch(String speciesBatchId, List<SpeciesBatch> speciesBatchs) { - if (speciesBatchs == null) { - return null; - } - for (SpeciesBatch speciesBatch : speciesBatchs) { - if (speciesBatchId.equals(speciesBatch.getId())) { - return speciesBatch; - } - if (speciesBatch.getChildBatchs() != null) { - speciesBatch = getSpeciesBatch(speciesBatchId, speciesBatch.getChildBatchs()); - if (speciesBatch != null) { - return speciesBatch; - } - } - } - return null; - } -} Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/batch/CatchBatchValidatorReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/batch/CatchBatchValidatorReadTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/batch/CatchBatchValidatorReadTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,23 +1,29 @@ package fr.ifremer.tutti.persistence.service.batch; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +/* + * #%L + * Tutti :: Persistence + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ -import java.util.Collection; -import java.util.List; - -import org.jmock.Expectations; -import org.jmock.Mockery; -import org.jmock.api.Invocation; -import org.jmock.integration.junit4.JUnit4Mockery; -import org.jmock.lib.action.CustomAction; -import org.junit.Assert; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.adagio.core.service.ServiceLocator; @@ -25,98 +31,109 @@ import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.service.BatchPersistenceService; -import fr.ifremer.tutti.persistence.service.CatchBatchPersistenceService; import fr.ifremer.tutti.persistence.service.CruisePersistenceService; import fr.ifremer.tutti.persistence.service.FishingOperationPersistenceService; import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService; import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.api.Invocation; +import org.jmock.integration.junit4.JUnit4Mockery; +import org.jmock.lib.action.CustomAction; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import java.util.List; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + @Ignore public class CatchBatchValidatorReadTest { - @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + @ClassRule + public static final DatabaseResource dbResource = DatabaseResource.writeDb(); - protected BatchPersistenceService service; + protected BatchPersistenceService service; - protected CruisePersistenceService cruiseService; + protected CruisePersistenceService cruiseService; - protected FishingOperationPersistenceService fishingOperationService; + protected FishingOperationPersistenceService fishingOperationService; - protected CatchBatchPersistenceService catchBatchService; + protected ReferentialPersistenceService referentialService; - protected ReferentialPersistenceService referentialService; - - Mockery context ; - + Mockery context; + CatchBatchExtendDao catchBatchExtendDaoMock; String fishingOperationId = null; - + CatchBatchExtendDao catchBatchDao; - @Before - public void setUp() throws Exception { - context = new JUnit4Mockery(); - catchBatchExtendDaoMock = context.mock(CatchBatchExtendDao.class); - catchBatchDao=ServiceLocator.instance().getService("catchBatchDao", CatchBatchExtendDao.class); - - service = TuttiPersistenceServiceLocator.getBatchPersistenceService(); - cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); - fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - catchBatchService = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); - referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - - List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); - assertNotNull(fishingOperations); - assertTrue(fishingOperations.size() > 0); - fishingOperationId = fishingOperations.get(0).getId(); - } + @Before + public void setUp() throws Exception { + context = new JUnit4Mockery(); + catchBatchExtendDaoMock = context.mock(CatchBatchExtendDao.class); + catchBatchDao = ServiceLocator.instance().getService("catchBatchDao", CatchBatchExtendDao.class); - @Test - @Ignore - public void getInvalidCatchBatch() { + service = TuttiPersistenceServiceLocator.getBatchPersistenceService(); + cruiseService = TuttiPersistenceServiceLocator.getCruisePersistenceService(); + fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); + referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - // Full load operation - try { - CatchBatch catchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); - Assert.fail("Historical batch tree must not be valid"); - } catch (CatchBatchValidationException e) { - assertNotNull(e); - } - } - - @Test - @Ignore - public void getInvalidCatchBatchButTryRepair() throws CatchBatchValidationException { + List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); + assertNotNull(fishingOperations); + assertTrue(fishingOperations.size() > 0); + fishingOperationId = fishingOperations.get(0).getId(); + } - // Replace catchBatchDao with a mock : - //service.setCatchBatchDao(catchBatchExtendDaoMock); - - context.checking(new Expectations() {{ - // Assert update() is call once + @Test + @Ignore + public void getInvalidCatchBatch() { + + // Full load operation + try { + CatchBatch catchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); + Assert.fail("Historical batch tree must not be valid"); + } catch (CatchBatchValidationException e) { + assertNotNull(e); + } + } + + @Test + @Ignore + public void getInvalidCatchBatchButTryRepair() throws CatchBatchValidationException { + + // Replace catchBatchDao with a mock : + //service.setCatchBatchDao(catchBatchExtendDaoMock); + + context.checking(new Expectations() {{ + // Assert update() is call once //oneOf (catchBatchExtendDaoMock).update(with(any(fr.ifremer.adagio.core.dao.data.batch.CatchBatch.class))); - + // Delegate other methods to the real DAO - allowing(catchBatchExtendDaoMock); - will(new CustomAction("call delegated catchBatchDao") { - @Override - public Object invoke(Invocation invocation) throws Throwable { - return invocation.applyTo(catchBatchDao); - } - }); - }}); + allowing(catchBatchExtendDaoMock); + will(new CustomAction("call delegated catchBatchDao") { + @Override + public Object invoke(Invocation invocation) throws Throwable { + return invocation.applyTo(catchBatchDao); + } + }); + }}); - CatchBatch catchBatch = null; - try { - catchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId, true/*tryToRepair*/); - assertNotNull(catchBatch); - } catch (CatchBatchValidationException e) { - Assert.fail("Historical batch tree must have been repaired"); - } - context.assertIsSatisfied(); - - // Restore original dao - //service.setCatchBatchDao(catchBatchDao); - } + CatchBatch catchBatch; + try { + catchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId, true/*tryToRepair*/); + assertNotNull(catchBatch); + } catch (CatchBatchValidationException e) { + Assert.fail("Historical batch tree must have been repaired"); + } + context.assertIsSatisfied(); + + // Restore original dao + //service.setCatchBatchDao(catchBatchDao); + } } Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java 2013-02-28 09:08:07 UTC (rev 500) @@ -188,10 +188,10 @@ getLastUpdateDate(TuttiTable.GEAR, internalDb, getSqlDate(2012, 12, 18)); getLastUpdateDate(TuttiTable.LOCATION_CLASSIFICATION, internalDb, getSqlDate(2010, 10, 26)); getLastUpdateDate(TuttiTable.LOCATION_LEVEL, internalDb, getSqlDate(2013, 1, 28)); - getLastUpdateDate(TuttiTable.LOCATION, internalDb, getSqlDate(2013, 1, 29)); + getLastUpdateDate(TuttiTable.LOCATION, internalDb, getSqlDate(2013, 2, 27)); getLastUpdateDate(TuttiTable.TAXONOMIC_LEVEL, internalDb, getSqlDate(2012, 4, 18)); getLastUpdateDate(TuttiTable.REFERENCE_TAXON, internalDb, getSqlDate(2013, 1, 21)); - getLastUpdateDate(TuttiTable.TAXON_NAME, internalDb, getSqlDate(2013, 1, 21)); + getLastUpdateDate(TuttiTable.TAXON_NAME, internalDb, getSqlDate(2013, 2, 26)); getLastUpdateDate(TuttiTable.TAXON_GROUP_TYPE, internalDb, getSqlDate(2012, 5, 24)); getLastUpdateDate(TuttiTable.TAXON_GROUP, internalDb, getSqlDate(2013, 1, 16)); getLastUpdateDate(TuttiTable.ROUND_WEIGHT_CONVERSION, internalDb, getSqlDate(2012, 10, 4)); Added: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/InvalidBatchModelException.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/InvalidBatchModelException.java (rev 0) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/InvalidBatchModelException.java 2013-02-28 09:08:07 UTC (rev 500) @@ -0,0 +1,48 @@ +package fr.ifremer.tutti.service; + +/* + * #%L + * Tutti :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +/** + * Exception when batch model is not compatible with Tutti. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0.2 + */ +public class InvalidBatchModelException extends TuttiBusinessException { + + private static final long serialVersionUID = 1L; + + public InvalidBatchModelException(String message) { + super(message); + } + + public InvalidBatchModelException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidBatchModelException(Throwable cause) { + super(cause); + } +} Property changes on: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/InvalidBatchModelException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-02-28 09:08:07 UTC (rev 500) @@ -24,11 +24,11 @@ * #L% */ +import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.tutti.persistence.TuttiPersistence; import fr.ifremer.tutti.persistence.TuttiPersistenceNoDbImpl; import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfig; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -407,8 +407,14 @@ //------------------------------------------------------------------------// @Override - public CatchBatch getCatchBatchFromFishingOperation(String id) { - return driver.getCatchBatchFromFishingOperation(id); + public CatchBatch getCatchBatchFromFishingOperation(String id, + boolean canRepair) throws InvalidBatchModelException { + try { + return driver.getCatchBatchFromFishingOperation(id, canRepair); + } catch (CatchBatchValidationException e) { + throw new InvalidBatchModelException( + "L'arbre d'échantillonage n'est pas compatible avec Tutti", e); + } } @Override @@ -425,7 +431,6 @@ //-- Species Batch methods --// //------------------------------------------------------------------------// - @Override public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) { return driver.getAllRootSpeciesBatch(fishingOperationId); @@ -473,22 +478,18 @@ //------------------------------------------------------------------------// @Override - public List<BenthosBatch> getAllBenthosBatch(String fishingOperationId) { - return driver.getAllBenthosBatch(fishingOperationId); + public List<SpeciesBatch> getAllRootBenthosBatch(String fishingOperationId) { + return driver.getAllRootBenthosBatch(fishingOperationId); } @Override - public BenthosBatch getBenthosBatch(String id) { - return driver.getBenthosBatch(id); + public SpeciesBatch createBenthosBatch(SpeciesBatch bean, + String parentBatchId) { + return driver.createBenthosBatch(bean, parentBatchId); } @Override - public BenthosBatch createBenthosBatch(BenthosBatch bean) { - return driver.createBenthosBatch(bean); - } - - @Override - public BenthosBatch saveBenthosBatch(BenthosBatch bean) { + public SpeciesBatch saveBenthosBatch(SpeciesBatch bean) { return driver.saveBenthosBatch(bean); } @@ -497,6 +498,27 @@ driver.deleteBenthosBatch(id); } + @Override + public void deleteBenthosSubBatch(String id) { + driver.deleteBenthosSubBatch(id); + } + + @Override + public void changeBenthosBatchSpecies(String batchId, Species species) { + driver.changeBenthosBatchSpecies(batchId, species); + } + + @Override + public List<SpeciesBatchFrequency> getAllBenthosBatchFrequency(String benthosBatchId) { + return driver.getAllBenthosBatchFrequency(benthosBatchId); + } + + @Override + public List<SpeciesBatchFrequency> saveBenthosBatchFrequency(String benthosBatchId, + List<SpeciesBatchFrequency> frequencies) { + return driver.saveBenthosBatchFrequency(benthosBatchId, frequencies); + } + //------------------------------------------------------------------------// //-- Plancton Batch methods --// //------------------------------------------------------------------------// Modified: trunk/tutti-ui-swing/src/main/filtered-resources/log4j.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/log4j.properties 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-ui-swing/src/main/filtered-resources/log4j.properties 2013-02-28 09:08:07 UTC (rev 500) @@ -39,7 +39,7 @@ # tutti levels log4j.logger.fr.ifremer=INFO log4j.logger.fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler=WARN -log4j.logger.fr.ifremer.tutti.ui.swing.util.table=WARN +log4j.logger.fr.ifremer.tutti.ui.swing.util.table=INFO log4j.logger.org.nuiton.util=WARN log4j.logger.org.nuiton.util.ApplicationConfig=INFO log4j.logger.org.nuiton.util.ApplicationConfigHelper=INFO Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-02-28 09:08:07 UTC (rev 500) @@ -25,9 +25,10 @@ */ import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; +import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -39,7 +40,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<BenthosBatch, BenthosBatchRowModel> { +public class BenthosBatchRowModel extends AbstractTuttiBeanUIModel<SpeciesBatch, BenthosBatchRowModel> { private static final long serialVersionUID = 1L; @@ -57,6 +58,15 @@ public static final String PROPERTY_ATTACHMENTS = "attachments"; + public static final String PROPERTY_PARENT_BATCH = "parentBatch"; + + public static final String PROPERTY_CHILD_BATCH = "childBatch"; + + public static final String PROPERTY_BATCH_LEAF = "batchLeaf"; + + public static final String PROPERTY_BATCH_ROOT = "batchRoot"; + + /** * Species observed. * @@ -107,19 +117,35 @@ */ protected List<Attachment> attachments; - protected static final Binder<BenthosBatch, BenthosBatchRowModel> fromBeanBinder = - BinderFactory.newBinder(BenthosBatch.class, + /** + * Parent of this batch (can be null if batch is root). + * + * @see #isBatchRoot() + * @since 0.3 + */ + protected BenthosBatchRowModel parentBatch; + + /** + * List of child batches (can be null or empty if batch is a leaf). + * + * @see #isBatchLeaf() + * @since 0.3 + */ + protected List<BenthosBatchRowModel> childBatch; + + protected static final Binder<SpeciesBatch, BenthosBatchRowModel> fromBeanBinder = + BinderFactory.newBinder(SpeciesBatch.class, BenthosBatchRowModel.class); - protected static final Binder<BenthosBatchRowModel, BenthosBatch> toBeanBinder = + protected static final Binder<BenthosBatchRowModel, SpeciesBatch> toBeanBinder = BinderFactory.newBinder(BenthosBatchRowModel.class, - BenthosBatch.class); + SpeciesBatch.class); public BenthosBatchRowModel() { - super(BenthosBatch.class, fromBeanBinder, toBeanBinder); + super(SpeciesBatch.class, fromBeanBinder, toBeanBinder); } - public BenthosBatchRowModel(BenthosBatch aBatch) { + public BenthosBatchRowModel(SpeciesBatch aBatch) { this(); fromBean(aBatch); } @@ -164,6 +190,40 @@ firePropertyChange(PROPERTY_SAMPLE_WEIGHT, oldValue, sampleWeight); } + //------------------------------------------------------------------------// + //-- Navigation properties --// + //------------------------------------------------------------------------// + + public BenthosBatchRowModel getParentBatch() { + return parentBatch; + } + + public void setParentBatch(BenthosBatchRowModel parentBatch) { + Object oldValue = getParentBatch(); + this.parentBatch = parentBatch; + firePropertyChange(PROPERTY_PARENT_BATCH, oldValue, parentBatch); + firePropertyChange(PROPERTY_BATCH_ROOT, null, isBatchRoot()); + } + + public List<BenthosBatchRowModel> getChildBatch() { + return childBatch; + } + + public void setChildBatch(List<BenthosBatchRowModel> childBatch) { + this.childBatch = childBatch; + // force to propagate child changes + firePropertyChange(PROPERTY_CHILD_BATCH, null, childBatch); + firePropertyChange(PROPERTY_BATCH_LEAF, null, isBatchLeaf()); + } + + public boolean isBatchLeaf() { + return CollectionUtils.isEmpty(childBatch); + } + + public boolean isBatchRoot() { + return parentBatch == null; + } + public Integer getNumber() { return number; } @@ -194,4 +254,5 @@ firePropertyChange(PROPERTY_ATTACHMENTS, oldValue, attachments); } + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-02-28 09:08:07 UTC (rev 500) @@ -27,8 +27,8 @@ import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.Attachment; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.ui.swing.TuttiUI; @@ -93,9 +93,9 @@ rows = Lists.newArrayList(); if (!TuttiEntities.isNew(bean)) { - List<BenthosBatch> catches = - persistenceService.getAllBenthosBatch(bean.getId()); - for (BenthosBatch aBatch : catches) { + List<SpeciesBatch> catches = + persistenceService.getAllRootBenthosBatch(bean.getId()); + for (SpeciesBatch aBatch : catches) { BenthosBatchRowModel entry = new BenthosBatchRowModel(aBatch); rows.add(entry); @@ -157,7 +157,7 @@ // row is not valid can not save it - BenthosBatch catchBean = row.toBean(); + SpeciesBatch catchBean = row.toBean(); if (!TuttiEntities.isNew(catchBean)) { @@ -304,7 +304,7 @@ protected void saveRow(BenthosBatchRowModel row) { - BenthosBatch catchBean = row.toBean(); + SpeciesBatch catchBean = row.toBean(); FishingOperation fishingOperation = getModel().getFishingOperation(); catchBean.setFishingOperation(fishingOperation); @@ -314,7 +314,18 @@ if (TuttiEntities.isNew(catchBean)) { - catchBean = persistenceService.createBenthosBatch(catchBean); + BenthosBatchRowModel batchParent = row.getParentBatch(); + String parentBatchId = null; + + if (batchParent != null) { + parentBatchId = batchParent.getId(); + } + + if (log.isInfoEnabled()) { + log.info("Persist new benthos batch with parentId: " + + parentBatchId); + } + catchBean = persistenceService.createBenthosBatch(catchBean, parentBatchId); row.setId(catchBean.getId()); } else { persistenceService.saveBenthosBatch(catchBean); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java 2013-02-28 09:08:07 UTC (rev 500) @@ -1,5 +1,29 @@ package fr.ifremer.tutti.ui.swing.util.table; +/* + * #%L + * Tutti :: UI + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + import org.jdesktop.swingx.decorator.ComponentAdapter; import org.jdesktop.swingx.decorator.HighlightPredicate; Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java ___________________________________________________________________ Modified: svn:keywords - Author Date Id Revision + Author Date Id Revision HeadURL Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-02-28 09:03:00 UTC (rev 499) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-02-28 09:08:07 UTC (rev 500) @@ -543,9 +543,9 @@ tutti.validator.error.fishingOperation.trawlDistance.tooLong=La distance du trait dépasse 3 milles marin (5556 m), merci de vérifier les coordonnées tutti.validator.error.fishingOperation.trawlNetNumber.required=Le numéro de poche est obligatoire tutti.validator.error.fishingOperation.vessel.required=Le navire est obligatoire +tutti.validator.error.program.comment.required=Le commentaire de la série est obligatoire tutti.validator.error.program.existingKey=Le couple nom/zone existe déjà tutti.validator.error.program.name.required=Le nom de la série est obligatoire -tutti.validator.error.program.comment.required=Le commentaire de la série est obligatoire tutti.validator.error.program.zone.required=La zone de la série est obligatoire tutti.validator.error.protocol.name.alreadyUsed=Le nom du protocol est déjà utilisé tutti.validator.error.protocol.name.required=Le nom du protocol est obligatoire
participants (1)
-
tchemit@users.forge.codelutin.com