Author: tchemit Date: 2013-04-15 22:48:35 +0200 (Mon, 15 Apr 2013) New Revision: 785 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/785 Log: clean some codes 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/SpeciesBatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.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:31:51 UTC (rev 784) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BenthosBatchPersistenceServiceImpl.java 2013-04-15 20:48:35 UTC (rev 785) @@ -43,8 +43,6 @@ import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; 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.batch.BatchPersistenceHelper; import org.apache.commons.logging.Log; @@ -55,7 +53,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.text.MessageFormat; +import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -575,52 +573,6 @@ } } -// 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); -// } - protected void benthosBatchFrequencyToEntity(BenthosBatchFrequency source, SortingBatch target, SortingBatch parentBatch, @@ -711,26 +663,32 @@ 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); + Serializable categoryValue = batchHelper.getSampleCategoryQualitative( + pmfmId, + numericalvalue, + alphanumericalValue, + qualitativeValueId); + target.setSampleCategoryValue(categoryValue); +// 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); } } 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:31:51 UTC (rev 784) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/SpeciesBatchPersistenceServiceImpl.java 2013-04-15 20:48:35 UTC (rev 785) @@ -43,8 +43,6 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.service.batch.BatchPersistenceHelper; import org.apache.commons.collections.CollectionUtils; @@ -56,7 +54,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.text.MessageFormat; +import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -655,52 +653,6 @@ } } -// 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); -// } - protected void speciesBatchFrequencyToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, @@ -791,27 +743,33 @@ 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); + Serializable categoryValue = batchHelper.getSampleCategoryQualitative( + pmfmId, + numericalvalue, + alphanumericalValue, + qualitativeValueId); + target.setSampleCategoryValue(categoryValue); +// 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); } } 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:31:51 UTC (rev 784) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-04-15 20:48:35 UTC (rev 785) @@ -142,7 +142,7 @@ // 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})", + "A species or benthos batch with no parent should have a sampleCategoryType {0} (PMFM.ID={1})", SampleCategoryEnum.sortedUnsorted.name(), enumeration.PMFM_ID_SORTED_UNSORTED)); } @@ -182,347 +182,6 @@ target.setRootBatch(catchBatch); } -// public SpeciesBatch entityToSpeciesBatch(SortingBatch source, -// SpeciesBatch target) { -// -// target.setId(source.getId().toString()); -// -// // Individual count -// target.setNumber(source.getIndividualCount()); -// -// // Convert database weight (and sampling ratio) into UI weight and sampleCategoryWeight -// if (source.getWeight() != null && source.getWeightBeforeSampling() == null) { -// target.setSampleCategoryWeight(source.getWeight()); -// } else { -// target.setWeight(source.getWeight()); -// target.setSampleCategoryWeight(source.getWeightBeforeSampling()); -// } -// -// // Comments -// target.setComment(source.getComments()); -// -// // Sample category type (only one is applied) -// SortingMeasurement sm = null; -// if (source.getSortingMeasurements().size() == 1) { -// sm = source.getSortingMeasurements().iterator().next(); -// } else if (source.getReferenceTaxon() != null && source.getReferenceTaxon().getId() != null) { -// sm = catchBatchDao.getInheritedSortingMeasurement(source, enumeration.PMFM_ID_SORTED_UNSORTED); -// } -// if (sm != null) { -// SampleCategoryEnum sampleCategory = enumeration.getSampleCategoryByPmfmId(sm.getPmfm().getId()); -// if (sampleCategory != null) { -// Integer qualitativeId = null; -// if (sm.getQualitativeValue() != null) { -// qualitativeId = sm.getQualitativeValue().getId(); -// } -// setSampleCategoryQualitative(target, sm.getPmfm().getId(), sm.getNumericalValue(), sm.getAlphanumericalValue(), qualitativeId); -// } -// } -// -// // Species -// Integer referenceTaxonId = source.getInheritedReferenceTaxonId(); -// if (referenceTaxonId == null && source.getReferenceTaxon() != null) { -// referenceTaxonId = source.getReferenceTaxon().getId(); -// } -// if (referenceTaxonId != null) { -// // TODO : add cache on getSpeciesByReferenceTaxonId -// Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId); -// target.setSpecies(species); -// } -// //FIXME-TC Check the test is still ok? -// //FIXME-TC We should a stronger test -//// if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) { -// if (target.getSampleCategoryType() != null) { -// List<SpeciesBatch> targetChilds = Lists.newArrayList(); -// for (Batch batch : source.getChildBatchs()) { -// SortingBatch sourceChild = (SortingBatch) batch; -// SpeciesBatch targetChild = TuttiBeanFactory.newSpeciesBatch(); -// entityToSpeciesBatch(sourceChild, targetChild); -// if (log.isInfoEnabled()) { -// log.info("Loaded CatchBatch Hors Vrac > (Species|Benthos) > " + target.getSpecies().getReferenceTaxonId() + " : " + target.getId()); -// } -// if (targetChild.getSampleCategoryValue() != null) { -// targetChilds.add(targetChild); -// targetChild.setParentBatch(target); -// } -// } -// target.setChildBatchs(targetChilds); -// } -// -// QualityFlag qualityFlag = source.getQualityFlag(); -// target.setSpeciesToConfirm(qualityFlag != null && enumeration.QUALITY_FLAG_CODE_DOUBTFUL.equals(qualityFlag.getCode())); -// -// return target; -// } -// -// public void entityToSpeciesBatchFrequency(SortingBatch source, -// SpeciesBatchFrequency target) { -// -// target.setId(source.getId()); -// -// target.setNumber(source.getIndividualCount()); -// target.setWeight(source.getWeight()); -// -// Preconditions.checkState(source.getSortingMeasurements().size() == 1, "SortingBatch [" + source.getId() + "] need exactly one sortingMeasurement (to store the length step category), but had " + source.getSortingMeasurements().size()); -// SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); -// Preconditions.checkNotNull(sm.getPmfm(), "SortingMeasurement [" + sm.getId() + "] can not have a null pmfm"); -// Preconditions.checkNotNull(sm.getPmfm().getId(), "SortingMeasurement [" + sm.getId() + "] can not have a pmfm with null id"); -// -// // Length step category -// Caracteristic lengthStepCaracteristic = -// referentialService.getCaracteristic(sm.getPmfm().getId()); -// target.setLengthStepCaracteristic(lengthStepCaracteristic); -// -// // Length -// target.setLengthStep(sm.getNumericalValue()); -// } -// -// public void speciesBatchToEntity(SpeciesBatch source, -// SortingBatch target, -// String parentBatchId, -// fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, -// Integer batchPmfm) { -// -// Preconditions.checkNotNull(source.getFishingOperation()); -// Preconditions.checkNotNull(source.getFishingOperation().getId()); -// -// // Retrieve recorder department -// Integer recorderDepartmentId = getRecorderDepartmentId(); -// -// 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); -// } -// -// // If parent and root need to be set -// if (target.getId() == null -// || target.getRootBatch() == null -// || (target.getParentBatch() != null && !target.getParentBatch().getId().toString().equals(parentBatchId))) { -// setBatchParents(source, target, parentBatchId, catchBatch, batchPmfm); -// } -// -// // RankOrder (initialize once, at creation) -// if (target.getRankOrder() == null) { -// // 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) { -// rankOrder += (short) target.getParentBatch().getChildBatchs().size(); -// } -// target.setRankOrder(rankOrder); -// } -// -// // Force subgroup count to '1', as Allegro -// target.setSubgroupCount(1f); -// -// // Weight or SampleCategoryWeight -// if (source.getWeight() == null && source.getSampleCategoryWeight() == null) { -// // Nothing to do : will be removed later, using notChangedSortingMeasurements -// } else if (source.getSampleCategoryWeight() != null && source.getWeight() == null) { -// QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, -// enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true); -// notChangedQuantificationMeasurements.remove(quantificationMeasurement); -// } else if (source.getWeight() != null && source.getSampleCategoryWeight() == null) { -// QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, -// enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); -// notChangedQuantificationMeasurements.remove(quantificationMeasurement); -// } -// -// // Sampling Ratio -// if (source.getSampleCategoryWeight() == null || source.getWeight() == null) { -// target.setSamplingRatio(null); -// target.setSamplingRatioText(null); -// } else { -// String samplingRatioText = source.getWeight() + "/" + source.getSampleCategoryWeight(); -// samplingRatioText = samplingRatioText.replaceAll(",", "."); -// target.setSamplingRatioText(samplingRatioText); -// target.setSamplingRatio(source.getWeight() / source.getSampleCategoryWeight()); -// QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement(target, -// enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); -// notChangedQuantificationMeasurements.remove(quantificationMeasurement); -// } -// -// // Sorting measurement -// if ((source.getSampleCategoryType() == null || source.getSampleCategoryValue() == null)) { -// // Nothing to do : will be removed later, using notChangedSortingMeasurements -// } else { -// Integer pmfmId = source.getSampleCategoryType().getFieldValue(); -// // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch) -// if (!pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { -// SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId, -// source.getSampleCategoryType(), source.getSampleCategoryValue()); -// notChangedSortingMeasurements.remove(sortingMeasurement); -// } -// } -// -// // Individual count -// target.setIndividualCount(source.getNumber()); -// -// // Species -// ReferenceTaxon referenceTaxon; -// if (source.getSpecies() == null || parentBatchId != null) { -// referenceTaxon = null; -// } else { -// referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId()); -// } -// target.setReferenceTaxon(referenceTaxon); -// -// // QualityFlag -// String qualityFlag; -// if (source.isSpeciesToConfirm()) { -// qualityFlag = enumeration.QUALITY_FLAG_CODE_DOUBTFUL; -// } else { -// qualityFlag = enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED; -// } -// target.setQualityFlag(load(QualityFlagImpl.class, qualityFlag)); -// -// // Comments -// target.setComments(source.getComment()); -// -// // Exhaustive inventory (always true under a species batch) -// target.setExhaustiveInventory(true); -// -// // Removed not changed measurements (in sorting and quantification measurement lists) -// if (quantificationMeasurements != null) { -// quantificationMeasurements.removeAll(notChangedQuantificationMeasurements); -// } -// if (sortingMeasurements != null) { -// sortingMeasurements.removeAll(notChangedSortingMeasurements); -// } -// } - -// 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 = convertSampleCategoryValueIntoQualitativeId(source.getSampleCategoryValue()); -// -// parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), -// BATCH_PMFM_ID, pmfmId, qualitativeValueId, // vrac | hors vrac -// 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é -// ); -// } -// -// -// 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); -// } -// -// public void speciesBatchFrequencyToEntity(SpeciesBatchFrequency source, -// SortingBatch target, -// SortingBatch parentBatch, -// short rankOrder) { -// Preconditions.checkNotNull(source.getBatch()); -// Preconditions.checkNotNull(source.getBatch().getId()); -// -// // Retrieve recorder department -// Integer recorderDepartmentId = getRecorderDepartmentId(); -// -// 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); -// } -// -// // If parent and root need to be set -// if (target.getId() == null -// || target.getRootBatch() == null -// || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatch.getId()))) { -// -// target.setParentBatch(parentBatch); -// target.setRootBatch(parentBatch.getRootBatch()); -// } -// -// // RankOrder -// target.setRankOrder(rankOrder); -// -// // Weight or SampleCategoryWeight -// if (source.getWeight() == null) { -// // Nothing to do : will be removed later, using notChangedSortingMeasurements -// } else { -// QuantificationMeasurement quantificationMeasurement = catchBatchDao.setQuantificationMeasurement( -// target, -// enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); -// notChangedQuantificationMeasurements.remove(quantificationMeasurement); -// } -// -// // Sorting measurement -// if ((source.getLengthStepCaracteristic() == null || source.getLengthStep() == null)) { -// // Nothing to do : will be removed later, using notChangedSortingMeasurements -// } else { -// Integer pmfmId = source.getLengthStepCaracteristic().getIdAsInt(); -// SortingMeasurement sortingMeasurement = setSortingMeasurement(target, recorderDepartmentId, pmfmId, -// source.getLengthStep()); -// notChangedSortingMeasurements.remove(sortingMeasurement); -// } -// -// // Individual count -// target.setIndividualCount(source.getNumber()); -// -// // Species -// target.setReferenceTaxon(null); -// -// // QualityFlag -// target.setQualityFlag(parentBatch.getQualityFlag()); -// -// // Exhaustive inventory (always true under a species batch) -// target.setExhaustiveInventory(true); -// -// // Removed not changed measurements (in sorting and quantification measurement lists) -// if (quantificationMeasurements != null) { -// quantificationMeasurements.removeAll(notChangedQuantificationMeasurements); -// } -// if (sortingMeasurements != null) { -// sortingMeasurements.removeAll(notChangedSortingMeasurements); -// } -// } - public Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { if (value == null) return null; @@ -536,43 +195,6 @@ 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 (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; @@ -632,4 +254,31 @@ setMeasurement(sortingMeasurement, caracteristic, value); return sortingMeasurement; } + + public Serializable getSampleCategoryQualitative(Integer pmfmId, + Float numericalvalue, + String alphanumericalValue, + Integer qualitativeValueId) { + + if (numericalvalue != null) { + return numericalvalue; + } + if (alphanumericalValue != null) { + return alphanumericalValue; + } + + Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId); + if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { + return null; + } + CaracteristicQualitativeValue value = null; + for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { + if (qualitativeValueId.equals(qv.getIdAsInt())) { + value = qv; + break; + } + } + + return value; + } }