Author: tchemit Date: 2013-04-03 17:14:47 +0200 (Wed, 03 Apr 2013) New Revision: 720 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/720 Log: fixes #2068: [REFERENTIEL] Cr?\195?\169ation d'un nouveau pmfm pour la s?\195?\169rie partielle d'une campagne (SURVEY_PART) fixes #2228: [REFERENTIEL] Cr?\195?\169er le pmfm Vivant non tri?\195?\169 / Inerte / Vivant refs #1865: [MACRODECHET] - Gestion de la saisie des Macrod?\195?\169chets (sauvegarde du catchBatch) refs #2227: [CAPTURE] Revoir la structure de l'arbre d'?\195?\169chantillonage (normalement ok, a bien tester) Added: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceCopyTest.java trunk/tutti-persistence/src/test/resources/tutti-test-read-dbEmpty.properties trunk/tutti-persistence/src/test/resources/tutti-test-write-dbEmpty.properties Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.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/batch/BatchPersistenceHelper.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.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/ReferentialPersistenceServiceReadTest.java 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/ReferentialSynchronizeServiceImplTest.java trunk/tutti-persistence/src/test/server.properties Modified: 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-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-03 15:14:47 UTC (rev 720) @@ -89,7 +89,9 @@ // Vrac / Benthos SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatchChils, "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS, + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED + ); BatchContainer<SpeciesBatch> result = new BatchContainer<SpeciesBatch>(); result.setId(vracSpeciesBatch.getId()); @@ -97,17 +99,11 @@ 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 = TuttiBeanFactory.newSpeciesBatch(); - batchHelper.entityToSpeciesBatch(source, target); - result.addChildren(target); - if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); - } + SpeciesBatch target = TuttiBeanFactory.newSpeciesBatch(); + batchHelper.entityToSpeciesBatch(source, target); + result.addChildren(target); + if (log.isInfoEnabled()) { + log.info("Loaded CatchBatch Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-04-03 15:14:47 UTC (rev 720) @@ -38,7 +38,6 @@ import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement; import fr.ifremer.adagio.core.dao.data.operation.FishingOperationImpl; import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl; -import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl; import fr.ifremer.adagio.core.dao.technical.synchronization.SynchronizationStatus; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.CatchBatchBean; @@ -99,7 +98,7 @@ Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId)); Preconditions.checkNotNull(catchBatchId); - // wenever want to repair anything from Tutti + // whenever want to repair anything from Tutti fr.ifremer.adagio.core.dao.data.batch.CatchBatch source = catchBatchDao.loadFullTree(catchBatchId, true, false); CatchBatch result = new CatchBatchBean(); @@ -111,8 +110,11 @@ } // Vrac - SortingBatch vracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID); + SortingBatch vracBatch = catchBatchDao.getSortingBatch( + source.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_VRAC_ID); if (log.isInfoEnabled()) { log.info("Loaded CatchBatch Vrac: " + vracBatch.getId()); } @@ -120,41 +122,55 @@ result.setCatchTotalSortedTremisWeight(vracBatch.getWeightBeforeSampling()); { // Vrac > Species - SortingBatch speciesBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + SortingBatch speciesBatch = catchBatchDao.getSortingBatch( + vracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Vrac > Species : " + speciesBatch.getId()); + log.info("Loaded CatchBatch Vrac > Species: " + speciesBatch.getId()); } result.setSpeciesTotalSortedWeight(speciesBatch.getWeight()); { // Vrac > Species > Inert - SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); + SortingBatch inertBatch = catchBatchDao.getSortingBatch( + speciesBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT); - if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Vrac > Species > Inert: " + inertBatch.getId()); - } + if (inertBatch != null) { + if (log.isInfoEnabled()) { + log.info("Loaded CatchBatch Vrac > Species > Inert: " + inertBatch.getId()); + } result.setSpeciesTotalInertWeight(inertBatch.getWeight()); } - // Vrac > Species > Alive no itemized - SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); - if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Vrac > Species > Alive not itemized: " + livingNotItemizedBatch.getId()); - } + // Vrac > Species > Alive not itemized + SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch( + speciesBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED); + if (livingNotItemizedBatch != null) { + if (log.isInfoEnabled()) { + log.info("Loaded CatchBatch Vrac > Species > Alive not itemized: " + livingNotItemizedBatch.getId()); + } result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); } } // Vrac > Benthos - SortingBatch benthosBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + SortingBatch benthosBatch = catchBatchDao.getSortingBatch( + vracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); if (log.isInfoEnabled()) { log.info("Loaded CatchBatch Vrac > Benthos: " + benthosBatch.getId()); @@ -164,22 +180,30 @@ { // Vrac > Benthos > Inert - SortingBatch inertBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); - if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Vrac > Benthos > Inert: " + inertBatch.getId()); - } + SortingBatch inertBatch = catchBatchDao.getSortingBatch( + benthosBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT); + if (inertBatch != null) { + if (log.isInfoEnabled()) { + log.info("Loaded CatchBatch Vrac > Benthos > Inert: " + inertBatch.getId()); + } result.setBenthosTotalInertWeight(inertBatch.getWeight()); } // Vrac > Benthos > Alive no itemized - SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); - if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Vrac > Benthos > Alive not itemized: " + livingNotItemizedBatch.getId()); - } + SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch( + benthosBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED); + if (livingNotItemizedBatch != null) { + if (log.isInfoEnabled()) { + log.info("Loaded CatchBatch Vrac > Benthos > Alive not itemized: " + livingNotItemizedBatch.getId()); + } result.setBenthosTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); } } @@ -188,16 +212,22 @@ } // Hors Vrac - SortingBatch horsVracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID); + SortingBatch horsVracBatch = catchBatchDao.getSortingBatch( + source.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_HORS_VRAC_ID); if (horsVracBatch != null) { if (log.isInfoEnabled()) { log.info("Loaded CatchBatch Hors Vrac: " + horsVracBatch.getId()); } { // Hors Vrac > Species - SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + SortingBatch speciesBatch = catchBatchDao.getSortingBatch( + horsVracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (speciesBatch != null) { if (log.isInfoEnabled()) { @@ -206,8 +236,11 @@ } // Hors Vrac > Benthos - SortingBatch benthosBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + SortingBatch benthosBatch = catchBatchDao.getSortingBatch( + horsVracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); if (benthosBatch != null) { @@ -217,14 +250,19 @@ } // Hors Vrac > MarineLitter - SortingBatch marineLitterBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); + SortingBatch marineLitterBatch = catchBatchDao.getSortingBatch( + horsVracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); if (marineLitterBatch != null) { if (log.isInfoEnabled()) { log.info("Loaded CatchBatch Hors Vrac> MarineLitter: " + marineLitterBatch.getId()); } + + result.setMarineLitterTotalWeight(marineLitterBatch.getWeight()); } // TODO : Plancton... @@ -232,12 +270,16 @@ } // Non trié - SortingBatch unsortedBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID); - if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Unsorted: " + unsortedBatch.getId()); - } + SortingBatch unsortedBatch = catchBatchDao.getSortingBatch( + source.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_UNSORTED_ID); + if (unsortedBatch != null) { + if (log.isInfoEnabled()) { + log.info("Loaded CatchBatch Unsorted: " + unsortedBatch.getId()); + } result.setCatchTotalRejectedWeight(unsortedBatch.getWeight()); } @@ -348,9 +390,14 @@ target.getChildBatchs().add(batch); } //FIXME-TC what is the point catchTotalSortedCarousselWeight and catchTotalSortedTremisWeight ? - beanToEntitySortingBatch(target, target, batch, recorderDepartmentId, - enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, - source.getCatchTotalSortedCarousselWeight(), source.getCatchTotalSortedTremisWeight()); + beanToEntitySortingBatch(target, + target, + batch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_VRAC_ID, + source.getCatchTotalSortedCarousselWeight(), + source.getCatchTotalSortedTremisWeight()); batch.setRankOrder((short) 1); // Manage childs : @@ -364,14 +411,19 @@ // ----------------------------------------------------------------------------- // Vrac / Species // ----------------------------------------------------------------------------- + SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (speciesBatch == null) { speciesBatch = SortingBatch.Factory.newInstance(); batch.getChildBatchs().add(speciesBatch); } - beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, + beanToEntitySortingBatch(target, + batch, + speciesBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, source.getSpeciesTotalSortedWeight(), null); speciesBatch.setRankOrder((short) 1); @@ -380,38 +432,68 @@ if (speciesBatch.getChildBatchs() == null) { speciesBatch.setChildBatchs(Lists.<Batch>newArrayList()); } + + Map<Integer, SortingBatch> speciesBatchChilds = getChildsMap(speciesBatch, enumeration.PMFM_ID_SORTING_TYPE_2); + // ----------------------------------------------------------------------------- // Vrac / Species / Alive not itemized // ----------------------------------------------------------------------------- - SortingBatch aliveNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); + SortingBatch aliveNotItemizedBatch = speciesBatchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED); if (aliveNotItemizedBatch == null) { aliveNotItemizedBatch = SortingBatch.Factory.newInstance(); speciesBatch.getChildBatchs().add(aliveNotItemizedBatch); } - //TODO beanToEntitySortingBatch avec nouveau psfm - beanToEntityReferenceTaxonBatch(target, speciesBatch, aliveNotItemizedBatch, recorderDepartmentId, - enumeration.REFERENCE_TAXON_ID_LIFE, - source.getSpeciesTotalLivingNotItemizedWeight(), null); + beanToEntitySortingBatch(target, + speciesBatch, + aliveNotItemizedBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED, + source.getSpeciesTotalLivingNotItemizedWeight(), + null); aliveNotItemizedBatch.setRankOrder((short) 1); // ----------------------------------------------------------------------------- // Vrac / Species / Inert (not alive) // ----------------------------------------------------------------------------- - SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); + + SortingBatch inertBatch = speciesBatchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT); if (inertBatch == null) { inertBatch = SortingBatch.Factory.newInstance(); speciesBatch.getChildBatchs().add(inertBatch); } - //TODO beanToEntitySortingBatch avec nouveau psfm - beanToEntityReferenceTaxonBatch(target, speciesBatch, inertBatch, recorderDepartmentId, - enumeration.REFERENCE_TAXON_ID_INERT, - source.getSpeciesTotalInertWeight(), - null); + + beanToEntitySortingBatch(target, + speciesBatch, + inertBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT, + source.getSpeciesTotalInertWeight(), + null); inertBatch.setRankOrder((short) 2); - // TODO Créer le noeud Vivant trié + // ----------------------------------------------------------------------------- + // Vrac / Species / Alive itemized + // ----------------------------------------------------------------------------- + + SortingBatch aliveItemizedBatch = speciesBatchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED); + if (aliveItemizedBatch == null) { + aliveItemizedBatch = SortingBatch.Factory.newInstance(); + speciesBatch.getChildBatchs().add(aliveItemizedBatch); + } + + beanToEntitySortingBatch(target, + speciesBatch, + aliveItemizedBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED, + null, + null); + aliveItemizedBatch.setRankOrder((short) 3); } // ----------------------------------------------------------------------------- @@ -419,12 +501,17 @@ // ----------------------------------------------------------------------------- SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + if (benthosBatch == null) { benthosBatch = SortingBatch.Factory.newInstance(); batch.getChildBatchs().add(benthosBatch); } - beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS, + beanToEntitySortingBatch(target, + batch, + benthosBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS, source.getBenthosTotalSortedWeight(), null); benthosBatch.setRankOrder((short) 2); @@ -435,38 +522,70 @@ benthosBatch.setChildBatchs(Lists.<Batch>newArrayList()); } + Map<Integer, SortingBatch> benthosBatchChilds = getChildsMap(benthosBatch, enumeration.PMFM_ID_SORTING_TYPE_2); + // ----------------------------------------------------------------------------- // Vrac / Benthos / Alive not itemized // ----------------------------------------------------------------------------- - SortingBatch aliveNotItemizedBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); + SortingBatch aliveNotItemizedBatch = benthosBatchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED); if (aliveNotItemizedBatch == null) { aliveNotItemizedBatch = SortingBatch.Factory.newInstance(); benthosBatch.getChildBatchs().add(aliveNotItemizedBatch); } - beanToEntityReferenceTaxonBatch(target, benthosBatch, aliveNotItemizedBatch, recorderDepartmentId, - enumeration.REFERENCE_TAXON_ID_LIFE, - source.getBenthosTotalLivingNotItemizedWeight(), - null); + + beanToEntitySortingBatch(target, + benthosBatch, + aliveNotItemizedBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED, + source.getBenthosTotalLivingNotItemizedWeight(), + null); aliveNotItemizedBatch.setRankOrder((short) 1); // ----------------------------------------------------------------------------- - // Vrac / Species / Inert (not alive) + // Vrac / Benthos / Inert (not alive) // ----------------------------------------------------------------------------- - SortingBatch inertBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); + SortingBatch inertBatch = benthosBatchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT); if (inertBatch == null) { inertBatch = SortingBatch.Factory.newInstance(); benthosBatch.getChildBatchs().add(inertBatch); } - beanToEntityReferenceTaxonBatch(target, benthosBatch, inertBatch, recorderDepartmentId, - enumeration.REFERENCE_TAXON_ID_INERT, - source.getBenthosTotalInertWeight(), - null); + + beanToEntitySortingBatch(target, + benthosBatch, + inertBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT, + source.getBenthosTotalInertWeight(), + null); inertBatch.setRankOrder((short) 2); + + // ----------------------------------------------------------------------------- + // Vrac / Benthos / Alive itemized + // ----------------------------------------------------------------------------- + + SortingBatch aliveItemizedBatch = benthosBatchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED); + if (aliveItemizedBatch == null) { + aliveItemizedBatch = SortingBatch.Factory.newInstance(); + benthosBatch.getChildBatchs().add(aliveItemizedBatch); + } + + beanToEntitySortingBatch(target, + benthosBatch, + aliveItemizedBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED, + null, + null); + aliveItemizedBatch.setRankOrder((short) 3); } - // TODO plancton, macro déchet... + // TODO plancton } } @@ -479,8 +598,12 @@ batch = SortingBatch.Factory.newInstance(); target.getChildBatchs().add(batch); } - beanToEntitySortingBatch(target, target, batch, recorderDepartmentId, - enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, + beanToEntitySortingBatch(target, + target, + batch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_HORS_VRAC_ID, null, null); batch.setRankOrder((short) 2); @@ -490,7 +613,7 @@ Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE); // ----------------------------------------------------------------------------- - // Hors Vrac > Species : + // Hors Vrac > Species // ----------------------------------------------------------------------------- { SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); @@ -502,15 +625,19 @@ batch.getChildBatchs().add(speciesBatch); } } - beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, + beanToEntitySortingBatch(target, + batch, + speciesBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, null, null); speciesBatch.setRankOrder((short) 1); } // ----------------------------------------------------------------------------- - // Hors Vrac > Benthos : + // Hors Vrac > Benthos // ----------------------------------------------------------------------------- { SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); @@ -518,14 +645,38 @@ benthosBatch = SortingBatch.Factory.newInstance(); batch.getChildBatchs().add(benthosBatch); } - beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS, + beanToEntitySortingBatch(target, + batch, + benthosBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS, null, null); benthosBatch.setRankOrder((short) 2); } - // TODO : plancton, macro déchet... + // ----------------------------------------------------------------------------- + // Hors Vrac > MarineLitter + // ----------------------------------------------------------------------------- + { + SortingBatch marineLitterBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); + if (marineLitterBatch == null) { + marineLitterBatch = SortingBatch.Factory.newInstance(); + batch.getChildBatchs().add(marineLitterBatch); + } + beanToEntitySortingBatch(target, + batch, + marineLitterBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER, + source.getMarineLitterTotalWeight(), + null); + marineLitterBatch.setRankOrder((short) 3); + } + + // TODO : plancton } } @@ -539,8 +690,12 @@ unsortedBatch = SortingBatch.Factory.newInstance(); target.getChildBatchs().add(unsortedBatch); } - beanToEntitySortingBatch(target, target, unsortedBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID, + beanToEntitySortingBatch(target, + target, + unsortedBatch, + recorderDepartmentId, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_UNSORTED_ID, source.getCatchTotalRejectedWeight(), null); unsortedBatch.setRankOrder((short) 3); @@ -564,8 +719,8 @@ protected void beanToEntitySortingBatch( fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, - fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch, - fr.ifremer.adagio.core.dao.data.batch.SortingBatch target, + Batch parentBatch, + SortingBatch target, Integer recorderDepartmentId, Integer sortingPmfmId, Integer sortingQualitativeValueId, @@ -586,7 +741,8 @@ } // Some mandatory properties : - target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); + QualityFlagImpl qualityFlag = load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED); + target.setQualityFlag(qualityFlag); target.setRootBatch(rootBatch); target.setParentBatch(parentBatch); target.setExhaustiveInventory(true); @@ -636,71 +792,71 @@ } } - protected void beanToEntityReferenceTaxonBatch( - fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, - fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch, - fr.ifremer.adagio.core.dao.data.batch.SortingBatch target, - Integer recorderDepartmentId, - Integer referenceTaxonId, - Float weight, - Float sampleWeight) { +// protected void beanToEntityReferenceTaxonBatch( +// fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, +// Batch parentBatch, +// SortingBatch target, +// Integer recorderDepartmentId, +// Integer referenceTaxonId, +// Float weight, +// Float sampleWeight) { +// +// Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements(); +// Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); +// +// // Create lists to store all updates, then remove not updated items +// Set<QuantificationMeasurement> notChangedQuantificationMeasurements = Sets.newHashSet(); +// if (quantificationMeasurements != null) { +// notChangedQuantificationMeasurements.addAll(quantificationMeasurements); +// } +// Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); +// if (sortingMeasurements != null) { +// notChangedSortingMeasurements.addAll(sortingMeasurements); +// } +// +// // Some mandatory properties : +// target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); +// target.setRootBatch(rootBatch); +// target.setParentBatch(parentBatch); +// target.setExhaustiveInventory(true); +// +// // Reference taxon +// target.setReferenceTaxon(load(ReferenceTaxonImpl.class, referenceTaxonId)); +// target.setTaxonGroup(null); +// +// // Sampling Ratio +// if ((sampleWeight == null || weight == null)) { +// target.setSamplingRatio(null); +// target.setSamplingRatioText(null); +// } else { +// String samplingRatioText = weight + "/" + sampleWeight; +// samplingRatioText = samplingRatioText.replaceAll(",", "."); +// target.setSamplingRatioText(samplingRatioText); +// target.setSamplingRatio(weight / sampleWeight); +// } +// +// // Weight +// if ((sampleWeight == null && weight == null)) { +// // Nothing to do : will be removed later, using notChangedQuantificationMeasurements +// } else { +// Float batchReferenceWeight = weight; +// if (batchReferenceWeight == null) { +// batchReferenceWeight = sampleWeight; +// } +// QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, +// enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); +// notChangedQuantificationMeasurements.remove(quantificationMeasurement); +// } +// +// // Removed not changed measurements (in sorting and quantification measurement lists) +// if (quantificationMeasurements != null) { +// quantificationMeasurements.removeAll(notChangedQuantificationMeasurements); +// } +// if (sortingMeasurements != null) { +// sortingMeasurements.removeAll(notChangedSortingMeasurements); +// } +// } - Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements(); - Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); - - // Create lists to store all updates, then remove not updated items - Set<QuantificationMeasurement> notChangedQuantificationMeasurements = Sets.newHashSet(); - if (quantificationMeasurements != null) { - notChangedQuantificationMeasurements.addAll(quantificationMeasurements); - } - Set<SortingMeasurement> notChangedSortingMeasurements = Sets.newHashSet(); - if (sortingMeasurements != null) { - notChangedSortingMeasurements.addAll(sortingMeasurements); - } - - // Some mandatory properties : - target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); - target.setRootBatch(rootBatch); - target.setParentBatch(parentBatch); - target.setExhaustiveInventory(true); - - // Reference taxon - target.setReferenceTaxon(load(ReferenceTaxonImpl.class, referenceTaxonId)); - target.setTaxonGroup(null); - - // Sampling Ratio - if ((sampleWeight == null || weight == null)) { - target.setSamplingRatio(null); - target.setSamplingRatioText(null); - } else { - String samplingRatioText = weight + "/" + sampleWeight; - samplingRatioText = samplingRatioText.replaceAll(",", "."); - target.setSamplingRatioText(samplingRatioText); - target.setSamplingRatio(weight / sampleWeight); - } - - // Weight - if ((sampleWeight == null && weight == null)) { - // Nothing to do : will be removed later, using notChangedQuantificationMeasurements - } else { - Float batchReferenceWeight = weight; - if (batchReferenceWeight == null) { - batchReferenceWeight = sampleWeight; - } - QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } - - // Removed not changed measurements (in sorting and quantification measurement lists) - if (quantificationMeasurements != null) { - quantificationMeasurements.removeAll(notChangedQuantificationMeasurements); - } - if (sortingMeasurements != null) { - sortingMeasurements.removeAll(notChangedSortingMeasurements); - } - } - protected Integer getRecorderDepartmentId() { // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?) return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT; Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java 2013-04-03 15:14:47 UTC (rev 720) @@ -74,13 +74,13 @@ @Resource(name = "batchPersistenceHelper") protected BatchPersistenceHelper batchHelper; - Integer marineLitterCategory; + protected Integer marineLitterCategory; - Integer marineLitterSizeCategory; + protected Integer marineLitterSizeCategory; - Map<Integer, CaracteristicQualitativeValue> marineLitterCategoryCaracteristicValues; + protected Map<Integer, CaracteristicQualitativeValue> marineLitterCategoryCaracteristicValues; - Map<Integer, CaracteristicQualitativeValue> marineLitterSizeCategoryCaracteristicValues; + protected Map<Integer, CaracteristicQualitativeValue> marineLitterSizeCategoryCaracteristicValues; @Override public void init() { @@ -111,12 +111,15 @@ // Vrac / Marine Litter SortingBatch vracMarineLitterBatch = catchBatchDao.getSortingBatch( catchBatchChilds, - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_HORS_VRAC_ID, + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); - // container of speciesBatch is arbitraty put on vrac type (there is - // no common ancestor for all species batch). BatchContainer<MarineLitterBatch> result = new BatchContainer<>(); + result.setId(vracMarineLitterBatch.getId()); for (Batch batch1 : vracMarineLitterBatch.getChildBatchs()) { @@ -143,8 +146,8 @@ Preconditions.checkArgument(bean.getId() == null); Preconditions.checkNotNull(bean.getMarineLitterCategory()); Preconditions.checkNotNull(bean.getMarineLitterSizeCategory()); - Preconditions.checkNotNull(bean.getWeight()); // Preconditions.checkNotNull(bean.getNumber()); +// Preconditions.checkNotNull(bean.getWeight()); getCurrentSession().setFlushMode(FlushMode.COMMIT); @@ -253,7 +256,6 @@ notChangedSortingMeasurements.addAll(sortingMeasurements); } - // If parent and root need to be set if (target.getId() == null || target.getRootBatch() == null) { setBatchParents(source, target, catchBatch); @@ -272,6 +274,7 @@ // Force subgroup count to '1', as Allegro target.setSubgroupCount(1f); + //FIXME-TC Do we really need this ? // Weight if (source.getWeight() == null) { // Nothing to do : will be removed later, using notChangedSortingMeasurements @@ -298,7 +301,7 @@ notChangedQuantificationMeasurements.remove(quantificationMeasurement); } - // MarineLitterCategory + // MarineLitterSizeCategory if (source.getMarineLitterSizeCategory() == null) { // Nothing to do : will be removed later, using notChangedQuantificationMeasurements } else { @@ -312,12 +315,15 @@ } // Sampling Ratio - target.setSamplingRatio(null); + target.setSamplingRatio(1.0f); target.setSamplingRatioText(null); // Individual count target.setIndividualCount(source.getNumber()); + // Weight + target.setWeight(source.getWeight()); + // QualityFlag String qualityFlag; qualityFlag = enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED; @@ -326,7 +332,7 @@ // Comments target.setComments(source.getComment()); - // Exhaustive inventory (always true under a species batch) + // Exhaustive inventory (always true under a marine litter batch) target.setExhaustiveInventory(true); // Removed not changed measurements (in sorting and quantification measurement lists) @@ -348,16 +354,17 @@ Preconditions.checkNotNull(source.getFishingOperation().getId()); // Load existing parent and root - SortingBatch parentBatch; + SortingBatch parentBatch = catchBatchDao.getSortingBatch( + catchBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); - parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); - // Parent Batch if (parentBatch == null) { throw new DataIntegrityViolationException( - "Could not retrieve parent batch, for a given speciesBatch : invalid batch tree structure. Please make sure CatchBatch has been saved before to create a SpeciesBatch."); + "Could not retrieve parent batch, for a given marineLitterBatch : invalid batch tree structure. Please make sure CatchBatch has been saved before to create a MarineLitterBatch."); } // Parent Batch Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-03 15:14:47 UTC (rev 720) @@ -85,7 +85,9 @@ // Vrac / Species SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatchChilds, "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED + ); // container of speciesBatch is arbitraty put on vrac type (there is // no common ancestor for all species batch). @@ -95,18 +97,12 @@ 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 = TuttiBeanFactory.newSpeciesBatch(); + batchHelper.entityToSpeciesBatch(source, target); + result.addChildren(target); - SpeciesBatch target = TuttiBeanFactory.newSpeciesBatch(); - batchHelper.entityToSpeciesBatch(source, target); - result.addChildren(target); - - if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); - } + if (log.isInfoEnabled()) { + log.info("Loaded CatchBatch Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } } 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-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-04-03 15:14:47 UTC (rev 720) @@ -107,6 +107,9 @@ @Value("${PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE}") public final Integer PMFM_ID_SORTING_TYPE = null; + @Value("${PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE_2}") + public final Integer PMFM_ID_SORTING_TYPE_2 = null; + @Value("${UnitId.NONE}") public final Integer UNIT_ID_NONE = null; @@ -162,8 +165,17 @@ public final Integer QUALITATIVE_ID_SORTING_TYPE_BENTHOS = null; @Value("${QualitativeValueId.SORTING_TYPE_MARINE_LITTER}") - public final Integer QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER= null; + public final Integer QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER = null; + @Value("${QualitativeValueId.SORTING_TYPE_2_ALIVE_NOT_ITEMIZED}") + public final Integer QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED = null; + + @Value("${QualitativeValueId.SORTING_TYPE_2_INERT}") + public final Integer QUALITATIVE_ID_SORTING_TYPE_2_INERT = null; + + @Value("${QualitativeValueId.SORTING_TYPE_2_ALIVE_ITEMIZED}") + public final Integer QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED = null; + @Value("${StatusCode.ENABLE}") public final String STATUS_VALID_CODE = null; @@ -221,7 +233,8 @@ @Value("${PmfmId.SURVEY_PART}") public final Integer PMFM_ID_SURVEY_PART = null; - @Value("${PmfmId.MEASUREMENT_FILE}") + //FIXME-TC Remove this when no more used + @Value("${PmfmId.SURVEY_PART}") public final Integer PMFM_ID_MEASUREMENT_FILE = null; @Value("${ProgramCode.SCIENTIFIC_CRUISE_PREFIX}") @@ -230,12 +243,6 @@ @Value("${TaxonGroupTypeCode.COMMERCIAL_SPECIES}") public final String TAXON_GROUP_TYPE_ID_COMMERCIAL_SPECIES = null; - @Value("${ReferenceTaxonId.LIFE}") - public final Integer REFERENCE_TAXON_ID_LIFE = null; - - @Value("${ReferenceTaxonId.INERT}") - public final Integer REFERENCE_TAXON_ID_INERT = null; - @Value("${ObjectTypeCode.SCIENTIFIC_CRUISE}") public final String OBJECT_TYPE_SCIENTIFIC_CRUISE = null; Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-04-03 15:14:47 UTC (rev 720) @@ -74,6 +74,8 @@ private static final Log log = LogFactory.getLog(BatchPersistenceHelper.class); + public static final String BATCH_PMFM_ID = "pmfmId"; + @Resource(name = "referentialPersistenceService") protected ReferentialPersistenceService referentialService; @@ -188,7 +190,7 @@ SpeciesBatch targetChild = TuttiBeanFactory.newSpeciesBatch(); entityToSpeciesBatch(sourceChild, targetChild); if (log.isInfoEnabled()) { - log.info("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); + log.info("Loaded CatchBatch Hors Vrac > (Species|Benthos) > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } if (targetChild.getSampleCategoryValue() != null) { targetChilds.add(targetChild); @@ -258,8 +260,8 @@ // RankOrder (initialize once, at creation) if (target.getRankOrder() == null) { - // Start rank order at 3, because of special batches 'Biota' and 'Inert' - short rankOrder = (short) 3; + // Start rank order at 1 + short rankOrder = (short) 1; if (source.getParentBatch() != null && source.getParentBatch().getChildBatchs() != null) { rankOrder += (short) source.getParentBatch().getChildBatchs().size(); } else if (target.getParentBatch() != null && target.getParentBatch().getChildBatchs() != null) { @@ -358,7 +360,7 @@ // } } - public void setBatchParents(SpeciesBatch source, + protected void setBatchParents(SpeciesBatch source, SortingBatch target, String parentBatchIdStr, fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, @@ -386,12 +388,18 @@ } Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue()); + //FIXME-TC Should have PMFM_ID_SORTING_TYPE > PMFM_ID_SORTING_TYPE_2 > pmfmId ? +// parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), +// BATCH_PMFM_ID, pmfmId, qualitativeValueId, +// BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId, +// BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED); parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), - "pmfmId", pmfmId, qualitativeValueId, - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId); + BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId, // species | Benthos + BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED, // vivant trié + BATCH_PMFM_ID, pmfmId, qualitativeValueId); // vrac | hors vrac - // Parent Batch - target.setParentBatch(parentBatch); +// // Parent Batch +// target.setParentBatch(parentBatch); } @@ -405,56 +413,6 @@ target.setRootBatch(catchBatch); } - public Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { - if (value == null) - return null; - Integer qualitativeValueId = null; - if (value instanceof CaracteristicQualitativeValue) { - CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value; - qualitativeValueId = cqValue.getIdAsInt(); - } else if (value instanceof String) { - qualitativeValueId = Integer.valueOf((String) value); - } - return qualitativeValueId; - } - - public void setSampleCategoryQualitative(SpeciesBatch target, - Integer pmfmId, - Float numericalvalue, - String alphanumericalValue, - Integer qualitativeValueId) { - // skip if null or corresponding to the SORTING_TYPE PMFM (Expèce, Benthos, Plancton, etc.) - if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) { - return; - } - - SampleCategoryEnum sampleCategory = enumeration.getSampleCategoryByPmfmId(pmfmId); - Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); - - target.setSampleCategoryType(sampleCategory); - if (numericalvalue != null) { - target.setSampleCategoryValue(numericalvalue); - return; - } - if (alphanumericalValue != null) { - target.setSampleCategoryValue(alphanumericalValue); - return; - } - - Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId); - if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { - return; - } - CaracteristicQualitativeValue value = null; - for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { - if (qualitativeValueId.equals(qv.getIdAsInt())) { - value = qv; - break; - } - } - target.setSampleCategoryValue(value); - } - public void speciesBatchFrequencyToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, @@ -542,6 +500,56 @@ // } } + protected Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { + if (value == null) + return null; + Integer qualitativeValueId = null; + if (value instanceof CaracteristicQualitativeValue) { + CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value; + qualitativeValueId = cqValue.getIdAsInt(); + } else if (value instanceof String) { + qualitativeValueId = Integer.valueOf((String) value); + } + return qualitativeValueId; + } + + protected void setSampleCategoryQualitative(SpeciesBatch target, + Integer pmfmId, + Float numericalvalue, + String alphanumericalValue, + Integer qualitativeValueId) { + // skip if null or corresponding to the SORTING_TYPE PMFM (Espèce, Benthos, Plancton, etc.) + if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) { + return; + } + + SampleCategoryEnum sampleCategory = enumeration.getSampleCategoryByPmfmId(pmfmId); + Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); + + target.setSampleCategoryType(sampleCategory); + if (numericalvalue != null) { + target.setSampleCategoryValue(numericalvalue); + return; + } + if (alphanumericalValue != null) { + target.setSampleCategoryValue(alphanumericalValue); + return; + } + + Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId); + if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { + return; + } + CaracteristicQualitativeValue value = null; + for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { + if (qualitativeValueId.equals(qv.getIdAsInt())) { + value = qv; + break; + } + } + target.setSampleCategoryValue(value); + } + public Integer getRecorderDepartmentId() { // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?) return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT; 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-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java 2013-04-03 15:14:47 UTC (rev 720) @@ -80,8 +80,11 @@ List<CatchBatchValidationError> errors) { // Vrac - SortingBatch vracBatch = catchBatchDao.getSortingBatch(batchs, - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID); + SortingBatch vracBatch = catchBatchDao.getSortingBatch( + batchs, + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_VRAC_ID); if (log.isDebugEnabled()) { log.debug("Try to validate Vrac batch model " + vracBatch); @@ -91,80 +94,124 @@ addError(errors, n_("tutti.persistence.batch.validation.vracNotFound")); } else { // Vrac > Species - SortingBatch speciesBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, - enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + SortingBatch speciesBatch = catchBatchDao.getSortingBatch( + vracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (speciesBatch == null) { addError(errors, n_("tutti.persistence.batch.validation.vracSpeciesNotFound")); } else { + // Vrac > Species > Alive not itemized + SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch( + speciesBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED); + if (livingNotItemizedBatch == null) { + addWarning(errors, n_("tutti.persistence.batch.validation.vracSpeciesLifeNotFound")); + } + // Vrac > Species > Inert - SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); + SortingBatch inertBatch = catchBatchDao.getSortingBatch( + speciesBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT); if (inertBatch == null) { 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, n_("tutti.persistence.batch.validation.vracSpeciesLifeNotFound")); + // Vrac > Species > Alive itemized + SortingBatch aliveItemizedBatch = catchBatchDao.getSortingBatch( + speciesBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED); + if (aliveItemizedBatch == null) { + addWarning(errors, n_("tutti.persistence.batch.validation.vracSpeciesAliveItemizedNotFound")); } - // TODO verifier que les espèces en haut de grappe ont bien la catégorie voulue (sorted-unsroted) + // TODO verifier que les espèces en haut de grappe ont bien la catégorie voulue (sorted-unsorted) } // Vrac > Benthos - SortingBatch benthosBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, - enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + SortingBatch benthosBatch = catchBatchDao.getSortingBatch( + vracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); if (benthosBatch == null) { addError(errors, n_("tutti.persistence.batch.validation.vracBenthosNotFound")); } else { + + // Vrac > Benthos > Alive not itemized + SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch( + benthosBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_NOT_ITEMIZED); + if (livingNotItemizedBatch == null) { + addWarning(errors, n_("tutti.persistence.batch.validation.vracBenthosLifeNotFound")); + } + // Vrac > Benthos > Inert - SortingBatch inertBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); + SortingBatch inertBatch = catchBatchDao.getSortingBatch( + benthosBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_INERT); if (inertBatch == null) { addWarning(errors, n_("tutti.persistence.batch.validation.vracBenthosInertNotFound")); } - // Vrac > Benthos > Alive no itemized - SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(benthosBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); - if (livingNotItemizedBatch == null) { - addWarning(errors, n_("tutti.persistence.batch.validation.vracBenthosLifeNotFound")); + // Vrac > Benthos > Alive itermized + SortingBatch aliveItemizedBatch = catchBatchDao.getSortingBatch( + benthosBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE_2, + enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED); + if (aliveItemizedBatch == null) { + addWarning(errors, n_("tutti.persistence.batch.validation.vracBenthosAliveItemizedNotFound")); } } // TODO : Plancton... } // Hors Vrac - SortingBatch horsVracBatch = catchBatchDao.getSortingBatch(batchs, - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, - enumeration.QUALITATIVE_HORS_VRAC_ID); + SortingBatch horsVracBatch = catchBatchDao.getSortingBatch( + batchs, + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_HORS_VRAC_ID); if (horsVracBatch == null) { 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); + SortingBatch speciesBatch = catchBatchDao.getSortingBatch( + horsVracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (speciesBatch == null) { addWarning(errors, n_("tutti.persistence.batch.validation.horsVracSpeciesNotFound")); } // Hors Vrac > Benthos - SortingBatch benthosBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, - enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + SortingBatch benthosBatch = catchBatchDao.getSortingBatch( + horsVracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); if (benthosBatch == null) { addWarning(errors, n_("tutti.persistence.batch.validation.horsVracBenthosNotFound")); } - // Hors Vrac > MarineLitter - SortingBatch marineLitterBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), - "pmfmId", - enumeration.PMFM_ID_SORTING_TYPE, - enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); + // Hors Vrac > Marine Litter + SortingBatch marineLitterBatch = catchBatchDao.getSortingBatch( + horsVracBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTING_TYPE, + enumeration.QUALITATIVE_ID_SORTING_TYPE_MARINE_LITTER); if (marineLitterBatch == null) { addWarning(errors, n_("tutti.persistence.batch.validation.horsVracMarineLitterNotFound")); @@ -173,9 +220,11 @@ } // Unsorted - SortingBatch unsortedBatch = catchBatchDao.getSortingBatch(batchs, - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, - enumeration.QUALITATIVE_UNSORTED_ID); + SortingBatch unsortedBatch = catchBatchDao.getSortingBatch( + batchs, + BatchPersistenceHelper.BATCH_PMFM_ID, + enumeration.PMFM_ID_SORTED_UNSORTED, + enumeration.QUALITATIVE_UNSORTED_ID); if (unsortedBatch == null) { addWarning(errors, n_("tutti.persistence.batch.validation.unsortedNotFound")); } Modified: trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties =================================================================== --- trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties 2013-04-03 15:14:47 UTC (rev 720) @@ -19,10 +19,12 @@ tutti.persistence.batch.validation.horsVracSpeciesNotFound= tutti.persistence.batch.validation.onlySpeciesBatchStructure= tutti.persistence.batch.validation.unsortedNotFound= +tutti.persistence.batch.validation.vracBenthosAliveItemizedNotFound= tutti.persistence.batch.validation.vracBenthosInertNotFound= tutti.persistence.batch.validation.vracBenthosLifeNotFound= tutti.persistence.batch.validation.vracBenthosNotFound= tutti.persistence.batch.validation.vracNotFound= +tutti.persistence.batch.validation.vracSpeciesAliveItemizedNotFound= tutti.persistence.batch.validation.vracSpeciesInertNotFound= tutti.persistence.batch.validation.vracSpeciesLifeNotFound= tutti.persistence.batch.validation.vracSpeciesNotFound= 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-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties 2013-04-03 15:14:47 UTC (rev 720) @@ -19,10 +19,12 @@ tutti.persistence.batch.validation.horsVracSpeciesNotFound=Lot 'Hors Vrac > Espèces' non trouvé ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.onlySpeciesBatchStructure=Lot 'Espèces' (données historiques CGFS) détecté. tutti.persistence.batch.validation.unsortedNotFound=Lot 'Hors Vrac > Espèces' non trouvé ou configuré avec d'autres critères de classement. +tutti.persistence.batch.validation.vracBenthosAliveItemizedNotFound= tutti.persistence.batch.validation.vracBenthosInertNotFound=Lot 'Vrac > Benthos > Inerte' non trouvé, ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.vracBenthosLifeNotFound=Lot 'Vrac > Benthos > Biota' non trouvé, ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.vracBenthosNotFound=Lot 'Vrac > Benthos' 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.vracSpeciesAliveItemizedNotFound= tutti.persistence.batch.validation.vracSpeciesInertNotFound=Lot 'Vrac > Espèces > Inerte' non trouvé, ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.vracSpeciesLifeNotFound=Lot 'Vrac > Espèces > Biota' non trouvé, ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.vracSpeciesNotFound=Lot 'Vrac > Espèces' non trouvé, ou configuré avec d'autres critères de classement. Modified: trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties =================================================================== --- trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/main/resources/tutti-db-enumerations.properties 2013-04-03 15:14:47 UTC (rev 720) @@ -336,27 +336,17 @@ PmfmId.MARINE_LITTER_SIZE_CATEGORY=1422 # Pour stoquer Cruise.surveyPart -# TODO Alphanumeric = true A creer (dans les enumerations Allegro) -# FIXME Change this number -PmfmId.SURVEY_PART=1310 +PmfmId.SURVEY_PART=1432 -# Pmfm associé aux pièces-jointes -# TODO Alphanumeric = true A creer (dans les enumerations Allegro) -# FIXME Change this number -PmfmId.MEASUREMENT_FILE=1310 - -# TODO A creer (dans les enumerations Allegro) PmfmId.STATION_NUMBER=1243 -# TODO A creer (dans les enumerations Allegro) PmfmId.TRAWL_DISTANCE=113 -# TODO A creer (dans les enumerations Allegro) + PmfmId.HAUL_VALID=1163 QualitativeValueId.HAUL_VALID_YES=1575 QualitativeValueId.HAUL_VALID_NO=1576 -# TODO A creer (dans les enumerations Allegro) + PmfmId.RECTILINEAR_OPERATION=192 QualitativeValueId.RECTILINEAR_OPERATION_YES=277 -# TODO A creer (dans les enumerations Allegro) QualitativeValueId.RECTILINEAR_OPERATION_NO=278 # PSFM "Nombre de poche" d'un chalut (écran campagne) @@ -364,11 +354,9 @@ # PSFM "Liste des poches observées" (écran opération) PmfmId.MULTIRIG_AGGREGATION=1424 -# TODO A creer (dans les enumerations Allegro) # PSFM "Poids - observation par une observateur" (écran captures, onglet espèce, benthos, etc) PmfmId.WEIGHT_MEASURED=220 -# TODO A creer (dans les enumerations Allegro) # PSFM "Vrac/Hors Vrac" - "Organisation des données campagnes" PmfmId.SORTED_UNSORTED=1428 QualitativeValueId.SORTED_VRAC=311 @@ -382,25 +370,19 @@ QualitativeValueId.SORTING_TYPE_MARINE_LITTER=2150 QualitativeValueId.SORTING_TYPE_ACCIDENTAL_CATCH=2151 +PmfmId.SCIENTIFIC_CRUISE_SORTING_TYPE_2=1431 +QualitativeValueId.SORTING_TYPE_2_ALIVE_NOT_ITEMIZED=2161 +QualitativeValueId.SORTING_TYPE_2_INERT=2162 +QualitativeValueId.SORTING_TYPE_2_ALIVE_ITEMIZED=2160 -#TODO A creer (dans les enumerations Allegro) # (20=observateur volant, 95=Administrateur SIH) -> L'avantage du 20 est qu'il est inactif (=20), donc plus facilement detectable PersonId.UNKNOWN_RECORDER_PERSON=20 -#TODO A creer (dans les enumerations Allegro) # 181=PDG-RBE (à confirmer par Vincent) DepartmentId.UNKNOWN_RECORDER_DEPARTMENT=181 -#TODO A creer (dans les enumerations Allegro) ProgramCode.SCIENTIFIC_CRUISE_PREFIX=CAM- -#Reference taxon correspondant à "Biota" (ou "Vie") -ReferenceTaxonId.LIFE=7637 -#Reference taxon correspondant à "Non Biota" (ou "Non Vie" - matière inerte) -# TODO : a creer dans la base harmonie et achanger ! -ReferenceTaxonId.INERT=1 - -# TODO : A Creer (dans les énumerations Allegro) ObjectTypeCode.SCIENTIFIC_CRUISE=SCIENTIFIC_CRUISE ObjectTypeCode.OPERATION=OPERATION ObjectTypeCode.CATCH_BATCH=CATCH_BATCH Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseFixtures.java 2013-04-03 15:14:47 UTC (rev 720) @@ -67,15 +67,15 @@ } public int refNbCaracteristic() { - return 476; + return 478; } public int refNbSpecies() { - return 16853; + return 16946; } public int refNbReferentSpecies() { - return 8514; + return 8645; } public int refNbScientificGear() { @@ -87,15 +87,15 @@ } public int refNbCountry() { - return 240; + return 239; } public int refNbHarbour() { - return 1896; + return 1898; } public int refNbProgramZone() { - return 16; + return 14; } public int refNbStrata() { @@ -111,7 +111,7 @@ } public int refNbFishingVessel() { - return 24805; + return 24837; } public int refNbScientificVessel() { @@ -119,11 +119,11 @@ } public int refNbPerson() { - return 123; + return 128; } public int refNbObjectType() { - return 56; + return 57; } public String refSpeciesId() { Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/DatabaseResource.java 2013-04-03 15:14:47 UTC (rev 720) @@ -35,6 +35,7 @@ import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assume; @@ -86,35 +87,47 @@ private final boolean writeDb; + private String dbName; + public static DatabaseResource readDb() { - return new DatabaseResource(); + return new DatabaseResource(""); } public static DatabaseResource writeDb() { - return new DatabaseResource(true); + return new DatabaseResource("", true); } + public static DatabaseResource readDb(String dbName) { + return new DatabaseResource(dbName); + } + + public static DatabaseResource writeDb(String dbName) { + return new DatabaseResource(dbName, true); + } + public static DatabaseResource noDb() { return new DatabaseResource( - "beanRefFactoryWitNoDb.xml", "TuttiBeanRefFactoryWithNoDb"); + "", "beanRefFactoryWitNoDb.xml", "TuttiBeanRefFactoryWithNoDb"); } - protected DatabaseResource() { - this(null, null, false); + protected DatabaseResource(String dbName) { + this(dbName, null, null, false); } - protected DatabaseResource(boolean writeDb) { - this(null, null, writeDb); + protected DatabaseResource(String dbName, boolean writeDb) { + this(dbName, null, null, writeDb); } - protected DatabaseResource(String beanFactoryReferenceLocation, + protected DatabaseResource(String dbName, String beanFactoryReferenceLocation, String beanRefFactoryReferenceId) { - this(beanFactoryReferenceLocation, beanRefFactoryReferenceId, false); + this(dbName, beanFactoryReferenceLocation, + beanRefFactoryReferenceId, false); } - protected DatabaseResource(String beanFactoryReferenceLocation, + protected DatabaseResource(String dbName, String beanFactoryReferenceLocation, String beanRefFactoryReferenceId, boolean writeDb) { + this.dbName = dbName; this.beanFactoryReferenceLocation = beanFactoryReferenceLocation; this.beanRefFactoryReferenceId = beanRefFactoryReferenceId; this.writeDb = writeDb; @@ -156,7 +169,12 @@ testClass = description.getTestClass(); - File db = new File("src/test/db"); + boolean defaultDbName = StringUtils.isEmpty(dbName); + + if (defaultDbName) { + dbName = "db"; + } + File db = new File("src/test/" + dbName); if (!db.exists()) { if (log.isWarnEnabled()) { @@ -182,8 +200,12 @@ // check that config file is in classpath (avoid to find out why it does not works...) String configFilename = writeDb ? - "tutti-test-write.properties" : - "tutti-test-read.properties"; + "tutti-test-write" : + "tutti-test-read"; + if (!defaultDbName) { + configFilename += "-" + dbName; + } + configFilename += ".properties"; InputStream resourceAsStream = getClass().getResourceAsStream("/" + configFilename); Preconditions.checkNotNull(resourceAsStream, "Could not find " + configFilename + " in test class-path"); @@ -319,7 +341,7 @@ } } else { if (log.isWarnEnabled()) { - log.warn("Won't destroy directories caus of failures in test."); + log.warn("Won't destroy directories cause of failures in test."); } } Modified: 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-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceWriteTest.java 2013-04-03 15:14:47 UTC (rev 720) @@ -30,10 +30,6 @@ 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.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 fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import org.junit.Assert; import org.junit.Before; @@ -76,32 +72,6 @@ protected FishingOperation fishingOperationNoCatchBatch; - protected FishingOperation fishingOperationWithEmptyBatch; - - 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; - @Before public void setUp() throws Exception { service = TuttiPersistenceServiceLocator.getCatchBatchPersistenceService(); @@ -109,10 +79,6 @@ fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); referentialService = TuttiPersistenceServiceLocator.getReferentialPersistenceService(); - species = referentialService.getAllSpecies(); - assertNotNull(species); - assertTrue(species.size() > 2); - cruise = cruiseService.getCruise(dbResource.getFixtures().cruiseId()); cruise.setId((String) null); Calendar calendar = new GregorianCalendar(); @@ -144,46 +110,6 @@ 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((String) 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 = TuttiBeanFactory.newCatchBatch(); - 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); - - 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 @@ -228,6 +154,9 @@ catchBatch.setBenthosTotalInertWeight(0.2f); } } + // Hors-Vrac : + // MarineLitter + catchBatch.setMarineLitterTotalWeight(100f); // Rejet : 15kg catchBatch.setCatchTotalRejectedWeight(15f); @@ -299,5 +228,7 @@ assertEquals(expectedCatchBatch.getBenthosTotalSortedWeight(), actualCatchBatch.getBenthosTotalSortedWeight()); assertEquals(expectedCatchBatch.getBenthosTotalInertWeight(), actualCatchBatch.getBenthosTotalInertWeight()); assertEquals(expectedCatchBatch.getBenthosTotalLivingNotItemizedWeight(), actualCatchBatch.getBenthosTotalLivingNotItemizedWeight()); + + assertEquals(expectedCatchBatch.getMarineLitterTotalWeight(), actualCatchBatch.getMarineLitterTotalWeight()); } } Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java 2013-04-03 15:14:47 UTC (rev 720) @@ -58,7 +58,7 @@ public class ReferentialPersistenceServiceReadTest { @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.readDb(); + public static final DatabaseResource dbResource = DatabaseResource.readDb("dbEmpty"); /** Logger. */ private static final Log log = 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-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeHelperTest.java 2013-04-03 15:14:47 UTC (rev 720) @@ -82,6 +82,8 @@ protected Properties localConnectionProperties; + protected boolean checkDate = true; + @Before public void setUp() throws Exception { helper = new ReferentialSynchronizeHelper(); @@ -178,34 +180,34 @@ getLastUpdateDate(TuttiTable.UNIT, internalDb, getSqlDate(2012, 8, 17)); getLastUpdateDate(TuttiTable.AGGREGATION_LEVEL, internalDb, getSqlDate(2011, 6, 9)); - getLastUpdateDate(TuttiTable.PARAMETER_GROUP, internalDb, getSqlDate(2013, 1, 29)); - getLastUpdateDate(TuttiTable.PARAMETER, internalDb, getSqlDate(2013, 1, 29)); + getLastUpdateDate(TuttiTable.PARAMETER_GROUP, internalDb, getSqlDate(2013, 4, 2)); + getLastUpdateDate(TuttiTable.PARAMETER, internalDb, getSqlDate(2013, 4, 2)); getLastUpdateDate(TuttiTable.MATRIX, internalDb, getSqlDate(2013, 1, 24)); getLastUpdateDate(TuttiTable.FRACTION, internalDb, getSqlDate(2013, 1, 24)); getLastUpdateDate(TuttiTable.METHOD, internalDb, getSqlDate(2013, 1, 29)); - getLastUpdateDate(TuttiTable.PMFM, internalDb, getSqlDate(2013, 1, 29)); + getLastUpdateDate(TuttiTable.PMFM, internalDb, getSqlDate(2013, 4, 2)); getLastUpdateDate(TuttiTable.GEAR_CLASSIFICATION, internalDb, getSqlDate(2012, 12, 18)); 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, 3, 29)); - getLastUpdateDate(TuttiTable.TAXONOMIC_LEVEL, internalDb, getSqlDate(2012, 4, 18)); - getLastUpdateDate(TuttiTable.REFERENCE_TAXON, internalDb, getSqlDate(2013, 1, 21)); + getLastUpdateDate(TuttiTable.TAXONOMIC_LEVEL, internalDb, getSqlDate(2013, 2, 21)); + getLastUpdateDate(TuttiTable.REFERENCE_TAXON, internalDb, getSqlDate(2013, 3, 26)); getLastUpdateDate(TuttiTable.TAXON_NAME, internalDb, getSqlDate(2013, 3, 29)); 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)); - getLastUpdateDate(TuttiTable.WEIGHT_LENGTH_CONVERSION, internalDb, getSqlDate(2013, 1, 17)); + getLastUpdateDate(TuttiTable.TAXON_GROUP, internalDb, getSqlDate(2013, 2, 20)); + getLastUpdateDate(TuttiTable.ROUND_WEIGHT_CONVERSION, internalDb, getSqlDate(2013, 3, 28)); + getLastUpdateDate(TuttiTable.WEIGHT_LENGTH_CONVERSION, internalDb, getSqlDate(2013, 2, 18)); getLastUpdateDate(TuttiTable.VESSEL_TYPE, internalDb, getSqlDate(2012, 4, 25)); - getLastUpdateDate(TuttiTable.VESSEL, internalDb, getSqlDate(2013, 1, 25)); + getLastUpdateDate(TuttiTable.VESSEL, internalDb, getSqlDate(2013, 3, 29)); getLastUpdateDate(TuttiTable.USER_PROFIL, internalDb, getSqlDate(2009, 6, 18)); - getLastUpdateDate(TuttiTable.DEPARTMENT, internalDb, getSqlDate(2013, 1, 24)); - getLastUpdateDate(TuttiTable.PERSON, internalDb, getSqlDate(2013, 1, 29)); + getLastUpdateDate(TuttiTable.DEPARTMENT, internalDb, getSqlDate(2013,2, 14)); + getLastUpdateDate(TuttiTable.PERSON, internalDb, getSqlDate(2013, 4, 2)); getLastUpdateDate(TuttiTable.FRACTION2MATRIX, internalDb, null); getLastUpdateDate(TuttiTable.PMFM2QUALITATIVE_VALUE, internalDb, null); getLastUpdateDate(TuttiTable.GEAR_CLASSIFICATION_ASSOCIATIO, internalDb, getSqlDate(2012, 12, 18)); getLastUpdateDate(TuttiTable.GEAR_ASSOCIATION, internalDb, getSqlDate(2012, 12, 18)); - getLastUpdateDate(TuttiTable.LOCATION_ASSOCIATION, internalDb, getSqlDate(2013, 1, 29)); + getLastUpdateDate(TuttiTable.LOCATION_ASSOCIATION, internalDb, getSqlDate(2013, 3, 27)); getLastUpdateDate(TuttiTable.LOCATION_HIERARCHY, internalDb, null); getLastUpdateDate(TuttiTable.LOCATION_HIERARCHY_EXCEPTION, internalDb, null); getLastUpdateDate(TuttiTable.TAXON_INFORMATION, internalDb, getSqlDate(2012, 2, 13)); @@ -215,16 +217,16 @@ getLastUpdateDate(TuttiTable.UNIT_CONVERSION, internalDb, getSqlDate(2011, 11, 21)); getLastUpdateDate(TuttiTable.VESSEL_REGISTRATION_PERIOD, internalDb, null); getLastUpdateDate(TuttiTable.PERSON2USER_PROFIL, internalDb, null); - getLastUpdateDate(TuttiTable.TAXON_NAME_HISTORY, internalDb, getSqlDate(2013, 1, 21)); + getLastUpdateDate(TuttiTable.TAXON_NAME_HISTORY, internalDb, getSqlDate(2013, 3, 28)); getLastUpdateDate(TuttiTable.REFERENCE_DOCUMENT, internalDb, getSqlDate(2011, 11, 4)); getLastUpdateDate(TuttiTable.AUTHOR, internalDb, null); - getLastUpdateDate(TuttiTable.CITATION, internalDb, getSqlDate(2012, 11, 30)); - getLastUpdateDate(TuttiTable.TAXON_GROUP_HISTORICAL_RECORD, internalDb, getSqlDate(2013, 1, 16)); + getLastUpdateDate(TuttiTable.CITATION, internalDb, getSqlDate(2013, 3, 28)); + getLastUpdateDate(TuttiTable.TAXON_GROUP_HISTORICAL_RECORD, internalDb, getSqlDate(2013, 2, 20)); getLastUpdateDate(TuttiTable.ORDER_ITEM, internalDb, getSqlDate(2010, 5, 5)); getLastUpdateDate(TuttiTable.PRECISION_TYPE, internalDb, null); getLastUpdateDate(TuttiTable.NUMERICAL_PRECISION, internalDb, null); getLastUpdateDate(TuttiTable.PHOTO_TYPE, internalDb, getSqlDate(2010, 5, 26)); - getLastUpdateDate(TuttiTable.OBJECT_TYPE, internalDb, getSqlDate(2013, 1, 7)); + getLastUpdateDate(TuttiTable.OBJECT_TYPE, internalDb, getSqlDate(2013, 2, 14)); getLastUpdateDate(TuttiTable.ORDER_TYPE, internalDb, getSqlDate(2009, 10, 16)); getLastUpdateDate(TuttiTable.ANALYSIS_INSTRUMENT, internalDb, null); @@ -736,11 +738,30 @@ log.debug("getLastUpdateDate(TuttiTable." + tuttiTable.name() + ", internalDb, getSqlDate(" + instance.get(Calendar.YEAR) + ", " + (1 + instance.get(Calendar.MONTH)) + ", " + instance.get(Calendar.DAY_OF_MONTH) + "));"); } } - if (expected == null) { + if (checkDate) { + if (expected == null) { - Assert.assertNull(actual); + Assert.assertNull(actual); + } else { + assertDate(expected, actual); + } } else { - assertDate(expected, actual); + if (expected == null) { + + if(actual!=null) { + if (log.isWarnEnabled()) { + log.warn("getLastUpdateDate(TuttiTable." + tuttiTable.name() + ", internalDb, null);"); + } + } + } else { + if (!equalsDate(expected, actual)) { + if (log.isWarnEnabled()) { + Calendar instance = Calendar.getInstance(); + instance.setTime(actual); + log.warn("getLastUpdateDate(TuttiTable." + tuttiTable.name() + ", internalDb, getSqlDate(" + instance.get(Calendar.YEAR) + ", " + (1 + instance.get(Calendar.MONTH)) + ", " + instance.get(Calendar.DAY_OF_MONTH) + "));"); + } + } + } } } @@ -863,6 +884,16 @@ Assert.assertEquals(expectedCal.get(Calendar.DAY_OF_MONTH), actualCal.get(Calendar.DAY_OF_MONTH)); } + public static boolean equalsDate(Date expected, Date actual) { + Calendar expectedCal = Calendar.getInstance(); + expectedCal.setTime(expected); + Calendar actualCal = Calendar.getInstance(); + actualCal.setTime(actual); + boolean result = expectedCal.get(Calendar.YEAR) == actualCal.get(Calendar.YEAR); + result &= expectedCal.get(Calendar.MONTH)== actualCal.get(Calendar.MONTH); + result &= expectedCal.get(Calendar.DAY_OF_MONTH)== actualCal.get(Calendar.DAY_OF_MONTH); + return result; + } public static Date getSqlDate(int year, int month, int day) { return getDate(year, month - 1, day); Copied: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceCopyTest.java (from rev 717, trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java) =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceCopyTest.java (rev 0) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceCopyTest.java 2013-04-03 15:14:47 UTC (rev 720) @@ -0,0 +1,194 @@ +package fr.ifremer.tutti.persistence.service.synchro; + +/* + * #%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.ProgressionModel; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; +import org.hibernate.dialect.Dialect; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.springframework.jdbc.support.JdbcUtils; + +import javax.swing.JDialog; +import javax.swing.JProgressBar; +import java.awt.Frame; +import java.awt.GraphicsEnvironment; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Properties; + +/** + * To synchonize a db with cgfs data with last referentiel db. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +@Ignore +public class ReferentialSynchronizeServiceCopyTest { + + @ClassRule + public static final DatabaseResource dbResource = + DatabaseResource.writeDb(); + + @Rule + public final TestName n = new TestName(); + + protected ReferentialSynchronizeService service; + + protected Properties remoteConnectionProperties; + + protected Properties localConnectionProperties; + + protected Connection remoteConnection; + + protected Connection localConnection; + + private Dialect dialect; + + protected ReferentialSynchronizeHelper helper; + + protected JDialog dialog; + + @Before + public void setUp() throws Exception { + + // create services + helper = new ReferentialSynchronizeHelper(); + service = TuttiPersistenceServiceLocator.getReferentialSynchronizeService(); + + // create grab local stuff + localConnectionProperties = service.getLocalConnectionProperties(); + dialect = service.getLocalDialect(); + + // create read-only remote db + remoteConnectionProperties = new Properties(); + TuttiEntities.fillConnectionProperties( + remoteConnectionProperties, + TuttiEntities.getJdbcUrl(new File("src/test/dbEmpty"), dbResource.getConfig().getDbName()), + dbResource.getConfig().getJdbcUsername(), + dbResource.getConfig().getJdbcPassword()); + +// dbResource.copyDb(n.getMethodName(), false, remoteConnectionProperties); + + // open connections + remoteConnection = TuttiEntities.createConnection(remoteConnectionProperties); + localConnection = TuttiEntities.createConnection(localConnectionProperties); + } + + @After + public void tearDown() throws Exception { + if (dialog != null) { + dialog.setVisible(false); + } + service = null; + remoteConnectionProperties = null; + dialect = null; + helper = null; + JdbcUtils.closeConnection(localConnection); + + JdbcUtils.closeConnection(remoteConnection); + } + + @Test + public void synchronize() throws SQLException { + + ReferentialSynchronizeResult result = + new ReferentialSynchronizeResult(); + + dialog = createProgressBar(result); + + service.prepare(remoteConnectionProperties, result); + + Assert.assertNotNull(result); + Assert.assertNull(result.getError()); + Assert.assertTrue(result.isSuccess()); + + service.synchronize(remoteConnectionProperties, result); + + Assert.assertEquals(result.getTotalRows(), result.getProgressionModel().getTotal()); + Assert.assertEquals(result.getProgressionModel().getTotal(), result.getProgressionModel().getCurrent()); + Assert.assertEquals(1.0, result.getProgressionModel().getRate(), 0.01); + + Assert.assertNull(result.getError()); + Assert.assertTrue(result.isSuccess()); + + Statement statement = localConnection.createStatement(); + + statement.execute("SHUTDOWN"); + statement.close(); + } + + public static JDialog createProgressBar(ReferentialSynchronizeResult result) { + + JDialog dialog; + if (GraphicsEnvironment.isHeadless()) { + dialog = null; + } else { + dialog = new JDialog((Frame) null, + "synchronisation " + result.getLocalUrl() + " from " + result.getRemoteUrl(), + false); + dialog.setSize(600, 400); + final JProgressBar progressBar = new JProgressBar(); + progressBar.setStringPainted(true); + progressBar.setIndeterminate(false); + ProgressionModel progressionModel = result.getProgressionModel(); + progressionModel.addPropertyChangeListener(ProgressionModel.PROPERTY_MESSAGE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + progressBar.setString((String) evt.getNewValue()); + } + }); + progressionModel.addPropertyChangeListener(ProgressionModel.PROPERTY_TOTAL, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + progressBar.setMinimum(0); + progressBar.setMaximum((Integer) evt.getNewValue()); + } + }); + progressionModel.addPropertyChangeListener(ProgressionModel.PROPERTY_CURRENT, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + progressBar.setValue((Integer) evt.getNewValue()); + + } + }); + dialog.add(progressBar); + dialog.setVisible(true); + } + return dialog; + } +} Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplTest.java 2013-04-03 15:14:47 UTC (rev 720) @@ -57,7 +57,8 @@ public class ReferentialSynchronizeServiceImplTest { @ClassRule - public static final DatabaseResource dbResource = DatabaseResource.writeDb(); + public static final DatabaseResource dbResource = + DatabaseResource.writeDb(); @Rule public final TestName n = new TestName(); Copied: trunk/tutti-persistence/src/test/resources/tutti-test-read-dbEmpty.properties (from rev 717, trunk/tutti-persistence/src/test/resources/tutti-test-read.properties) =================================================================== --- trunk/tutti-persistence/src/test/resources/tutti-test-read-dbEmpty.properties (rev 0) +++ trunk/tutti-persistence/src/test/resources/tutti-test-read-dbEmpty.properties 2013-04-03 15:14:47 UTC (rev 720) @@ -0,0 +1,27 @@ +### +# #%L +# Tutti :: Persistence API +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 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% +### +tutti.persistence.db.directory=src/test/dbEmpty +tutti.persistence.jdbc.url=jdbc:hsqldb:file:src/test/dbEmpty/allegro +#tutti.persistence.jdbc.url=jdbc:hsqldb:hsql://localhost/allegro +tutti.persistence.jdbc.createScript=src/test/dbEmpty/allegro.script Copied: trunk/tutti-persistence/src/test/resources/tutti-test-write-dbEmpty.properties (from rev 717, trunk/tutti-persistence/src/test/resources/tutti-test-write.properties) =================================================================== --- trunk/tutti-persistence/src/test/resources/tutti-test-write-dbEmpty.properties (rev 0) +++ trunk/tutti-persistence/src/test/resources/tutti-test-write-dbEmpty.properties 2013-04-03 15:14:47 UTC (rev 720) @@ -0,0 +1,24 @@ +### +# #%L +# Tutti :: Persistence API +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2012 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% +### +tutti.persistence.jdbc.createScript=src/test/dbEmpty/allegro.script Modified: trunk/tutti-persistence/src/test/server.properties =================================================================== --- trunk/tutti-persistence/src/test/server.properties 2013-04-03 09:21:33 UTC (rev 719) +++ trunk/tutti-persistence/src/test/server.properties 2013-04-03 15:14:47 UTC (rev 720) @@ -22,4 +22,6 @@ # #L% ### server.database.0=file:db/allegro -server.dbname.0=allegro \ No newline at end of file +server.dbname.0=allegro +server.database.1=file:dbEmpty/allegro +server.dbname.1=allegroEmpty \ No newline at end of file