r784 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos
Author: tchemit Date: 2013-04-15 22:31:51 +0200 (Mon, 15 Apr 2013) New Revision: 784 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/784 Log: fixes #2269: [BENTHOS] - Erreur ?\195?\160 la cr?\195?\169ation d'un lot fixes #2270: [BENTHOS] - Suite de l'erreur pr?\195?\169c?\195?\169dente vf pi?\195?\168ce jointe, il a cr?\195?\169er 2 lots jumeaux 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/SpeciesBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 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-15 20:27:37 UTC (rev 783) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-15 20:31:51 UTC (rev 784) @@ -449,13 +449,11 @@ protected void benthosBatchToEntity(BenthosBatch source, SortingBatch target, String parentBatchId, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { + CatchBatch catchBatch) { Preconditions.checkNotNull(source.getFishingOperation()); Preconditions.checkNotNull(source.getFishingOperation().getId()); - Integer batchPmfm = enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS; - // Retrieve recorder department Integer recorderDepartmentId = batchHelper.getRecorderDepartmentId(); @@ -477,7 +475,13 @@ if (target.getId() == null || target.getRootBatch() == null || (target.getParentBatch() != null && !target.getParentBatch().getId().toString().equals(parentBatchId))) { - setBatchParents(source, target, parentBatchId, catchBatch, batchPmfm); + batchHelper.setBatchParents( + source.getSampleCategoryType(), + source.getSampleCategoryValue(), + target, + parentBatchId, + catchBatch, + enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); } // RankOrder (initialize once, at creation) @@ -571,52 +575,52 @@ } } - protected void setBatchParents(BenthosBatch source, - SortingBatch target, - String parentBatchIdStr, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, - Integer batchPmfmId) { +// protected void setBatchParents(BenthosBatch source, +// SortingBatch target, +// String parentBatchIdStr, +// fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, +// Integer batchPmfmId) { +// +// Preconditions.checkNotNull(target); +// Preconditions.checkNotNull(source.getFishingOperation()); +// Preconditions.checkNotNull(source.getFishingOperation().getId()); +// +// SortingBatch parentBatch; +// if (parentBatchIdStr != null) { +// +// // Load existing parent and root +// parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); +// } else { +// +// // Or retrieve parent batch, from pmfm id +// // Retrieve category type +// Integer pmfmId = source.getSampleCategoryType().getFieldValue(); +// if (pmfmId == null || !pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { +// throw new DataIntegrityViolationException(MessageFormat.format( +// "A species batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", +// SampleCategoryEnum.sortedUnsorted.name(), +// enumeration.PMFM_ID_SORTED_UNSORTED)); +// } +// Integer qualitativeValueId = batchHelper.convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue()); +// +// parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), +// BatchPersistenceHelper.BATCH_PMFM_ID, pmfmId, qualitativeValueId, // vrac | hors vrac +// BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId, // species | Benthos +// BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED // vivant trié +// ); +// } +// +// +// 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 BenthosBatch."); +// } +// +// // Parent Batch +// target.setParentBatch(parentBatch); +// target.setRootBatch(catchBatch); +// } - Preconditions.checkNotNull(target); - Preconditions.checkNotNull(source.getFishingOperation()); - Preconditions.checkNotNull(source.getFishingOperation().getId()); - - SortingBatch parentBatch; - if (parentBatchIdStr != null) { - - // Load existing parent and root - parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); - } else { - - // Or retrieve parent batch, from pmfm id - // Retrieve category type - Integer pmfmId = source.getSampleCategoryType().getFieldValue(); - if (pmfmId == null || !pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { - throw new DataIntegrityViolationException(MessageFormat.format( - "A species batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", - SampleCategoryEnum.sortedUnsorted.name(), - enumeration.PMFM_ID_SORTED_UNSORTED)); - } - Integer qualitativeValueId = batchHelper.convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue()); - - parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), - BatchPersistenceHelper.BATCH_PMFM_ID, pmfmId, qualitativeValueId, // vrac | hors vrac - BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId, // species | Benthos - BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED // vivant trié - ); - } - - - 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 BenthosBatch."); - } - - // Parent Batch - target.setParentBatch(parentBatch); - target.setRootBatch(catchBatch); - } - protected void benthosBatchFrequencyToEntity(BenthosBatchFrequency source, SortingBatch target, SortingBatch parentBatch, 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-15 20:27:37 UTC (rev 783) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/CatchBatchPersistenceServiceImpl.java 2013-04-15 20:31:51 UTC (rev 784) @@ -610,7 +610,7 @@ { Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE); - + batch.setChildBatchs(Lists.<Batch>newArrayList()); // ----------------------------------------------------------------------------- // Hors Vrac > Species // ----------------------------------------------------------------------------- @@ -618,11 +618,12 @@ SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); if (speciesBatch == null) { speciesBatch = SortingBatch.Factory.newInstance(); - if (batch.getChildBatchs() == null) { - batch.setChildBatchs(Lists.newArrayList((Batch) speciesBatch)); - } else { - batch.getChildBatchs().add(speciesBatch); - } + batch.getChildBatchs().add(speciesBatch); +// if (batch.getChildBatchs() == null) { +// batch.setChildBatchs(Lists.newArrayList((Batch) speciesBatch)); +// } else { +// batch.getChildBatchs().add(speciesBatch); +// } } beanToEntitySortingBatch(target, 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-15 20:27:37 UTC (rev 783) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-15 20:31:51 UTC (rev 784) @@ -533,8 +533,6 @@ Preconditions.checkNotNull(source.getFishingOperation()); Preconditions.checkNotNull(source.getFishingOperation().getId()); - Integer batchPmfm = enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES; - // Retrieve recorder department Integer recorderDepartmentId = batchHelper.getRecorderDepartmentId(); @@ -556,7 +554,14 @@ if (target.getId() == null || target.getRootBatch() == null || (target.getParentBatch() != null && !target.getParentBatch().getId().toString().equals(parentBatchId))) { - setBatchParents(source, target, parentBatchId, catchBatch, batchPmfm); + + batchHelper.setBatchParents( + source.getSampleCategoryType(), + source.getSampleCategoryValue(), + target, + parentBatchId, + catchBatch, + enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); } // RankOrder (initialize once, at creation) @@ -650,52 +655,52 @@ } } - protected void setBatchParents(SpeciesBatch source, - SortingBatch target, - String parentBatchIdStr, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, - Integer batchPmfmId) { +// protected void setBatchParents(SpeciesBatch source, +// SortingBatch target, +// String parentBatchIdStr, +// fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, +// Integer batchPmfmId) { +// +// Preconditions.checkNotNull(target); +// Preconditions.checkNotNull(source.getFishingOperation()); +// Preconditions.checkNotNull(source.getFishingOperation().getId()); +// +// SortingBatch parentBatch; +// if (parentBatchIdStr != null) { +// +// // Load existing parent and root +// parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); +// } else { +// +// // Or retrieve parent batch, from pmfm id +// // Retrieve category type +// Integer pmfmId = source.getSampleCategoryType().getFieldValue(); +// if (pmfmId == null || !pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { +// throw new DataIntegrityViolationException(MessageFormat.format( +// "A species batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", +// SampleCategoryEnum.sortedUnsorted.name(), +// enumeration.PMFM_ID_SORTED_UNSORTED)); +// } +// Integer qualitativeValueId = batchHelper.convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue()); +// +// parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), +// BatchPersistenceHelper.BATCH_PMFM_ID, pmfmId, qualitativeValueId, // vrac | hors vrac +// BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId, // species | Benthos +// BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED // vivant trié +// ); +// } +// +// +// 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."); +// } +// +// // Parent Batch +// target.setParentBatch(parentBatch); +// target.setRootBatch(catchBatch); +// } - Preconditions.checkNotNull(target); - Preconditions.checkNotNull(source.getFishingOperation()); - Preconditions.checkNotNull(source.getFishingOperation().getId()); - - SortingBatch parentBatch; - if (parentBatchIdStr != null) { - - // Load existing parent and root - parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); - } else { - - // Or retrieve parent batch, from pmfm id - // Retrieve category type - Integer pmfmId = source.getSampleCategoryType().getFieldValue(); - if (pmfmId == null || !pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { - throw new DataIntegrityViolationException(MessageFormat.format( - "A species batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", - SampleCategoryEnum.sortedUnsorted.name(), - enumeration.PMFM_ID_SORTED_UNSORTED)); - } - Integer qualitativeValueId = batchHelper.convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue()); - - parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), - BatchPersistenceHelper.BATCH_PMFM_ID, pmfmId, qualitativeValueId, // vrac | hors vrac - BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId, // species | Benthos - BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED // vivant trié - ); - } - - - 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."); - } - - // Parent Batch - target.setParentBatch(parentBatch); - target.setRootBatch(catchBatch); - } - protected void speciesBatchFrequencyToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, 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-15 20:27:37 UTC (rev 783) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-04-15 20:31:51 UTC (rev 784) @@ -42,10 +42,12 @@ import fr.ifremer.tutti.persistence.service.ReferentialPersistenceService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.io.Serializable; +import java.text.MessageFormat; import java.util.List; /** @@ -120,6 +122,66 @@ return result; } + public void setBatchParents(SampleCategoryEnum sampleCategoryType, + Serializable sampleCategoryValue, + SortingBatch target, + String parentBatchIdStr, + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, + Integer batchPmfmId) { + + Preconditions.checkNotNull(target); + + SortingBatch parentBatch; + if (parentBatchIdStr != null) { + + // Load existing parent and root + parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); + } else { + + // Or retrieve parent batch, from pmfm id + // Retrieve category type + if (!sampleCategoryType.equals(SampleCategoryEnum.sortedUnsorted)) { + throw new DataIntegrityViolationException(MessageFormat.format( + "A benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", + SampleCategoryEnum.sortedUnsorted.name(), + enumeration.PMFM_ID_SORTED_UNSORTED)); + } + + Integer qualitativeValueId = convertSampleCategoryValueIntoQualitativeId(sampleCategoryValue); + + if (enumeration.QUALITATIVE_VRAC_ID.equals(qualitativeValueId)) { + + // vrac + parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, // vrac + BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId, // Species | Benthos + BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE_2, enumeration.QUALITATIVE_ID_SORTING_TYPE_2_ALIVE_ITEMIZED // vivant trié + ); + } else if (enumeration.QUALITATIVE_HORS_VRAC_ID.equals(qualitativeValueId)) { + + // hors-vrac + parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), + BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, // hors vrac + BatchPersistenceHelper.BATCH_PMFM_ID, enumeration.PMFM_ID_SORTING_TYPE, batchPmfmId // Species | Benthos + ); + } else { + + // not possible + throw new DataIntegrityViolationException("Should have Vrac / Hor Vrac qualitative value, but had: " + qualitativeValueId); + } + + } + + if (parentBatch == null) { + throw new DataIntegrityViolationException( + "Could not retrieve parent batch, for a given speciesBatch or benthosBatch : invalid batch tree structure. Please make sure CatchBatch has been saved before to create a such batch."); + } + + // Parent Batch + target.setParentBatch(parentBatch); + target.setRootBatch(catchBatch); + } + // public SpeciesBatch entityToSpeciesBatch(SortingBatch source, // SpeciesBatch target) { // Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-04-15 20:27:37 UTC (rev 783) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-04-15 20:31:51 UTC (rev 784) @@ -657,28 +657,28 @@ parent.getHandler().setBenthosSelectedCard(EditCatchesUIHandler.CREATE_BATCH_CARD); } - public void addBatch(CreateBenthosBatchUIModel speciesBatchRootRowModel) { - if (speciesBatchRootRowModel.isValid()) { + public void addBatch(CreateBenthosBatchUIModel bethosBatchRootRowModel) { + if (bethosBatchRootRowModel.isValid()) { BenthosBatchTableModel tableModel = getTableModel(); BenthosBatchRowModel newRow = tableModel.createNewRow(); - Species species = speciesBatchRootRowModel.getSpecies(); + Species species = bethosBatchRootRowModel.getSpecies(); newRow.setSpecies(species); - CaracteristicQualitativeValue sortedUnsortedCategory = speciesBatchRootRowModel.getSortedUnsortedCategory(); + CaracteristicQualitativeValue sortedUnsortedCategory = bethosBatchRootRowModel.getSortedUnsortedCategory(); SampleCategory<CaracteristicQualitativeValue> category = newRow.getSortedUnsortedCategory(); category.setCategoryValue(sortedUnsortedCategory); - category.setCategoryWeight(speciesBatchRootRowModel.getBatchWeight()); + category.setCategoryWeight(bethosBatchRootRowModel.getBatchWeight()); newRow.setSampleCategory(category); recomputeRowValidState(newRow); + saveRow(newRow); + tableModel.addNewRow(newRow); AbstractSelectTableAction.doSelectCell(getTable(), tableModel.getRowCount() - 1, 0); - saveRow(newRow); - // update speciesUsed addToSpeciesUsed(newRow); }
participants (1)
-
tchemit@users.forge.codelutin.com