r1736 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tutti/service/catches tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise
Author: tchemit Date: 2014-04-28 13:17:10 +0200 (Mon, 28 Apr 2014) New Revision: 1736 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1736 Log: refs-90 #4958 Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/IndividualObservationBatchPersistenceServiceImpl.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/util/BatchPersistenceHelper.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SamplePersistenceHelper.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SynchronizationStatusHelper.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseToReadyToSynchAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/ValidateCruiseUIModel.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceImpl.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AccidentalBatchPersistenceServiceImpl.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -40,7 +40,6 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.MatrixImpl; import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId2; import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl; -import fr.ifremer.adagio.core.dao.technical.synchronization.SynchronizationStatus; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; @@ -54,7 +53,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.type.IntegerType; -import org.springframework.dao.DataRetrievalFailureException; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -138,6 +136,7 @@ beanToEntity(bean, sample); samplePersistenceHelper.create(sample); bean.setId(String.valueOf(sample.getId())); + synchronizationStatusHelper.setDirty(bean); return bean; } @@ -150,12 +149,9 @@ Preconditions.checkState(!TuttiEntities.isNew(bean.getFishingOperation())); Sample sample = samplePersistenceHelper.load(bean.getIdAsInt()); - if (sample == null) { - throw new DataRetrievalFailureException( - "Could not retrieve sample id=" + bean.getId()); - } beanToEntity(bean, sample); samplePersistenceHelper.update(sample); + synchronizationStatusHelper.setDirty(bean); return bean; } @@ -243,9 +239,6 @@ // Always use a null batch (to differ with other samples) target.setBatch(null); - // Synchronization Status - target.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue()); - // Comment target.setComments(source.getComment()); 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 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -51,6 +51,8 @@ import fr.ifremer.tutti.persistence.service.util.BatchPersistenceHelper; import fr.ifremer.tutti.persistence.service.util.BatchTreeHelper; import fr.ifremer.tutti.persistence.service.util.MeasurementPersistenceHelper; +import fr.ifremer.tutti.persistence.service.util.SynchronizationStatusHelper; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.dao.DataIntegrityViolationException; @@ -90,6 +92,9 @@ @Resource(name = "measurementPersistenceHelper") protected MeasurementPersistenceHelper measurementPersistenceHelper; + @Resource(name = "synchronizationStatusHelper") + protected SynchronizationStatusHelper synchronizationStatusHelper; + //------------------------------------------------------------------------// //-- Benthos Batch methods --// //------------------------------------------------------------------------// @@ -121,7 +126,7 @@ BenthosBatch target = BenthosBatchs.newBenthosBatch(); target.setSpecies(species); - entityToBenthosBatch(sampleCategoryModel, source, target); + entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch Vrac > Benthos > Alive Itemized > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); @@ -145,7 +150,7 @@ BenthosBatch target = BenthosBatchs.newBenthosBatch(); target.setSpecies(species); - entityToBenthosBatch(sampleCategoryModel, source, target); + entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch Hors Vrac > Benthos > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); @@ -174,7 +179,7 @@ CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getId(), false); SortingBatch batch = SortingBatch.Factory.newInstance(); - benthosBatchToEntity(bean, batch, parentBatchId, catchBatch); + beanToEntity(bean, batch, parentBatchId, catchBatch); bean = batchHelper.createSortingBatch(bean, catchBatch, batch); return bean; @@ -193,7 +198,7 @@ if (bean.getParentBatch() != null) { parentBatchId = bean.getParentBatch().getId(); } - benthosBatchToEntity(bean, batch, parentBatchId, catchBatch); + beanToEntity(bean, batch, parentBatchId, catchBatch); batchHelper.updateSortingBatch(batch, catchBatch); return bean; @@ -202,24 +207,21 @@ @Override public void deleteBenthosBatch(String id) { Preconditions.checkNotNull(id); - - Integer batchId = Integer.valueOf(id); - batchHelper.removeWithChildren(batchId); + batchHelper.deleteBatch(id); } @Override public void deleteBenthosSubBatch(String id) { + Preconditions.checkNotNull(id); batchHelper.deleteSpeciesSubBatch(id); } @Override - public void changeBenthosBatchSpecies(String batchId, Species species) { - - Preconditions.checkNotNull(batchId); + public void changeBenthosBatchSpecies(String id, Species species) { + Preconditions.checkNotNull(id); Preconditions.checkNotNull(species); Preconditions.checkNotNull(species.getReferenceTaxonId()); - - batchHelper.setSortingBatchReferenceTaxon(batchId, species.getReferenceTaxonId()); + batchHelper.changeBatchSpecies(id, species); } //------------------------------------------------------------------------// @@ -288,6 +290,9 @@ return frequencies; } + // Synchronization status + synchronizationStatusHelper.setDirty(catchBatch); + // Retrieve parent SortingBatch parentBatch = batchHelper.getSortingBatchById(catchBatch, sortingBatchId); @@ -310,7 +315,7 @@ target = SortingBatch.Factory.newInstance(); // Fill the sorting batch from the source - benthosBatchFrequencyToEntity(source, target, parentBatch, rankOrder); + beanToEntity(source, target, parentBatch, rankOrder); // Create the targeted batch, then update the source id batchHelper.createSortingBatch(source, catchBatch, target); @@ -321,7 +326,7 @@ target = batchHelper.getSortingBatchById(catchBatch, source.getIdAsInt()); // Fill the sorting batch from the source - benthosBatchFrequencyToEntity(source, target, parentBatch, rankOrder); + beanToEntity(source, target, parentBatch, rankOrder); // Add the batch into a list (will be update later, using this list) batchsToUpdate.add(target); @@ -331,11 +336,11 @@ } // If some batchs need to be update, do it - if (batchsToUpdate.size() > 0) { + if (CollectionUtils.isNotEmpty(batchsToUpdate)) { batchHelper.updateSortingBatch(batchsToUpdate, catchBatch); } - if (notUpdatedChildIds.size() > 0) { + if (CollectionUtils.isNotEmpty(notUpdatedChildIds)) { for (Integer batchId : notUpdatedChildIds) { batchHelper.removeWithChildren(batchId, catchBatch); } @@ -348,9 +353,9 @@ //-- Internal methods --// //------------------------------------------------------------------------// - protected BenthosBatch entityToBenthosBatch(SampleCategoryModel sampleCategoryModel, - SortingBatch source, - BenthosBatch target) { + protected BenthosBatch entityToBean(SampleCategoryModel sampleCategoryModel, + SortingBatch source, + BenthosBatch target) { Preconditions.checkNotNull(target.getSpecies()); @@ -403,7 +408,7 @@ SortingBatch sourceChild = (SortingBatch) batch; BenthosBatch targetChild = BenthosBatchs.newBenthosBatch(); targetChild.setSpecies(target.getSpecies()); - entityToBenthosBatch(sampleCategoryModel, sourceChild, targetChild); + entityToBean(sampleCategoryModel, sourceChild, targetChild); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch Hors Vrac > Benthos > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } @@ -421,15 +426,14 @@ return target; } - protected void benthosBatchToEntity(BenthosBatch source, - SortingBatch target, - String parentBatchId, - CatchBatch catchBatch) { + protected void beanToEntity(BenthosBatch source, + SortingBatch target, + String parentBatchId, + CatchBatch catchBatch) { Preconditions.checkNotNull(source.getFishingOperation()); Preconditions.checkNotNull(source.getFishingOperation().getId()); - Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements(); Collection<SortingMeasurement> sortingMeasurements = target.getSortingMeasurements(); @@ -563,10 +567,10 @@ } } - protected void benthosBatchFrequencyToEntity(BenthosBatchFrequency source, - SortingBatch target, - SortingBatch parentBatch, - short rankOrder) { + protected void beanToEntity(BenthosBatchFrequency source, + SortingBatch target, + SortingBatch parentBatch, + short rankOrder) { Preconditions.checkNotNull(source.getBatch()); Preconditions.checkNotNull(source.getBatch().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 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -33,7 +33,6 @@ import fr.ifremer.adagio.core.dao.data.operation.FishingOperationImpl; import fr.ifremer.adagio.core.dao.referential.QualityFlagCode; import fr.ifremer.adagio.core.dao.referential.QualityFlagImpl; -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; import fr.ifremer.tutti.persistence.service.util.BatchPersistenceHelper; @@ -105,37 +104,111 @@ batchTreeHelper.displayCatchBatch(source); CatchBatch result = new CatchBatchBean(); - result.setId(source.getId()); - result.setCatchTotalWeight(source.getWeight()); - result.setSynchronizationStatus(source.getSynchronizationStatus()); + entityToBean(source, result); + + return result; + } + + @Override + public CatchBatch createCatchBatch(CatchBatch bean) { + Preconditions.checkNotNull(bean); + Preconditions.checkArgument(bean.getId() == null); + Preconditions.checkNotNull(bean.getFishingOperation()); + Preconditions.checkNotNull(bean.getFishingOperation().getId()); + + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = fr.ifremer.adagio.core.dao.data.batch.CatchBatch.Factory.newInstance(); + beanToEntity(bean, catchBatch); + bean = batchHelper.createCatchBatch(bean, catchBatch); + + // Link to fishing operation + getCurrentSession().flush(); + Integer fishingOperationId = bean.getFishingOperation().getIdAsInt(); + int rowUpdated = queryUpdate("updateFishingOperationCatchBatch", + "fishingOperationId", IntegerType.INSTANCE, fishingOperationId, + "catchBatchId", IntegerType.INSTANCE, catchBatch.getId()); + if (rowUpdated == 0) { + throw new DataIntegrityViolationException("Could not attach catch batch to the given operation : operation was not found."); + } + + // bean is dirty + synchronizationStatusHelper.setDirty(bean); + return bean; + } + + @Override + public CatchBatch saveCatchBatch(CatchBatch bean) { + + Preconditions.checkNotNull(bean); + Preconditions.checkNotNull(bean.getId()); + Preconditions.checkNotNull(bean.getFishingOperation()); + Preconditions.checkNotNull(bean.getFishingOperation().getId()); + + getCurrentSession().enableFetchProfile("batch-with-childs"); + getCurrentSession().setFlushMode(FlushMode.COMMIT); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = load(CatchBatchImpl.class, bean.getIdAsInt()); + if (catchBatch == null) { + throw new DataRetrievalFailureException("Could not retrieve catch batch with id=" + bean.getId()); + } + + beanToEntity(bean, catchBatch); + batchHelper.update(catchBatch); + getCurrentSession().flush(); + + // bean is dirty + synchronizationStatusHelper.setDirty(bean); + return bean; + } + + @Override + public void deleteCatchBatch(String fishingOperationId) { + Preconditions.checkNotNull(fishingOperationId); + Integer catchBatchId = batchHelper.getCatchBatchIdByFishingOperationId(Integer.valueOf(fishingOperationId)); + + if (catchBatchId == null) { + throw new DataRetrievalFailureException("Could not retrieve catch batch for fishingOperation id=" + fishingOperationId); + } + + batchHelper.deleteCatchBatch(fishingOperationId, catchBatchId); + } + + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// + + protected void entityToBean(fr.ifremer.adagio.core.dao.data.batch.CatchBatch source, CatchBatch target) { + + target.setId(source.getId()); + target.setCatchTotalWeight(source.getWeight()); + target.setSynchronizationStatus(source.getSynchronizationStatus()); + // -- Vrac SortingBatch vracBatch = batchTreeHelper.getVracBatch(source); if (vracBatch != null) { - result.setCatchTotalSortedCarousselWeight(vracBatch.getWeight()); - result.setCatchTotalSortedTremisWeight(vracBatch.getWeightBeforeSampling()); + target.setCatchTotalSortedCarousselWeight(vracBatch.getWeight()); + target.setCatchTotalSortedTremisWeight(vracBatch.getWeightBeforeSampling()); // -- Vrac > Species SortingBatch vracSpeciesBatch = batchTreeHelper.getSpeciesVracRootBatch(vracBatch); if (vracSpeciesBatch != null) { - result.setSpeciesTotalSortedWeight(vracSpeciesBatch.getWeight()); + target.setSpeciesTotalSortedWeight(vracSpeciesBatch.getWeight()); // -- Vrac > Species > Inert SortingBatch inertBatch = batchTreeHelper.getSpeciesVracInertRootBatch(vracSpeciesBatch); if (inertBatch != null) { - result.setSpeciesTotalInertWeight(inertBatch.getWeight()); + target.setSpeciesTotalInertWeight(inertBatch.getWeight()); } // -- Vrac > Species > Alive not itemized SortingBatch livingNotItemizedBatch = batchTreeHelper.getSpeciesVracAliveNotItemizedRootBatch(vracSpeciesBatch); if (livingNotItemizedBatch != null) { - result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); + target.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); } } @@ -143,20 +216,20 @@ SortingBatch vracBenthosBatch = batchTreeHelper.getBenthosVracRootBatch(vracBatch); if (vracBenthosBatch != null) { - result.setBenthosTotalSortedWeight(vracBenthosBatch.getWeight()); + target.setBenthosTotalSortedWeight(vracBenthosBatch.getWeight()); // -- Vrac > Benthos > Inert SortingBatch inertBatch = batchTreeHelper.getBenthosVracInertRootBatch(vracBenthosBatch); if (inertBatch != null) { - result.setBenthosTotalInertWeight(inertBatch.getWeight()); + target.setBenthosTotalInertWeight(inertBatch.getWeight()); } // -- Vrac > Benthos > Alive no itemized SortingBatch livingNotItemizedBatch = batchTreeHelper.getBenthosVracAliveNotItemizedRootBatch(vracBenthosBatch); if (livingNotItemizedBatch != null) { - result.setBenthosTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); + target.setBenthosTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); } } } @@ -176,7 +249,7 @@ SortingBatch marineLitterBatch = batchTreeHelper.getMarineLitterRootBatch(horsVracBatch); if (marineLitterBatch != null) { - result.setMarineLitterTotalWeight(marineLitterBatch.getWeight()); + target.setMarineLitterTotalWeight(marineLitterBatch.getWeight()); } } @@ -184,80 +257,12 @@ SortingBatch unsortedBatch = batchTreeHelper.getRejectedBatch(source); if (unsortedBatch != null) { - result.setCatchTotalRejectedWeight(unsortedBatch.getWeight()); + target.setCatchTotalRejectedWeight(unsortedBatch.getWeight()); } - - return result; } - @Override - public CatchBatch createCatchBatch(CatchBatch bean) { - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(bean.getId() == null); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); - - bean.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue()); - - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = fr.ifremer.adagio.core.dao.data.batch.CatchBatch.Factory.newInstance(); - catchBatchToEntity(bean, catchBatch); - bean = batchHelper.createCatchBatch(bean, catchBatch); - - // Link to fishing operation - getCurrentSession().flush(); - Integer fishingOperationId = bean.getFishingOperation().getIdAsInt(); - int rowUpdated = queryUpdate("updateFishingOperationCatchBatch", - "fishingOperationId", IntegerType.INSTANCE, fishingOperationId, - "catchBatchId", IntegerType.INSTANCE, catchBatch.getId()); - if (rowUpdated == 0) { - throw new DataIntegrityViolationException("Could not attach catch batch to the given operation : operation was not found."); - } - - return bean; - } - - @Override - public CatchBatch saveCatchBatch(CatchBatch bean) { - - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(bean.getId()); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); - - bean.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue()); - - getCurrentSession().enableFetchProfile("batch-with-childs"); - getCurrentSession().setFlushMode(FlushMode.COMMIT); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = load(CatchBatchImpl.class, bean.getIdAsInt()); - if (catchBatch == null) { - throw new DataRetrievalFailureException("Could not retrieve catch batch with id=" + bean.getId()); - } - - catchBatchToEntity(bean, catchBatch); - batchHelper.update(catchBatch); - getCurrentSession().flush(); - - return bean; - } - - @Override - public void deleteCatchBatch(String fishingOperationId) { - Preconditions.checkNotNull(fishingOperationId); - Integer catchBatchId = batchHelper.getCatchBatchIdByFishingOperationId(Integer.valueOf(fishingOperationId)); - - if (catchBatchId == null) { - throw new DataRetrievalFailureException("Could not retrieve catch batch for fishingOperation id=" + fishingOperationId); - } - - batchHelper.deleteCatchBatch(fishingOperationId, catchBatchId); - } - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - - protected void catchBatchToEntity(CatchBatch source, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch target) { + protected void beanToEntity(CatchBatch source, + fr.ifremer.adagio.core.dao.data.batch.CatchBatch target) { Preconditions.checkNotNull(source.getFishingOperation()); Preconditions.checkNotNull(source.getFishingOperation().getId()); @@ -270,11 +275,8 @@ target.setQualityFlag(load(QualityFlagImpl.class, QualityFlagCode.NOTQUALIFIED.getValue())); target.setRankOrder((short) 1); - // SynchronizationStatus - String synchronizationStatus = SynchronizationStatus.DIRTY.getValue(); - target.setSynchronizationStatus(synchronizationStatus); - target.getFishingOperation().getFishingTrip().setSynchronizationStatus(synchronizationStatus); - target.getFishingOperation().getFishingTrip().getScientificCruise().setSynchronizationStatus(synchronizationStatus); + // Synchronization status + synchronizationStatusHelper.setDirty(target); // Create lists to store all updates, then remove not updated items Collection<QuantificationMeasurement> quantificationMeasurements = target.getQuantificationMeasurements(); @@ -484,7 +486,6 @@ batchTreeHelper.getOrCreateRejectedBatch( target, source.getCatchTotalRejectedWeight()); } - } } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -450,6 +450,7 @@ fishingOperationDao.create(fishingOperation); bean.setId(String.valueOf(fishingOperation.getId())); getCurrentSession().flush(); + return bean; } @@ -753,9 +754,7 @@ target.setFishingTrip(fishingTrip); // SynchronizationStatus - String synchronizationStatus = SynchronizationStatus.DIRTY.getValue(); - fishingTrip.setSynchronizationStatus(synchronizationStatus); - scientificCruise.setSynchronizationStatus(synchronizationStatus); + synchronizationStatusHelper.setDirty(fishingTrip); // Retrieve entities : VesselPosition (start and end) Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/IndividualObservationBatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/IndividualObservationBatchPersistenceServiceImpl.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/IndividualObservationBatchPersistenceServiceImpl.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -41,7 +41,6 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.MatrixId2; import fr.ifremer.adagio.core.dao.referential.pmfm.MatrixImpl; import fr.ifremer.adagio.core.dao.referential.taxon.ReferenceTaxonImpl; -import fr.ifremer.adagio.core.dao.technical.synchronization.SynchronizationStatus; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -56,7 +55,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.type.IntegerType; -import org.springframework.dao.DataRetrievalFailureException; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -158,6 +156,7 @@ beanToEntity(bean, sample, catchBatch); samplePersistenceHelper.create(sample); bean.setId(String.valueOf(sample.getId())); + synchronizationStatusHelper.setDirty(bean); return bean; } @@ -175,12 +174,10 @@ Batch catchBatch = getBatch(fishingOperation.getIdAsInt()); Sample sample = samplePersistenceHelper.load(bean.getIdAsInt()); - if (sample == null) { - throw new DataRetrievalFailureException( - "Could not retrieve sample id: " + bean.getId()); - } + beanToEntity(bean, sample, catchBatch); samplePersistenceHelper.update(sample); + synchronizationStatusHelper.setDirty(bean); return bean; } @@ -271,9 +268,6 @@ // Always attach to given vracSpecies batch target.setBatch(vracSpeciesBatch); - // Synchronization Status - target.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue()); - // Comment target.setComments(source.getComment()); 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 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/MarineLitterBatchPersistenceServiceImpl.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -114,7 +114,7 @@ SortingBatch source = (SortingBatch) batch1; MarineLitterBatch target = MarineLitterBatchs.newMarineLitterBatch(); - entityToMarineLitterBatch(source, target); + entityToBean(source, target); result.addChildren(target); if (log.isDebugEnabled()) { @@ -141,7 +141,7 @@ CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getId(), false); SortingBatch batch = SortingBatch.Factory.newInstance(); - marineLitterBatchToEntity(bean, batch, catchBatch); + beanToEntity(bean, batch, catchBatch); bean = batchHelper.createSortingBatch(bean, catchBatch, batch); return bean; @@ -154,7 +154,7 @@ Integer batchId = bean.getIdAsInt(); CatchBatch catchBatch = batchHelper.getRootCatchBatchByBatchId(batchId); SortingBatch batch = batchHelper.getSortingBatchById(catchBatch, batchId); - marineLitterBatchToEntity(bean, batch, catchBatch); + beanToEntity(bean, batch, catchBatch); batchHelper.updateSortingBatch(batch, catchBatch); return bean; @@ -163,13 +163,10 @@ @Override public void deleteMarineLitterBatch(String id) { Preconditions.checkNotNull(id); - - Integer batchId = Integer.valueOf(id); - batchHelper.removeWithChildren(batchId); + batchHelper.deleteBatch(id); } - public MarineLitterBatch entityToMarineLitterBatch(SortingBatch source, - MarineLitterBatch target) { + public MarineLitterBatch entityToBean(SortingBatch source, MarineLitterBatch target) { target.setId(source.getId().toString()); @@ -204,9 +201,9 @@ return target; } - protected void marineLitterBatchToEntity(MarineLitterBatch source, - SortingBatch target, - CatchBatch catchBatch) { + protected void beanToEntity(MarineLitterBatch source, + SortingBatch target, + CatchBatch catchBatch) { Preconditions.checkNotNull(source.getFishingOperation()); Preconditions.checkNotNull(source.getFishingOperation().getId()); 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 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -51,6 +51,8 @@ import fr.ifremer.tutti.persistence.service.util.BatchPersistenceHelper; import fr.ifremer.tutti.persistence.service.util.BatchTreeHelper; import fr.ifremer.tutti.persistence.service.util.MeasurementPersistenceHelper; +import fr.ifremer.tutti.persistence.service.util.SynchronizationStatusHelper; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.dao.DataIntegrityViolationException; @@ -90,6 +92,9 @@ @Resource(name = "measurementPersistenceHelper") protected MeasurementPersistenceHelper measurementPersistenceHelper; + @Resource(name = "synchronizationStatusHelper") + protected SynchronizationStatusHelper synchronizationStatusHelper; + //------------------------------------------------------------------------// //-- SpeciesBatch methods --// //------------------------------------------------------------------------// @@ -128,7 +133,7 @@ SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); target.setSpecies(species); - entityToSpeciesBatch(sampleCategoryModel, source, target); + entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { @@ -154,7 +159,7 @@ } SpeciesBatch target = SpeciesBatchs.newSpeciesBatch(); target.setSpecies(species); - entityToSpeciesBatch(sampleCategoryModel, source, target); + entityToBean(sampleCategoryModel, source, target); result.addChildren(target); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch Hors Vrac > Species > " + target.getSpecies().getReferenceTaxonId() + ": " + target.getId()); @@ -183,7 +188,7 @@ CatchBatch catchBatch = batchHelper.getRootCatchBatchByFishingOperationId(bean.getFishingOperation().getId(), false); SortingBatch batch = SortingBatch.Factory.newInstance(); - speciesBatchToEntity(bean, batch, parentBatchId, catchBatch); + beanToEntity(bean, batch, parentBatchId, catchBatch); bean = batchHelper.createSortingBatch(bean, catchBatch, batch); return bean; @@ -202,7 +207,7 @@ if (bean.getParentBatch() != null) { parentBatchId = bean.getParentBatch().getId(); } - speciesBatchToEntity(bean, batch, parentBatchId, catchBatch); + beanToEntity(bean, batch, parentBatchId, catchBatch); batchHelper.updateSortingBatch(batch, catchBatch); return bean; @@ -211,26 +216,21 @@ @Override public void deleteSpeciesBatch(String id) { Preconditions.checkNotNull(id); - - Integer batchId = Integer.valueOf(id); - batchHelper.removeWithChildren(batchId); + batchHelper.deleteBatch(id); } @Override public void deleteSpeciesSubBatch(String id) { + Preconditions.checkNotNull(id); batchHelper.deleteSpeciesSubBatch(id); } @Override - public void changeSpeciesBatchSpecies(String batchId, Species species) { - - Preconditions.checkNotNull(batchId); + public void changeSpeciesBatchSpecies(String id, Species species) { + Preconditions.checkNotNull(id); Preconditions.checkNotNull(species); Preconditions.checkNotNull(species.getReferenceTaxonId()); - - batchHelper.setSortingBatchReferenceTaxon( - batchId, - species.getReferenceTaxonId()); + batchHelper.changeBatchSpecies(id, species); } //------------------------------------------------------------------------// @@ -308,6 +308,9 @@ return notNullFrequencies; } + // Synchronization status + synchronizationStatusHelper.setDirty(catchBatch); + // Retrieve parent SortingBatch parentBatch = batchHelper.getSortingBatchById(catchBatch, sortingBatchId); @@ -330,7 +333,7 @@ target = SortingBatch.Factory.newInstance(); // Fill the sorting batch from the source - speciesBatchFrequencyToEntity(source, target, parentBatch, rankOrder); + beanToEntity(source, target, parentBatch, rankOrder); // Create the targeted batch, then update the source id batchHelper.createSortingBatch(source, catchBatch, target); @@ -347,7 +350,7 @@ target = batchHelper.loadSortingBatch(source.getIdAsInt(), catchBatch); // Fill the sorting batch from the source - speciesBatchFrequencyToEntity(source, target, parentBatch, rankOrder); + beanToEntity(source, target, parentBatch, rankOrder); // Add the batch into a list (will be update later, using this list) batchsToUpdate.add(target); @@ -361,13 +364,13 @@ } } - if (batchsToUpdate.size() > 0) { + if (CollectionUtils.isNotEmpty(batchsToUpdate)) { // update some batchs batchHelper.updateSortingBatch(batchsToUpdate, catchBatch); } - if (notUpdatedChildIds.size() > 0) { + if (CollectionUtils.isNotEmpty(notUpdatedChildIds)) { // Remove obsolete frequencies for (Integer batchId : notUpdatedChildIds) { @@ -386,8 +389,8 @@ //-- Internal methods --// //------------------------------------------------------------------------// - protected SpeciesBatch entityToSpeciesBatch(SampleCategoryModel sampleCategoryModel, SortingBatch source, - SpeciesBatch target) { + protected SpeciesBatch entityToBean(SampleCategoryModel sampleCategoryModel, SortingBatch source, + SpeciesBatch target) { Preconditions.checkNotNull(target.getSpecies()); @@ -441,7 +444,7 @@ SortingBatch sourceChild = (SortingBatch) batch; SpeciesBatch targetChild = SpeciesBatchs.newSpeciesBatch(); targetChild.setSpecies(target.getSpecies()); - entityToSpeciesBatch(sampleCategoryModel, sourceChild, targetChild); + entityToBean(sampleCategoryModel, sourceChild, targetChild); if (log.isDebugEnabled()) { log.debug("Loaded CatchBatch (Vrac|Hors Vrac) > Species > " + targetChild.getSpecies().getReferenceTaxonId() + " : " + target.getId()); } @@ -459,10 +462,10 @@ return target; } - protected void speciesBatchToEntity(SpeciesBatch source, - SortingBatch target, - String parentBatchId, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { + protected void beanToEntity(SpeciesBatch source, + SortingBatch target, + String parentBatchId, + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { Preconditions.checkNotNull(source.getFishingOperation()); Preconditions.checkNotNull(source.getFishingOperation().getId()); @@ -603,10 +606,10 @@ } } - protected void speciesBatchFrequencyToEntity(SpeciesBatchFrequency source, - SortingBatch target, - SortingBatch parentBatch, - short rankOrder) { + protected void beanToEntity(SpeciesBatchFrequency source, + SortingBatch target, + SortingBatch parentBatch, + short rankOrder) { Preconditions.checkNotNull(source.getBatch()); Preconditions.checkNotNull(source.getBatch().getId()); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -36,6 +36,8 @@ import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationError; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement; +import fr.ifremer.adagio.core.dao.data.operation.FishingOperation; +import fr.ifremer.adagio.core.dao.data.operation.FishingOperationDao; import fr.ifremer.adagio.core.dao.referential.pmfm.ObjectTypeCode2; import fr.ifremer.adagio.core.dao.referential.pmfm.Pmfm; import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId2; @@ -51,6 +53,7 @@ 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.service.AbstractPersistenceService; import fr.ifremer.tutti.persistence.service.AttachmentPersistenceService; import fr.ifremer.tutti.persistence.service.IndividualObservationBatchPersistenceService; @@ -99,12 +102,18 @@ @Resource(name = "sortingBatchDao") protected SortingBatchDao sortingBatchDao; + @Resource(name = "fishingOperationDao") + protected FishingOperationDao fishingOperationDao; + @Resource(name = "scientificCruiseCatchBatchValidator") protected TuttiCatchBatchValidator catchBatchValidator; @Resource(name = "batchTreeHelper") protected BatchTreeHelper batchTreeHelper; + @Resource(name = "synchronizationStatusHelper") + protected SynchronizationStatusHelper synchronizationStatusHelper; + @Override public void init() { super.init(); @@ -163,6 +172,10 @@ getCurrentSession().flush(); + // SynchronizationStatus on fishingTrip + FishingOperation fishingOperation = fishingOperationDao.load(Integer.valueOf(fishingOperationId)); + synchronizationStatusHelper.setDirty(fishingOperation.getFishingTrip()); + // get all catch batch children ids (to delete attachments) List<Integer> ids = catchBatchDao.getAllChildrenIds(catchBatchId); @@ -176,6 +189,8 @@ } public <D extends TuttiEntity> D createSortingBatch(D bean, CatchBatch catchBatch, SortingBatch batch) { + // Synchronization status + synchronizationStatusHelper.setDirty(catchBatch); batch = catchBatchDao.createSortingBatch(batch, catchBatch); bean.setId(batch.getId()); return bean; @@ -213,15 +228,13 @@ catchBatchDao.update(catchBatch); } - public void setSortingBatchReferenceTaxon(String batchId, Integer referenceTaxonId) { - catchBatchDao.setSortingBatchReferenceTaxon(batchId, referenceTaxonId); - } - public SortingBatch getSortingBatchById(CatchBatch catchBatch, Integer sortingBatchId) { return catchBatchDao.getSortingBatchById(catchBatch, sortingBatchId); } public void updateSortingBatch(SortingBatch sortingBatch, CatchBatch parentCatchBatch) { + // Synchronization status + synchronizationStatusHelper.setDirty(parentCatchBatch); catchBatchDao.updateSortingBatch(sortingBatch, parentCatchBatch); } @@ -489,12 +502,25 @@ return qualitativeValueId; } + public void deleteBatch(String id) { + Preconditions.checkNotNull(id); + + Integer batchId = Integer.valueOf(id); + + CatchBatch catchBatch = getRootCatchBatchByBatchId(batchId); + synchronizationStatusHelper.setDirty(catchBatch); + + removeWithChildren(batchId); + } + public void deleteSpeciesSubBatch(String id) { Preconditions.checkNotNull(id); Integer speciesBatchId = Integer.valueOf(id); CatchBatch catchBatch = getRootCatchBatchByBatchId(speciesBatchId); + synchronizationStatusHelper.setDirty(catchBatch); + SortingBatch sortingBatch = getSortingBatchById(catchBatch, speciesBatchId); // get his children @@ -515,10 +541,19 @@ } } -// protected Integer getSortingTypeId() { -// return Integer.valueOf(PmfmId2.SCIENTIFIC_CRUISE_SORTING_TYPE.getValue()); -// } + public void changeBatchSpecies(String id, Species species) { + Preconditions.checkNotNull(id); + Preconditions.checkNotNull(species); + Preconditions.checkNotNull(species.getReferenceTaxonId()); + + Integer batchId = Integer.valueOf(id); + CatchBatch catchBatch = getRootCatchBatchByBatchId(batchId); + synchronizationStatusHelper.setDirty(catchBatch); + + catchBatchDao.setSortingBatchReferenceTaxon(id, species.getReferenceTaxonId()); + } + public <S extends SpeciesAbleBatch> void setSampleCategoryQualitative(S target, Integer pmfmId, Float numericalvalue, Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SamplePersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SamplePersistenceHelper.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SamplePersistenceHelper.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -39,6 +39,7 @@ import fr.ifremer.tutti.persistence.service.AttachmentPersistenceService; import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService; import org.hibernate.type.IntegerType; +import org.springframework.dao.DataRetrievalFailureException; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -64,31 +65,47 @@ @Resource(name = "attachmentPersistenceService") protected AttachmentPersistenceService attachmentPersistenceService; + @Resource(name = "synchronizationStatusHelper") + protected SynchronizationStatusHelper synchronizationStatusHelper; + @Resource(name = "sampleDao") protected SampleDao sampleDao; public Sample create(Sample sample) { + + // Synchronization Status + synchronizationStatusHelper.setDirty(sample); + return sampleDao.create(sample); } public void update(Sample sample) { + + // Synchronization Status + synchronizationStatusHelper.setDirty(sample); + sampleDao.update(sample); } public Sample load(Integer id) { - return sampleDao.load(id); + Sample sample = sampleDao.load(id); + if (sample == null) { + throw new DataRetrievalFailureException( + "Could not retrieve sample id=" + id); + } + return sample; } public void deleteSample(Integer sampleId) { - Sample sample = sampleDao.load(sampleId); - if (sample != null) { - sample.getSampleMeasurements().clear(); - sampleDao.remove(sample); - attachmentPersistenceService.deleteAllAttachment( - ObjectTypeCode2.SAMPLE, - sampleId); - } + Sample sample = load(sampleId); + + // Synchronization Status + synchronizationStatusHelper.setDirty(sample); + + sample.getSampleMeasurements().clear(); + sampleDao.remove(sample); + attachmentPersistenceService.deleteAllAttachment(ObjectTypeCode2.SAMPLE, sampleId); } public void setSampleMeasurements(Sample target, Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SynchronizationStatusHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SynchronizationStatusHelper.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/SynchronizationStatusHelper.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -6,6 +6,8 @@ import fr.ifremer.adagio.core.dao.data.survey.fishingTrip.FishingTrip; import fr.ifremer.adagio.core.dao.data.survey.scientificCruise.ScientificCruise; import fr.ifremer.adagio.core.dao.technical.synchronization.SynchronizationStatus; +import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; +import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; import fr.ifremer.tutti.persistence.service.AbstractPersistenceService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,24 +32,36 @@ public void setDirty(ScientificCruise scientificCruise) { String synchronizationStatus = getDirtyValue(); + if (log.isInfoEnabled()) { + log.info("SetDirty scientificCruise: " + scientificCruise.getId()); + } scientificCruise.setSynchronizationStatus(synchronizationStatus); } public void setDirty(FishingTrip fishingTrip) { String synchronizationStatus = getDirtyValue(); fishingTrip.setSynchronizationStatus(synchronizationStatus); + if (log.isInfoEnabled()) { + log.info("SetDirty fishingTrip: " + fishingTrip.getId()); + } setDirty(fishingTrip.getScientificCruise()); } public void setDirty(CatchBatch catchBatch) { String synchronizationStatus = getDirtyValue(); catchBatch.setSynchronizationStatus(synchronizationStatus); + if (log.isInfoEnabled()) { + log.info("SetDirty catchBatch: " + catchBatch.getId()); + } setDirty(catchBatch.getFishingOperation().getFishingTrip()); } public void setDirty(Sample sample) { String synchronizationStatus = getDirtyValue(); sample.setSynchronizationStatus(synchronizationStatus); + if (log.isInfoEnabled()) { + log.info("SetDirty sample: " + sample.getId()); + } Batch batch = sample.getBatch(); if (batch != null && batch instanceof CatchBatch) { setDirty((CatchBatch) batch); @@ -61,6 +75,10 @@ String oldStatus = getDirtyValue(); String newStatus = SynchronizationStatus.READY_TO_SYNCHRONIZE.getValue(); + if (log.isInfoEnabled()) { + log.info("setCruiseReadyToSynch cruise: " + cruiseId); + } + // update scientificCruise int scientificCruiseQueryUpdate = queryUpdate("updateScientificCruiseSynchronizationStatus", "cruiseId", IntegerType.INSTANCE, cruiseId, @@ -104,4 +122,16 @@ protected String getDirtyValue() { return SynchronizationStatus.DIRTY.getValue(); } + + public void setDirty(fr.ifremer.tutti.persistence.entities.data.CatchBatch bean) { + bean.setSynchronizationStatus(getDirtyValue()); + } + + public void setDirty(IndividualObservationBatch bean) { + bean.setSynchronizationStatus(getDirtyValue()); + } + + public void setDirty(AccidentalBatch bean) { + bean.setSynchronizationStatus(getDirtyValue()); + } } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -438,6 +438,17 @@ return cruise; } + public Cruise reloadCruise() { + checkOpened(); + Preconditions.checkState(isCruiseFilled()); + String id = getCruiseId(); + if (log.isInfoEnabled()) { + log.info("Loading cruise: " + id); + } + cruise = service.getCruise(id); + return cruise; + } + public TuttiProtocol getProtocol() { checkOpened(); if (isProtocolFilled()) { Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -47,6 +47,7 @@ import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.ValidationService; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections4.MapUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -306,9 +307,11 @@ errors.add(e.getMessage()); } - Map<String, List<String>> errorMap = Maps.newHashMap(); - errorMap.put("catches", errors); - validator.addMessagesForScope(NuitonValidatorScope.ERROR, errorMap); + if (CollectionUtils.isNotEmpty(errors)) { + Map<String, List<String>> errorMap = Maps.newHashMap(); + errorMap.put("catches", errors); + validator.addMessagesForScope(NuitonValidatorScope.ERROR, errorMap); + } TuttiDataContext dataContext = context.getDataContext(); if (dataContext.isProtocolFilled()) { @@ -346,7 +349,9 @@ } } - validator.addMessagesForScope(NuitonValidatorScope.WARNING, warningMap); + if (MapUtils.isNotEmpty(warningMap)) { + validator.addMessagesForScope(NuitonValidatorScope.WARNING, warningMap); + } } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseAction.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseAction.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -154,7 +154,8 @@ Cruise bean = model.toBean(); Cruise saved; - if (TuttiEntities.isNew(bean)) { + boolean createCruise = TuttiEntities.isNew(bean); + if (createCruise) { saved = persistenceService.createCruise(bean); model.setId(saved.getId()); @@ -167,6 +168,12 @@ context.setProgramId(saved.getProgram().getId()); context.setCruiseId(saved.getId()); + if (!createCruise) { + + // reload cruise + getDataContext().reloadCruise(); + } + // update originalRankOrder for all gears of the cruise for (GearWithOriginalRankOrder gear : model.getGear()) { gear.setOriginalRankOrder(gear.getRankOrder()); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseToReadyToSynchAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseToReadyToSynchAction.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/SaveCruiseToReadyToSynchAction.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -59,7 +59,11 @@ @Override public void postSuccessAction() { super.postSuccessAction(); - // can't synch anylonger - getModel().setReadyToSynch(false); + + // reload cruise in data context + getDataContext().reloadCruise(); + + // reload it in our model + getModel().setCruise(getDataContext().getCruise()); } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/ValidateCruiseUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/ValidateCruiseUIModel.java 2014-04-25 11:39:08 UTC (rev 1735) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/ValidateCruiseUIModel.java 2014-04-28 11:17:10 UTC (rev 1736) @@ -98,11 +98,25 @@ boolean result = Cruises.isDirty(cruise); if (result) { for (NuitonValidatorResult nuitonValidatorResult : validator.values()) { - if (nuitonValidatorResult.hasErrorMessagess() || nuitonValidatorResult.hasFatalMessages()) { + if (nuitonValidatorResult.hasErrorMessagess() ) { result = false; + if (log.isInfoEnabled()) { + log.info("there is some errors: "+nuitonValidatorResult.getFieldsForError()); + } break; } + if ( nuitonValidatorResult.hasFatalMessages()) { + result = false; + if (log.isInfoEnabled()) { + log.info("there is some fatal errors: "+nuitonValidatorResult.getFieldsForFatal()); + } + break; + } } + } else { + if (log.isInfoEnabled()) { + log.info("Cruise is not dirty"); + } } if (log.isInfoEnabled()) { log.info("New readyToSynch value: " + result);
participants (1)
-
tchemit@users.forge.codelutin.com