r432 - in trunk: . tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/synchro tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro tutti-service tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tu
Author: tchemit Date: 2013-02-15 21:28:55 +0100 (Fri, 15 Feb 2013) New Revision: 432 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/432 Log: prepare release (reformat code, optimize dependencies, i18n) Modified: trunk/pom.xml trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/synchro/TuttiTableMetadata.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplUpTodateTest.java trunk/tutti-service/pom.xml trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/PersonModel.java trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties trunk/tutti-ui-swing/pom.xml trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/pom.xml 2013-02-15 20:28:55 UTC (rev 432) @@ -273,12 +273,6 @@ </dependency> <dependency> - <groupId>org.swinglabs.swingx</groupId> - <artifactId>swingx-action</artifactId> - <version>${swingXVersion}</version> - </dependency> - - <dependency> <groupId>com.ezware.oxbow</groupId> <artifactId>swing-bits</artifactId> <version>0.5.0</version> Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AbstractPersistenceService.java 2013-02-15 20:28:55 UTC (rev 432) @@ -53,7 +53,7 @@ LogFactory.getLog(AbstractPersistenceService.class); private boolean debug = false; - + /** * Session factory. * @@ -157,19 +157,19 @@ } protected <T extends Serializable> T load(Class<? extends T> clazz, Serializable id) { - // TODO BLA : ajouter une annotation qui rejoue une méthode - // avec debug=true. puis repasse à faux, - // lorsqu'une erreur - if (debug) { - T load = (T) getCurrentSession().get(clazz, id); - if (load == null) { - throw new DataIntegrityViolationException("Unable to load entity " + clazz.getName() + " with id="+id+" : not found in database."); - } - } + // TODO BLA : ajouter une annotation qui rejoue une méthode + // avec debug=true. puis repasse à faux, + // lorsqu'une erreur + if (debug) { + T load = (T) getCurrentSession().get(clazz, id); + if (load == null) { + throw new DataIntegrityViolationException("Unable to load entity " + clazz.getName() + " with id=" + id + " : not found in database."); + } + } T load = (T) getCurrentSession().load(clazz, id); return load; } - + protected <T extends Serializable> T get(Class<? extends T> clazz, Serializable id) { T load = (T) getCurrentSession().get(clazz, id); return load; Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-02-15 20:28:55 UTC (rev 432) @@ -25,34 +25,8 @@ */ -import static org.nuiton.i18n.I18n._; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.FlushMode; -import org.hibernate.type.IntegerType; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.stereotype.Service; - import com.google.common.base.Preconditions; import com.google.common.collect.Lists; - import fr.ifremer.adagio.core.dao.data.batch.Batch; import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; @@ -77,1246 +51,1262 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.service.measure.MeasurementPersistenceHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.FlushMode; +import org.hibernate.type.IntegerType; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.dao.DataRetrievalFailureException; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.nuiton.i18n.I18n._; + @Service("batchPersistenceService") -public class BatchPersistenceServiceImpl - extends AbstractPersistenceService implements BatchPersistenceService, CatchBatchValidator - { +public class BatchPersistenceServiceImpl + extends AbstractPersistenceService implements BatchPersistenceService, CatchBatchValidator { - /** Logger. */ - private static final Log log = - LogFactory.getLog(BatchPersistenceServiceImpl.class); + /** Logger. */ + private static final Log log = + LogFactory.getLog(BatchPersistenceServiceImpl.class); - @Resource(name = "referentialPersistenceService") - protected ReferentialPersistenceService referentialService; + @Resource(name = "referentialPersistenceService") + protected ReferentialPersistenceService referentialService; - @Resource(name = "denormalizedBatchDao") - protected DenormalizedBatchDao denormalizedBatchDao; + @Resource(name = "denormalizedBatchDao") + protected DenormalizedBatchDao denormalizedBatchDao; - @Resource(name = "sortingBatchDao") - protected SortingBatchDao sortingBatchDao; + @Resource(name = "sortingBatchDao") + protected SortingBatchDao sortingBatchDao; - @Resource(name = "catchBatchDao") - protected CatchBatchExtendDao catchBatchDao; + @Resource(name = "catchBatchDao") + protected CatchBatchExtendDao catchBatchDao; - @Resource(name = "measurementPersistenceHelper") - protected MeasurementPersistenceHelper measurementHelper; - - @Override - public void init() { - super.init(); - catchBatchDao.registerCatchBatchValidator(this); - } - - @Override - public void close() { - catchBatchDao.unregisterCatchBatchValidator(this); - super.close(); - } + @Resource(name = "measurementPersistenceHelper") + protected MeasurementPersistenceHelper measurementHelper; - @Override - public boolean isEnable(fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { - // Apply validation only on catch batch for fishingOperation - return (catchBatch.getFishingOperation() != null); - } + @Override + public void init() { + super.init(); + catchBatchDao.registerCatchBatchValidator(this); + } - @Override - public List<CatchBatchValidationError> validate(fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { - List<CatchBatchValidationError> errors = Lists.newArrayList(); - validate(catchBatch.getChildBatchs(), errors, 1); - return errors; - } - - @Override - public CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) { - Preconditions.checkNotNull(fishingOperationId); - - Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId)); + @Override + public void close() { + catchBatchDao.unregisterCatchBatchValidator(this); + super.close(); + } - fr.ifremer.adagio.core.dao.data.batch.CatchBatch source; - try { - source = catchBatchDao.loadFullTree(catchBatchId, true, true); - } catch (CatchBatchValidationException e) { - throw new DataRetrievalFailureException("Invalid batch tree structure, for fishing operation id=" + fishingOperationId, e); - } + @Override + public boolean isEnable(fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { + // Apply validation only on catch batch for fishingOperation + return (catchBatch.getFishingOperation() != null); + } - CatchBatch result = new CatchBatch(); - result.setId(source.getId().toString()); - result.setCatchTotalWeight(source.getWeight()); - - // Vrac - SortingBatch vracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID); - result.setCatchTotalSortedCarousselWeight(vracBatch.getWeight()); - result.setCatchTotalSortedTremisWeight(vracBatch.getWeightBeforeSampling()); - { - // Species - SortingBatch speciesBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + @Override + public List<CatchBatchValidationError> validate(fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { + List<CatchBatchValidationError> errors = Lists.newArrayList(); + validate(catchBatch.getChildBatchs(), errors, 1); + return errors; + } - result.setSpeciesTotalSampleSortedWeight(speciesBatch.getWeight()); - result.setSpeciesTotalSortedWeight(speciesBatch.getWeightBeforeSampling()); - - { - // Inert - SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); - result.setSpeciesTotalInertWeight(inertBatch.getWeight()); - - // Alive no itemized - SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), - "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); - result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); - } - - // TODO : Benthos, Plancton... - } - - // Hors Vrac - SortingBatch horsVracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID); - result.setCatchTotalUnsortedWeight(horsVracBatch.getWeight()); - { - // Species - SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + @Override + public CatchBatch getCatchBatchFromFishingOperation(String fishingOperationId) { + Preconditions.checkNotNull(fishingOperationId); - result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight()); - - // TODO : Benthos, Plancton... - } + Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId)); - // Non trié - SortingBatch unsortedBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID); - result.setCatchTotalRejectedWeight(unsortedBatch.getWeight()); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch source; + try { + source = catchBatchDao.loadFullTree(catchBatchId, true, true); + } catch (CatchBatchValidationException e) { + throw new DataRetrievalFailureException("Invalid batch tree structure, for fishing operation id=" + fishingOperationId, e); + } - return result; - } + CatchBatch result = new CatchBatch(); + result.setId(source.getId().toString()); + result.setCatchTotalWeight(source.getWeight()); - @Override - - public CatchBatch createCatchBatch(CatchBatch bean) { - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(bean.getId() == null); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); + // Vrac + SortingBatch vracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID); + result.setCatchTotalSortedCarousselWeight(vracBatch.getWeight()); + result.setCatchTotalSortedTremisWeight(vracBatch.getWeightBeforeSampling()); + { + // Species + SortingBatch speciesBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = fr.ifremer.adagio.core.dao.data.batch.CatchBatch.Factory.newInstance(); - beanToEntity(bean, catchBatch, true); - catchBatch = catchBatchDao.create(catchBatch); - bean.setId(String.valueOf(catchBatch.getId())); + result.setSpeciesTotalSampleSortedWeight(speciesBatch.getWeight()); + result.setSpeciesTotalSortedWeight(speciesBatch.getWeightBeforeSampling()); - // Link to fishing operation - getCurrentSession().flush(); - Integer fishingOperationId = Integer.valueOf(bean.getFishingOperation().getId()); - 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."); - } + { + // Inert + SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), + "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); + result.setSpeciesTotalInertWeight(inertBatch.getWeight()); - return bean; - } + // Alive no itemized + SortingBatch livingNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), + "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); + result.setSpeciesTotalLivingNotItemizedWeight(livingNotItemizedBatch.getWeight()); + } - @Override - @CacheEvict(value = "batchTree", key="#bean.fishingOperation.id") - public CatchBatch saveCatchBatch(CatchBatch bean) { + // TODO : Benthos, Plancton... + } - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(bean.getId()); + // Hors Vrac + SortingBatch horsVracBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID); + result.setCatchTotalUnsortedWeight(horsVracBatch.getWeight()); + { + // Species + SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - getCurrentSession().enableFetchProfile("batch-with-childs"); - getCurrentSession().setFlushMode(FlushMode.COMMIT); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.load(Integer.valueOf(bean.getId())); - if (catchBatch == null) { - throw new DataRetrievalFailureException("Could not retrieve catch batch with id=" + bean.getId()); - } + result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight()); - beanToEntity(bean, catchBatch, true); - catchBatchDao.update(catchBatch); - getCurrentSession().flush(); - - return bean; - } + // TODO : Benthos, Plancton... + } - @Override - public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) { - - // Load batch tree - Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId)); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - - List<SpeciesBatch> result = new ArrayList<SpeciesBatch>(); - - // Vrac / Species - SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - for (Iterator<Batch> iterator = vracSpeciesBatch.getChildBatchs().iterator(); iterator.hasNext();) { - SortingBatch source = (SortingBatch) iterator.next(); - - // evict some special batches : Life (or Biota) and Inert - if (source.getReferenceTaxon() != null - && enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId()) == false - && enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId()) == false) { - SpeciesBatch target = new SpeciesBatch(); - - entityToBean(source, target); - result.add(target); - } - } - - // Hors-Vrac / Species - SortingBatch horsVracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), - "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - for (Iterator<Batch> iterator = horsVracSpeciesBatch.getChildBatchs().iterator(); iterator.hasNext();) { - SortingBatch source = (SortingBatch) iterator.next(); - - SpeciesBatch target = new SpeciesBatch(); - - entityToBean(source, target); - result.add(target); - } + // Non trié + SortingBatch unsortedBatch = catchBatchDao.getSortingBatch(source.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID); + result.setCatchTotalRejectedWeight(unsortedBatch.getWeight()); - return result; - } - - protected SpeciesBatch entityToBean(SortingBatch source, SpeciesBatch target) { + return result; + } - target.setId(source.getId().toString()); + @Override - // Individual count - target.setNumber(source.getIndividualCount()); + public CatchBatch createCatchBatch(CatchBatch bean) { + Preconditions.checkNotNull(bean); + Preconditions.checkArgument(bean.getId() == null); + Preconditions.checkNotNull(bean.getFishingOperation()); + Preconditions.checkNotNull(bean.getFishingOperation().getId()); - // 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()); - } + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = fr.ifremer.adagio.core.dao.data.batch.CatchBatch.Factory.newInstance(); + beanToEntity(bean, catchBatch, true); + catchBatch = catchBatchDao.create(catchBatch); + bean.setId(String.valueOf(catchBatch.getId())); - // Comments - target.setComment(source.getComments()); + // Link to fishing operation + getCurrentSession().flush(); + Integer fishingOperationId = Integer.valueOf(bean.getFishingOperation().getId()); + 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."); + } - // 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 = measurementHelper.getInheritedSortingMeasurement(source, enumeration.PMFM_ID_SORTED_UNSORTED); - } - if (sm != null) { - SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(sm.getPmfm().getId()); - if (sampleCategory != null) { - setSampleCategoryQualitative(target, sm.getPmfm().getId(), sm.getNumericalValue(), sm.getAlphanumericalValue(), sm.getQualitativeValue().getId()); - } - } - - // Species - Integer referenceTaxonId = source.getInheritedReferenceTaxonId(); - if (referenceTaxonId == null && source.getReferenceTaxon() != null) { - referenceTaxonId = source.getReferenceTaxon().getId(); - } - if (referenceTaxonId != null) { - // TODO : add cache on getSpeciesByReferenceTaxonId - Species species = referentialService.getSpeciesByReferenceTaxonId(referenceTaxonId); - target.setSpecies(species); - } - - if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) { - List<SpeciesBatch> targetChilds = Lists.newArrayList(); - for (Iterator<Batch> iterator = source.getChildBatchs().iterator(); iterator.hasNext();) { - SortingBatch sourceChild = (SortingBatch) iterator.next(); - SpeciesBatch targetChild = new SpeciesBatch(); - entityToBean(sourceChild, targetChild); - if (targetChild.getSampleCategoryValue() != null) { - targetChilds.add(targetChild); - targetChild.setParentBatch(target); - } - } - target.setChildBatchs(targetChilds); - } + return bean; + } - return target; - } + @Override + @CacheEvict(value = "batchTree", key = "#bean.fishingOperation.id") + public CatchBatch saveCatchBatch(CatchBatch bean) { - @Override - public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, - String parentBatchId) { - Preconditions.checkNotNull(bean); - Preconditions.checkArgument(bean.getId() == null); - Preconditions.checkNotNull(bean.getSpecies()); - Preconditions.checkNotNull(bean.getSpecies().getId()); - Preconditions.checkNotNull(bean.getFishingOperation()); - Preconditions.checkNotNull(bean.getFishingOperation().getId()); + Preconditions.checkNotNull(bean); + Preconditions.checkNotNull(bean.getId()); - getCurrentSession().setFlushMode(FlushMode.COMMIT); - - // Load full batch tree - Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(bean.getFishingOperation().getId())); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + getCurrentSession().enableFetchProfile("batch-with-childs"); + getCurrentSession().setFlushMode(FlushMode.COMMIT); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.load(Integer.valueOf(bean.getId())); + if (catchBatch == null) { + throw new DataRetrievalFailureException("Could not retrieve catch batch with id=" + bean.getId()); + } - SortingBatch batch = SortingBatch.Factory.newInstance(); - beanToEntity(bean, batch, parentBatchId, catchBatch, true); - batch = sortingBatchDao.create(batch); + beanToEntity(bean, catchBatch, true); + catchBatchDao.update(catchBatch); + getCurrentSession().flush(); - bean.setId(String.valueOf(batch.getId())); + return bean; + } - getCurrentSession().flush(); + @Override + public List<SpeciesBatch> getAllRootSpeciesBatch(String fishingOperationId) { - return bean; - } + // Load batch tree + Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(fishingOperationId)); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - @Override - public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) { - Preconditions.checkNotNull(bean); - Preconditions.checkNotNull(bean.getId()); + List<SpeciesBatch> result = new ArrayList<SpeciesBatch>(); - // Load full batch tree - Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(bean.getId())); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + // Vrac / Species + SortingBatch vracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + for (Iterator<Batch> iterator = vracSpeciesBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { + SortingBatch source = (SortingBatch) iterator.next(); - getCurrentSession().setFlushMode(FlushMode.COMMIT); - - SortingBatch batch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(bean.getId())); - String parentBatchId = null; - if (bean.getParentBatch() != null) { - parentBatchId = bean.getParentBatch().getId(); - } - beanToEntity(bean, batch, parentBatchId, catchBatch, true); - sortingBatchDao.update(batch); - getCurrentSession().flush(); + // evict some special batches : Life (or Biota) and Inert + if (source.getReferenceTaxon() != null + && enumeration.REFERENCE_TAXON_ID_LIFE.equals(source.getReferenceTaxon().getId()) == false + && enumeration.REFERENCE_TAXON_ID_INERT.equals(source.getReferenceTaxon().getId()) == false) { + SpeciesBatch target = new SpeciesBatch(); - return bean; - } + entityToBean(source, target); + result.add(target); + } + } - @Override - public void deleteSpeciesBatch(String id) { - Preconditions.checkNotNull(id); + // Hors-Vrac / Species + SortingBatch horsVracSpeciesBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), + "pmfmId", enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + for (Iterator<Batch> iterator = horsVracSpeciesBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { + SortingBatch source = (SortingBatch) iterator.next(); - getCurrentSession().setFlushMode(FlushMode.COMMIT); + SpeciesBatch target = new SpeciesBatch(); - catchBatchDao.removeWithChildren(Integer.valueOf(id)); + entityToBean(source, target); + result.add(target); + } - getCurrentSession().flush(); - } + return result; + } - public void deleteSpeciesSubBatch(String id) { - deleteSpeciesBatch(id); - } + protected SpeciesBatch entityToBean(SortingBatch source, SpeciesBatch target) { - public void changeSpeciesBatchSpecies(String batchId, Species species) { - Preconditions.checkNotNull(batchId); - Preconditions.checkNotNull(species); - Preconditions.checkNotNull(species.getReferenceTaxonId()); + target.setId(source.getId().toString()); - if (log.isDebugEnabled()) { - log.debug("Changing species for batch id=" + batchId); - } + // Individual count + target.setNumber(source.getIndividualCount()); - int rowUpdated = queryUpdate("updateBatchSpecies", - "batchId", IntegerType.INSTANCE, Integer.valueOf(batchId), - "referenceTaxonId", IntegerType.INSTANCE, species.getReferenceTaxonId()); - Preconditions.checkArgument(rowUpdated == 1, "Unable to update operation, to be linked with catch batch."); - } + // 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()); + } - public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency( - String speciesBatchId) { - List<SpeciesBatchFrequency> results = Lists.newArrayList(); - - Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(speciesBatchId)); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - - if (catchBatchId == null) { - return results; - } - - SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(speciesBatchId)); - - for (Iterator<Batch> iterator = sortingBatch.getChildBatchs().iterator(); iterator.hasNext();) { - SortingBatch source = (SortingBatch) iterator.next(); - SpeciesBatchFrequency target = new SpeciesBatchFrequency(); - - entityToBean(source, target); - results.add(target); - } - return results; - } - - protected void entityToBean(SortingBatch source, SpeciesBatchFrequency target) { + // Comments + target.setComment(source.getComments()); - target.setId(source.getId().toString()); + // 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 = measurementHelper.getInheritedSortingMeasurement(source, enumeration.PMFM_ID_SORTED_UNSORTED); + } + if (sm != null) { + SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(sm.getPmfm().getId()); + if (sampleCategory != null) { + setSampleCategoryQualitative(target, sm.getPmfm().getId(), sm.getNumericalValue(), sm.getAlphanumericalValue(), sm.getQualitativeValue().getId()); + } + } - target.setNumber(source.getIndividualCount()); - target.setWeight(source.getWeight()); - target.setComment(source.getComments()); + // 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); + } - // Length step category - if (source.getSortingMeasurements().size() == 1) { - SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); - if (sm.getPmfm() != null && sm.getPmfm().getId() != null) { - Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(sm.getPmfm().getId()); - target.setLengthStepCaracteristic(lengthStepCaracteristic); - } - - // Length - target.setLengthStep(sm.getNumericalValue()); - } - } + if (target.getSampleCategoryType() != null && source.getChildBatchs().size() > 0) { + List<SpeciesBatch> targetChilds = Lists.newArrayList(); + for (Iterator<Batch> iterator = source.getChildBatchs().iterator(); iterator.hasNext(); ) { + SortingBatch sourceChild = (SortingBatch) iterator.next(); + SpeciesBatch targetChild = new SpeciesBatch(); + entityToBean(sourceChild, targetChild); + if (targetChild.getSampleCategoryValue() != null) { + targetChilds.add(targetChild); + targetChild.setParentBatch(target); + } + } + target.setChildBatchs(targetChilds); + } - public List<SpeciesBatchFrequency> saveSpeciesBatchFrequency( - String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { - Preconditions.checkNotNull(speciesBatchId); - Preconditions.checkNotNull(frequencies); + return target; + } - if (frequencies.size() == 0) { - return frequencies; - } - getCurrentSession().setFlushMode(FlushMode.COMMIT); - - Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(speciesBatchId)); - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); + @Override + public SpeciesBatch createSpeciesBatch(SpeciesBatch bean, + String parentBatchId) { + Preconditions.checkNotNull(bean); + Preconditions.checkArgument(bean.getId() == null); + Preconditions.checkNotNull(bean.getSpecies()); + Preconditions.checkNotNull(bean.getSpecies().getId()); + Preconditions.checkNotNull(bean.getFishingOperation()); + Preconditions.checkNotNull(bean.getFishingOperation().getId()); - if (catchBatch == null) { - return frequencies; - } + getCurrentSession().setFlushMode(FlushMode.COMMIT); - // Retrieve parent - SortingBatch parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(speciesBatchId)); - - // Remember child ids, to remove unchanged item (see at bottom in this method) - List<Integer> notUpdatedChildIds = Lists.newArrayList(); - for (Iterator<Batch> iterator = parentBatch.getChildBatchs().iterator(); iterator.hasNext();) { - SortingBatch sortingBatch = (SortingBatch) iterator.next(); - notUpdatedChildIds.add(sortingBatch.getId()); - } + // Load full batch tree + Integer catchBatchId = catchBatchDao.getIdByFishingOperationId(Integer.valueOf(bean.getFishingOperation().getId())); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - short rankOrder = 0; - String pmfmId = null; - List<SortingBatch> batchsToUpdate = Lists.newArrayList(); - for (SpeciesBatchFrequency source : frequencies) { - rankOrder++; + SortingBatch batch = SortingBatch.Factory.newInstance(); + beanToEntity(bean, batch, parentBatchId, catchBatch, true); + batch = sortingBatchDao.create(batch); - // Check that all frequencies have the same length PMFM - if (pmfmId == null) { - source.getLengthStepCaracteristic().getId(); - } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { - throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); - } + bean.setId(String.valueOf(batch.getId())); - // Not existing batch - SortingBatch target = null; - if (source.getId() == null) { - target = SortingBatch.Factory.newInstance(); + getCurrentSession().flush(); - // Fill the sorting batch from the source - beanToEntity(source, target, parentBatch, rankOrder, true); + return bean; + } - // Create the targeted batch, then update the source id - sortingBatchDao.create(target); - source.setId(target.getId().toString()); - } + @Override + public SpeciesBatch saveSpeciesBatch(SpeciesBatch bean) { + Preconditions.checkNotNull(bean); + Preconditions.checkNotNull(bean.getId()); - // Existing batch - else { - target = sortingBatchDao.load(Integer.valueOf(source.getId())); + // Load full batch tree + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(bean.getId())); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - // Fill the sorting batch from the source - beanToEntity(source, target, parentBatch, rankOrder, true); + getCurrentSession().setFlushMode(FlushMode.COMMIT); - // Add the batch into a list (will be update later, using this list) - batchsToUpdate.add(target); - - notUpdatedChildIds.remove(target.getId()); - } - } + SortingBatch batch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(bean.getId())); + String parentBatchId = null; + if (bean.getParentBatch() != null) { + parentBatchId = bean.getParentBatch().getId(); + } + beanToEntity(bean, batch, parentBatchId, catchBatch, true); + sortingBatchDao.update(batch); + getCurrentSession().flush(); - // If some batchs need to be update, do it - if (batchsToUpdate.size() > 0) { - sortingBatchDao.update(batchsToUpdate); - } - - if (notUpdatedChildIds.size() > 0) { - for (Iterator<Integer> iterator = notUpdatedChildIds.iterator(); iterator.hasNext();) { - Integer batchId = iterator.next(); - catchBatchDao.removeWithChildren(batchId); - } - } - - getCurrentSession().flush(); + return bean; + } - return frequencies; - } + @Override + public void deleteSpeciesBatch(String id) { + Preconditions.checkNotNull(id); - // ------------------------------------------------------------------------// - // -- Internal methods --// - // ------------------------------------------------------------------------// + getCurrentSession().setFlushMode(FlushMode.COMMIT); - protected void validate(Collection<Batch> batchs, List<CatchBatchValidationError> errors, int treeLevel) { - - List<Integer> expectedPmfms = null; - boolean expectedReferenceTaxon = false; - // First tree level : should have pmfm SORTED (Vrac, Hors Vrac, Non trié) - if (treeLevel == 1) { - expectedPmfms = Lists.newArrayList(enumeration.PMFM_ID_SORTED_UNSORTED); - } - // Second tree level : should have pmfm SORTING_TYPE (Species, Benthos...) - else if (treeLevel == 2) { - expectedPmfms = Lists.newArrayList(enumeration.PMFM_ID_SORTING_TYPE); - } - else if (treeLevel == 3) { - expectedReferenceTaxon = true; - } - else if (treeLevel > 3) { - expectedPmfms = referentialService.getSampleCategoryIds(); - expectedPmfms.remove(enumeration.PMFM_ID_SORTED_UNSORTED); - } - - // First level : should be only PMFM=SORTED - for (Iterator<Batch> iterator = batchs.iterator(); iterator.hasNext();) { - SortingBatch batch = (SortingBatch) iterator.next(); - boolean batchHasError = false; - - // For all sorting measurements - if (batch.getSortingMeasurements() != null && batch.getSortingMeasurements().size() > 0) { - for (Iterator<SortingMeasurement> iterator2 = batch.getSortingMeasurements().iterator(); iterator2.hasNext();) { - SortingMeasurement sm = iterator2.next(); - Integer pmfmId = sm.getPmfm().getId(); - if (expectedReferenceTaxon) { - CatchBatchValidationError error = new CatchBatchValidationError( - "tutti.persistence.batch.validation.onlyTaxonButPmfmFound", - _("tutti.persistence.batch.validation.onlyTaxonButPmfmFound", batch.getId(), pmfmId), - CatchBatchValidationError.GRAVITY_ERROR); - errors.add(error); - } - else if (expectedPmfms.contains(pmfmId) == false) { - if (sm.getNumericalValue() == null || batch.getChildBatchs().size() > 0) { - batchHasError = true; - CatchBatchValidationError error = new CatchBatchValidationError( - "tutti.persistence.batch.validation.pmfmNotFound", - _("tutti.persistence.batch.validation.pmfmNotFound", - batch.getId(), Arrays.toString(expectedPmfms.toArray()), pmfmId), - CatchBatchValidationError.GRAVITY_ERROR); - errors.add(error); - } - } - } - } - else if (expectedPmfms != null && expectedPmfms.size() > 0){ - batchHasError = true; - CatchBatchValidationError error = new CatchBatchValidationError( - "tutti.persistence.batch.validation.pmfmNotFound", - _("tutti.persistence.batch.validation.pmfmNotFound", - batch.getId(), Arrays.toString(expectedPmfms.toArray()), "null"), - CatchBatchValidationError.GRAVITY_ERROR); - errors.add(error); - } - - if (!batchHasError && expectedReferenceTaxon == true && batch.getReferenceTaxon() == null) { - CatchBatchValidationError error = new CatchBatchValidationError( - "tutti.persistence.batch.validation.referenceTaxonNotFound", - _("tutti.persistence.batch.validation.referenceTaxonNotFound", batch.getId()), - CatchBatchValidationError.GRAVITY_ERROR); - errors.add(error); - } - - if (!batchHasError) { - validate(batch.getChildBatchs(), errors, treeLevel+1); - } - } - } - - protected void beanToEntity(SpeciesBatch source, - SortingBatch target, - String parentBatchId, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, - boolean copyIfNull) { - Preconditions.checkNotNull(source.getFishingOperation()); - Preconditions.checkNotNull(source.getFishingOperation().getId()); + catchBatchDao.removeWithChildren(Integer.valueOf(id)); - // Retrieve recorder department - Integer recorderDepartmentId = getRecorderDepartmentId(); + getCurrentSession().flush(); + } - // Create lists to store all updates, then remove not updated items - Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); - if (target.getQuantificationMeasurements() != null) { - notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); - } - Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); - if (target.getSortingMeasurements() != null) { - notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); - } + public void deleteSpeciesSubBatch(String id) { + deleteSpeciesBatch(id); + } - // 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); - } + public void changeSpeciesBatchSpecies(String batchId, Species species) { + Preconditions.checkNotNull(batchId); + Preconditions.checkNotNull(species); + Preconditions.checkNotNull(species.getReferenceTaxonId()); - // RankOrder (initialize once, at creation) - if (target.getRankOrder() == null) { - // Start rank order at 3, because of special batches 'Biota' and 'Inert' - short rankOrder = (short) 3; - if (source.getParentBatch() != null && source.getParentBatch().getChildBatchs() != null) { - // TODO BL : vérifier cela (est-ce que l'item est ajouté à son père AVANT d'être passé au service ?) - rankOrder += (short) source.getParentBatch().getChildBatchs().size(); - } - target.setRankOrder(rankOrder); - } - - // Force subgroup count to '1', as Allegro - target.setSubgroupCount(1f); + if (log.isDebugEnabled()) { + log.debug("Changing species for batch id=" + batchId); + } - // Weight or SampleCategoryWeight - if (copyIfNull && 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 = measurementHelper.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } else if (source.getWeight() != null && source.getSampleCategoryWeight() == null) { - QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } + int rowUpdated = queryUpdate("updateBatchSpecies", + "batchId", IntegerType.INSTANCE, Integer.valueOf(batchId), + "referenceTaxonId", IntegerType.INSTANCE, species.getReferenceTaxonId()); + Preconditions.checkArgument(rowUpdated == 1, "Unable to update operation, to be linked with catch batch."); + } - // Sampling Ratio - if (copyIfNull && (source.getSampleCategoryWeight() == null || source.getWeight() == null)) { - target.setSamplingRatio(null); - target.setSamplingRatioText(null); - } else if (source.getSampleCategoryWeight() != null && source.getWeight() != null) { - String samplingRatioText = source.getWeight() + "/" + source.getSampleCategoryWeight(); - samplingRatioText = samplingRatioText.replaceAll(",", "."); - target.setSamplingRatioText(samplingRatioText); - target.setSamplingRatio(source.getWeight() / source.getSampleCategoryWeight()); - QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } + public List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency( + String speciesBatchId) { + List<SpeciesBatchFrequency> results = Lists.newArrayList(); - // Sorting measurement - if (copyIfNull && (source.getSampleCategoryType() == null || source.getSampleCategoryValue() == null)) { - // Nothing to do : will be removed later, using notChangedSortingMeasurements - } else if (source.getSampleCategoryType() != null && source.getSampleCategoryValue() != null) { - Integer pmfmId = measurementHelper.sampleCategory2PmfmId(source.getSampleCategoryType()); - // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch) - if (!pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { - SortingMeasurement sortingMeasurement = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, - source.getSampleCategoryType(), source.getSampleCategoryValue()); - notChangedSortingMeasurements.remove(sortingMeasurement); - } - } + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(speciesBatchId)); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - // Individual count - if (copyIfNull && source.getNumber() == null) { - target.setIndividualCount(null); - } else if (source.getNumber() != null) { - target.setIndividualCount(source.getNumber()); - } + if (catchBatchId == null) { + return results; + } - // Species - if (copyIfNull && (source.getSpecies() == null || parentBatchId != null)) { - target.setReferenceTaxon(null); - } else if (source.getSpecies() != null && parentBatchId == null) { - ReferenceTaxon referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId()); - target.setReferenceTaxon(referenceTaxon); - } + SortingBatch sortingBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(speciesBatchId)); - // QualityFlag - if (source.isSpeciesToConfirm()) { - target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_DOUBTFUL)); - } else { - target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); - } + for (Iterator<Batch> iterator = sortingBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { + SortingBatch source = (SortingBatch) iterator.next(); + SpeciesBatchFrequency target = new SpeciesBatchFrequency(); - // Comments - if (copyIfNull && source.getComment() == null) { - target.setComments(null); - } else if (source.getComment() != null) { - target.setComments(source.getComment()); - } - - // Exhaustive inventory (always true under a species batch) - target.setExhaustiveInventory(true); + entityToBean(source, target); + results.add(target); + } + return results; + } - // Removed not changed measurements (in sorting and quantification measurement lists) - if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { - for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { - target.getQuantificationMeasurements().remove(qm); - } - } - if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { - for (SortingMeasurement sm : notChangedSortingMeasurements) { - target.getSortingMeasurements().remove(sm); - } - } - } + protected void entityToBean(SortingBatch source, SpeciesBatchFrequency target) { - public void setBatchParents(SpeciesBatch source, SortingBatch target, String parentBatchIdStr, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { + target.setId(source.getId().toString()); - Preconditions.checkNotNull(target); - Preconditions.checkNotNull(source.getFishingOperation()); - Preconditions.checkNotNull(source.getFishingOperation().getId()); + target.setNumber(source.getIndividualCount()); + target.setWeight(source.getWeight()); + target.setComment(source.getComments()); - // Load existing parent and root - SortingBatch parentBatch = null; - if (parentBatchIdStr != null) { - parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); - } - - // Or retrieve parent batch, from pmfm id - else { - // Retrieve category type - Integer pmfmId = measurementHelper.sampleCategory2PmfmId(source.getSampleCategoryType()); - 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(), - "pmfmId", pmfmId, qualitativeValueId, - "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + // Length step category + if (source.getSortingMeasurements().size() == 1) { + SortingMeasurement sm = source.getSortingMeasurements().iterator().next(); + if (sm.getPmfm() != null && sm.getPmfm().getId() != null) { + Caracteristic lengthStepCaracteristic = referentialService.getCaracteristic(sm.getPmfm().getId()); + target.setLengthStepCaracteristic(lengthStepCaracteristic); + } - // Parent Batch - target.setParentBatch(parentBatch); - } + // Length + target.setLengthStep(sm.getNumericalValue()); + } + } - - 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 List<SpeciesBatchFrequency> saveSpeciesBatchFrequency( + String speciesBatchId, List<SpeciesBatchFrequency> frequencies) { + Preconditions.checkNotNull(speciesBatchId); + Preconditions.checkNotNull(frequencies); - Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { - if (value == null) - return null; - Integer qualitativeValueId = null; - if (value instanceof CaracteristicQualitativeValue) { - CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value; - qualitativeValueId = Integer.valueOf(cqValue.getId()); - } else if (value instanceof String) { - qualitativeValueId = Integer.valueOf((String) value); - } - return qualitativeValueId; - } + if (frequencies.size() == 0) { + return frequencies; + } + getCurrentSession().setFlushMode(FlushMode.COMMIT); - protected void setSampleCategoryQualitative(SpeciesBatch target, Integer pmfmId, Float numericalvalue, String alphanumericalValue, - Integer qualitativeValueId) { - // skip if null or corresponding to the SORTING_TYPE PMFM (Expèce, Benthos, Plancton, etc.) - if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) { - return; - } + Integer catchBatchId = catchBatchDao.getIdBySortingBatchId(Integer.valueOf(speciesBatchId)); + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch = catchBatchDao.loadFullTree(catchBatchId); - SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(pmfmId); - Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); + if (catchBatch == null) { + return frequencies; + } - target.setSampleCategoryType(sampleCategory); - if (numericalvalue != null) { - target.setSampleCategoryValue(numericalvalue); - return; - } - if (alphanumericalValue != null) { - target.setSampleCategoryValue(alphanumericalValue); - return; - } + // Retrieve parent + SortingBatch parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(speciesBatchId)); - Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId); - if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { - return; - } - CaracteristicQualitativeValue value = null; - for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { - if (qualitativeValueId == Integer.parseInt(qv.getId())) { - value = qv; - break; - } - } - target.setSampleCategoryValue(value); - } + // Remember child ids, to remove unchanged item (see at bottom in this method) + List<Integer> notUpdatedChildIds = Lists.newArrayList(); + for (Iterator<Batch> iterator = parentBatch.getChildBatchs().iterator(); iterator.hasNext(); ) { + SortingBatch sortingBatch = (SortingBatch) iterator.next(); + notUpdatedChildIds.add(sortingBatch.getId()); + } - protected void beanToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, short rankOrder, boolean copyIfNull) { - Preconditions.checkNotNull(source.getBatch()); - Preconditions.checkNotNull(source.getBatch().getId()); + short rankOrder = 0; + String pmfmId = null; + List<SortingBatch> batchsToUpdate = Lists.newArrayList(); + for (SpeciesBatchFrequency source : frequencies) { + rankOrder++; - // Retrieve recorder department - Integer recorderDepartmentId = getRecorderDepartmentId(); + // Check that all frequencies have the same length PMFM + if (pmfmId == null) { + source.getLengthStepCaracteristic().getId(); + } else if (!pmfmId.equals(source.getLengthStepCaracteristic().getId())) { + throw new DataIntegrityViolationException("Batch frequencies under one Speciesbatch must have all the same lengthStepCaracteristic"); + } - // Create lists to store all updates, then remove not updated items - Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); - if (target.getQuantificationMeasurements() != null) { - notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); - } - Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); - if (target.getSortingMeasurements() != null) { - notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); - } + // Not existing batch + SortingBatch target = null; + if (source.getId() == null) { + target = SortingBatch.Factory.newInstance(); - // If parent and root need to be set - if (target.getId() == null - || target.getRootBatch() == null - || (target.getParentBatch() != null && !target.getParentBatch().getId().equals(parentBatch.getId()))) { + // Fill the sorting batch from the source + beanToEntity(source, target, parentBatch, rankOrder, true); - target.setParentBatch(parentBatch); - target.setRootBatch(parentBatch.getRootBatch()); - } + // Create the targeted batch, then update the source id + sortingBatchDao.create(target); + source.setId(target.getId().toString()); + } - // RankOrder - target.setRankOrder(rankOrder); + // Existing batch + else { + target = sortingBatchDao.load(Integer.valueOf(source.getId())); - // Weight or SampleCategoryWeight - if (copyIfNull && source.getWeight() == null) { - // Nothing to do : will be removed later, using notChangedSortingMeasurements - } else if (source.getWeight() != null) { - QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } + // Fill the sorting batch from the source + beanToEntity(source, target, parentBatch, rankOrder, true); - // Sorting measurement - if (copyIfNull && (source.getLengthStepCaracteristic() == null || source.getLengthStep() == null)) { - // Nothing to do : will be removed later, using notChangedSortingMeasurements - } else if (source.getLengthStepCaracteristic() != null && source.getLengthStep() != null) { - Integer pmfmId = Integer.valueOf(source.getLengthStepCaracteristic().getId()); - SortingMeasurement sortingMeasurement = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, pmfmId, - source.getLengthStep()); - notChangedSortingMeasurements.remove(sortingMeasurement); - } + // Add the batch into a list (will be update later, using this list) + batchsToUpdate.add(target); - // Individual count - if (copyIfNull && source.getNumber() == null) { - target.setIndividualCount(null); - } else if (source.getNumber() != null) { - target.setIndividualCount(source.getNumber()); - } + notUpdatedChildIds.remove(target.getId()); + } + } - // Species - target.setReferenceTaxon(null); + // If some batchs need to be update, do it + if (batchsToUpdate.size() > 0) { + sortingBatchDao.update(batchsToUpdate); + } - // QualityFlag - target.setQualityFlag(parentBatch.getQualityFlag()); + if (notUpdatedChildIds.size() > 0) { + for (Iterator<Integer> iterator = notUpdatedChildIds.iterator(); iterator.hasNext(); ) { + Integer batchId = iterator.next(); + catchBatchDao.removeWithChildren(batchId); + } + } - // Comments - if (copyIfNull && source.getComment() == null) { - target.setComments(null); - } else if (source.getComment() != null) { - target.setComments(source.getComment()); - } - - // Exhaustive inventory (always true under a species batch) - target.setExhaustiveInventory(true); + getCurrentSession().flush(); - // Removed not changed measurements (in sorting and quantification measurement lists) - if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { - for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { - target.getQuantificationMeasurements().remove(qm); - } - } - if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { - for (SortingMeasurement sm : notChangedSortingMeasurements) { - target.getSortingMeasurements().remove(sm); - } - } - } + return frequencies; + } - protected UIWeight convertDatabase2UI(Float weight, Float samplingRatio, String samplingRatioText) { - UIWeight result = new UIWeight(); + // ------------------------------------------------------------------------// + // -- Internal methods --// + // ------------------------------------------------------------------------// - // Weight & sampleCategory Weight - if (samplingRatio == null) { - result.sampleCategoryWeight = weight; - } else if (weight != null) { - String startStr = weight.toString().replace(',', '.') + "/"; - if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) { - String weightStr = samplingRatioText.substring(startStr.length()); - if (weightStr != null && !weightStr.isEmpty()) { - result.sampleCategoryWeight = Float.parseFloat(weightStr); - result.weight = weight; - } - } else { - result.sampleCategoryWeight = weight; - } - } - return result; - } + protected void validate(Collection<Batch> batchs, List<CatchBatchValidationError> errors, int treeLevel) { - static class UIWeight { - Float sampleCategoryWeight = null; + List<Integer> expectedPmfms = null; + boolean expectedReferenceTaxon = false; + // First tree level : should have pmfm SORTED (Vrac, Hors Vrac, Non trié) + if (treeLevel == 1) { + expectedPmfms = Lists.newArrayList(enumeration.PMFM_ID_SORTED_UNSORTED); + } + // Second tree level : should have pmfm SORTING_TYPE (Species, Benthos...) + else if (treeLevel == 2) { + expectedPmfms = Lists.newArrayList(enumeration.PMFM_ID_SORTING_TYPE); + } else if (treeLevel == 3) { + expectedReferenceTaxon = true; + } else if (treeLevel > 3) { + expectedPmfms = referentialService.getSampleCategoryIds(); + expectedPmfms.remove(enumeration.PMFM_ID_SORTED_UNSORTED); + } - Float weight = null; - } + // First level : should be only PMFM=SORTED + for (Iterator<Batch> iterator = batchs.iterator(); iterator.hasNext(); ) { + SortingBatch batch = (SortingBatch) iterator.next(); + boolean batchHasError = false; - protected void beanToEntity(CatchBatch source, - fr.ifremer.adagio.core.dao.data.batch.CatchBatch target, - boolean copyIfNull) { - Preconditions.checkNotNull(source.getFishingOperation()); - Preconditions.checkNotNull(source.getFishingOperation().getId()); + // For all sorting measurements + if (batch.getSortingMeasurements() != null && batch.getSortingMeasurements().size() > 0) { + for (Iterator<SortingMeasurement> iterator2 = batch.getSortingMeasurements().iterator(); iterator2.hasNext(); ) { + SortingMeasurement sm = iterator2.next(); + Integer pmfmId = sm.getPmfm().getId(); + if (expectedReferenceTaxon) { + CatchBatchValidationError error = new CatchBatchValidationError( + "tutti.persistence.batch.validation.onlyTaxonButPmfmFound", + _("tutti.persistence.batch.validation.onlyTaxonButPmfmFound", batch.getId(), pmfmId), + CatchBatchValidationError.GRAVITY_ERROR); + errors.add(error); + } else if (expectedPmfms.contains(pmfmId) == false) { + if (sm.getNumericalValue() == null || batch.getChildBatchs().size() > 0) { + batchHasError = true; + CatchBatchValidationError error = new CatchBatchValidationError( + "tutti.persistence.batch.validation.pmfmNotFound", + _("tutti.persistence.batch.validation.pmfmNotFound", + batch.getId(), Arrays.toString(expectedPmfms.toArray()), pmfmId), + CatchBatchValidationError.GRAVITY_ERROR); + errors.add(error); + } + } + } + } else if (expectedPmfms != null && expectedPmfms.size() > 0) { + batchHasError = true; + CatchBatchValidationError error = new CatchBatchValidationError( + "tutti.persistence.batch.validation.pmfmNotFound", + _("tutti.persistence.batch.validation.pmfmNotFound", + batch.getId(), Arrays.toString(expectedPmfms.toArray()), "null"), + CatchBatchValidationError.GRAVITY_ERROR); + errors.add(error); + } - // Retrieve recorder department - Integer recorderDepartmentId = getRecorderDepartmentId(); + if (!batchHasError && expectedReferenceTaxon == true && batch.getReferenceTaxon() == null) { + CatchBatchValidationError error = new CatchBatchValidationError( + "tutti.persistence.batch.validation.referenceTaxonNotFound", + _("tutti.persistence.batch.validation.referenceTaxonNotFound", batch.getId()), + CatchBatchValidationError.GRAVITY_ERROR); + errors.add(error); + } - // First initialization (when created) - Integer fishingOperationId = Integer.valueOf(source.getFishingOperation().getId()); - target.setFishingOperation(load(FishingOperationImpl.class, fishingOperationId)); + if (!batchHasError) { + validate(batch.getChildBatchs(), errors, treeLevel + 1); + } + } + } - target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); - target.setRankOrder((short) 1); - target.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue()); + protected void beanToEntity(SpeciesBatch source, + SortingBatch target, + String parentBatchId, + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch, + boolean copyIfNull) { + Preconditions.checkNotNull(source.getFishingOperation()); + Preconditions.checkNotNull(source.getFishingOperation().getId()); - // Create lists to store all updates, then remove not updated items - Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); - if (target.getQuantificationMeasurements() != null) { - notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); - } + // Retrieve recorder department + Integer recorderDepartmentId = getRecorderDepartmentId(); - // Total Weight - if (copyIfNull && source.getCatchTotalWeight() == null) { - // Nothing to do : will be removed later, using notChangedQuantificationMeasurements - } else if (source.getCatchTotalWeight() != null) { - QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getCatchTotalWeight(), true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } + // Create lists to store all updates, then remove not updated items + Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); + if (target.getQuantificationMeasurements() != null) { + notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); + } + Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); + if (target.getSortingMeasurements() != null) { + notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); + } - // Removed not changed measurements (in sorting and quantification measurement lists) - if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { - for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { - target.getQuantificationMeasurements().remove(qm); - } - } - Map<Integer, SortingBatch> catchBatchChilds = getChildsMap(target, enumeration.PMFM_ID_SORTED_UNSORTED); + // 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); + } - // ----------------------------------------------------------------------------- - // Sorted Vrac - // ----------------------------------------------------------------------------- - { - SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_VRAC_ID); - if (batch == null) { - batch = SortingBatch.Factory.newInstance(); - target.getChildBatchs().add(batch); - } - beanToEntitySortingBatch(target, target, batch, recorderDepartmentId, - enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, - source.getCatchTotalSortedCarousselWeight(), source.getCatchTotalSortedTremisWeight(), - copyIfNull); - batch.setRankOrder((short) 1); + // RankOrder (initialize once, at creation) + if (target.getRankOrder() == null) { + // Start rank order at 3, because of special batches 'Biota' and 'Inert' + short rankOrder = (short) 3; + if (source.getParentBatch() != null && source.getParentBatch().getChildBatchs() != null) { + // TODO BL : vérifier cela (est-ce que l'item est ajouté à son père AVANT d'être passé au service ?) + rankOrder += (short) source.getParentBatch().getChildBatchs().size(); + } + target.setRankOrder(rankOrder); + } - // Manage childs : - { - Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE); + // Force subgroup count to '1', as Allegro + target.setSubgroupCount(1f); - // ----------------------------------------------------------------------------- - // Sorted Vrac / Species - // ----------------------------------------------------------------------------- - 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); - } - } - beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, - source.getSpeciesTotalSampleSortedWeight(), source.getSpeciesTotalSortedWeight(), - copyIfNull); - speciesBatch.setRankOrder((short) 1); + // Weight or SampleCategoryWeight + if (copyIfNull && 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 = measurementHelper.setQuantificationMeasurement(target, + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getSampleCategoryWeight(), true); + notChangedQuantificationMeasurements.remove(quantificationMeasurement); + } else if (source.getWeight() != null && source.getSampleCategoryWeight() == null) { + QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); + notChangedQuantificationMeasurements.remove(quantificationMeasurement); + } - { - - // ----------------------------------------------------------------------------- - // Sorted Vrac / Species / Alive not itemized - // ----------------------------------------------------------------------------- - SortingBatch aliveNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); - if (aliveNotItemizedBatch == null) { - aliveNotItemizedBatch = SortingBatch.Factory.newInstance(); - if (speciesBatch.getChildBatchs() == null) { - speciesBatch.setChildBatchs(Lists.newArrayList((Batch) aliveNotItemizedBatch)); - } else { - speciesBatch.getChildBatchs().add(aliveNotItemizedBatch); - } - } - beanToEntityReferenceTaxonBatch(target, speciesBatch, aliveNotItemizedBatch, recorderDepartmentId, - enumeration.REFERENCE_TAXON_ID_LIFE, - source.getSpeciesTotalLivingNotItemizedWeight(), null, - copyIfNull); - aliveNotItemizedBatch.setRankOrder((short) 1); + // Sampling Ratio + if (copyIfNull && (source.getSampleCategoryWeight() == null || source.getWeight() == null)) { + target.setSamplingRatio(null); + target.setSamplingRatioText(null); + } else if (source.getSampleCategoryWeight() != null && source.getWeight() != null) { + String samplingRatioText = source.getWeight() + "/" + source.getSampleCategoryWeight(); + samplingRatioText = samplingRatioText.replaceAll(",", "."); + target.setSamplingRatioText(samplingRatioText); + target.setSamplingRatio(source.getWeight() / source.getSampleCategoryWeight()); + QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); + notChangedQuantificationMeasurements.remove(quantificationMeasurement); + } - // ----------------------------------------------------------------------------- - // Sorted Vrac / Species / Inert (not alive) - // ----------------------------------------------------------------------------- - SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); - if (inertBatch == null) { - inertBatch = SortingBatch.Factory.newInstance(); - speciesBatch.getChildBatchs().add(inertBatch); - } - beanToEntityReferenceTaxonBatch(target, speciesBatch, inertBatch, recorderDepartmentId, - enumeration.REFERENCE_TAXON_ID_INERT, - source.getSpeciesTotalInertWeight(), null, - copyIfNull); - inertBatch.setRankOrder((short) 2); - } - } - // TODO BL : benthos, plancton, macro déchet... - } + // Sorting measurement + if (copyIfNull && (source.getSampleCategoryType() == null || source.getSampleCategoryValue() == null)) { + // Nothing to do : will be removed later, using notChangedSortingMeasurements + } else if (source.getSampleCategoryType() != null && source.getSampleCategoryValue() != null) { + Integer pmfmId = measurementHelper.sampleCategory2PmfmId(source.getSampleCategoryType()); + // Do not store sorting measurement if pmfm = SORTED (already store in an ancestor batch) + if (!pmfmId.equals(enumeration.PMFM_ID_SORTED_UNSORTED)) { + SortingMeasurement sortingMeasurement = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, + source.getSampleCategoryType(), source.getSampleCategoryValue()); + notChangedSortingMeasurements.remove(sortingMeasurement); + } + } - // ----------------------------------------------------------------------------- - // Sorted Hors Vrac - // ----------------------------------------------------------------------------- - { - SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_HORS_VRAC_ID); - if (batch == null) { - batch = SortingBatch.Factory.newInstance(); - target.getChildBatchs().add(batch); - } - beanToEntitySortingBatch(target, target, batch, recorderDepartmentId, - enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, - source.getCatchTotalUnsortedWeight(), null, - copyIfNull); - batch.setRankOrder((short) 2); + // Individual count + if (copyIfNull && source.getNumber() == null) { + target.setIndividualCount(null); + } else if (source.getNumber() != null) { + target.setIndividualCount(source.getNumber()); + } - // Manage childs : - { - Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE); + // Species + if (copyIfNull && (source.getSpecies() == null || parentBatchId != null)) { + target.setReferenceTaxon(null); + } else if (source.getSpecies() != null && parentBatchId == null) { + ReferenceTaxon referenceTaxon = load(ReferenceTaxonImpl.class, source.getSpecies().getReferenceTaxonId()); + target.setReferenceTaxon(referenceTaxon); + } - // Species : - 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); - } - } - beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, - source.getSpeciesTotalUnsortedWeight(), null, - copyIfNull); - speciesBatch.setRankOrder((short) 1); - } + // QualityFlag + if (source.isSpeciesToConfirm()) { + target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_DOUBTFUL)); + } else { + target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); + } - // TODO BL : benthos, plancton, macro déchet... - } + // Comments + if (copyIfNull && source.getComment() == null) { + target.setComments(null); + } else if (source.getComment() != null) { + target.setComments(source.getComment()); + } - // ----------------------------------------------------------------------------- - // Unsorted (=rejected) - // ----------------------------------------------------------------------------- - // Unsorted : - SortingBatch unsortedBatch = catchBatchChilds.get(enumeration.QUALITATIVE_UNSORTED_ID); - if (unsortedBatch == null) { - unsortedBatch = SortingBatch.Factory.newInstance(); - target.getChildBatchs().add(unsortedBatch); - } - beanToEntitySortingBatch(target, target, unsortedBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID, - source.getCatchTotalRejectedWeight(), null, - copyIfNull); - unsortedBatch.setRankOrder((short) 3); + // Exhaustive inventory (always true under a species batch) + target.setExhaustiveInventory(true); - } + // Removed not changed measurements (in sorting and quantification measurement lists) + if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { + for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { + target.getQuantificationMeasurements().remove(qm); + } + } + if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { + for (SortingMeasurement sm : notChangedSortingMeasurements) { + target.getSortingMeasurements().remove(sm); + } + } + } - protected Map<Integer, SortingBatch> getChildsMap(Batch parentBatch, Integer pmfmId) { - Map<Integer, SortingBatch> batchByQualitativeValueId = new HashMap<Integer, SortingBatch>(); - if (parentBatch.getChildBatchs() == null) { - return batchByQualitativeValueId; - } - for (Batch childBatch : parentBatch.getChildBatchs()) { - SortingBatch childSortingBatch = (SortingBatch) childBatch; - SortingMeasurement sm = measurementHelper.getSortingMeasurement((SortingBatch) childBatch, pmfmId, null, false); - if (sm != null && sm.getQualitativeValue() != null && sm.getQualitativeValue().getId() != null) { - batchByQualitativeValueId.put(sm.getQualitativeValue().getId(), childSortingBatch); - } - } - return batchByQualitativeValueId; - } + public void setBatchParents(SpeciesBatch source, SortingBatch target, String parentBatchIdStr, + fr.ifremer.adagio.core.dao.data.batch.CatchBatch catchBatch) { - /** - * Retrieve child batchs if species is "Life" or "No life" - * (need to retrieve: speciesTotalLivingNotItemizedWeight and speciesTotalInertWeight) - * - * @param parentBatch - * @return - */ - protected Map<Integer, SortingBatch> getChildAliveNotSortedOrInert(Batch parentBatch) { - Map<Integer, SortingBatch> batchByQualitativeValueId = new HashMap<Integer, SortingBatch>(); - if (parentBatch.getChildBatchs() == null) { - return batchByQualitativeValueId; - } - for (Batch childBatch : parentBatch.getChildBatchs()) { - SortingBatch childSortingBatch = (SortingBatch) childBatch; - if (childSortingBatch.getReferenceTaxon() != null && childSortingBatch.getId().intValue() < 0) { - if (enumeration.REFERENCE_TAXON_ID_LIFE.equals(childSortingBatch.getId())) { - batchByQualitativeValueId.put(enumeration.REFERENCE_TAXON_ID_LIFE, childSortingBatch); - } else if (enumeration.REFERENCE_TAXON_ID_LIFE.equals(childSortingBatch.getId())) { - batchByQualitativeValueId.put(enumeration.REFERENCE_TAXON_ID_LIFE, childSortingBatch); - } - } - } - return batchByQualitativeValueId; - } + Preconditions.checkNotNull(target); + Preconditions.checkNotNull(source.getFishingOperation()); + Preconditions.checkNotNull(source.getFishingOperation().getId()); - protected void beanToEntitySortingBatch( - fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, - fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch, - fr.ifremer.adagio.core.dao.data.batch.SortingBatch target, - Integer recorderDepartmentId, - Integer sortingPmfmId, - Integer sortingQualitativeValueId, - Float weight, - Float sampleWeight, - boolean copyIfNull) { + // Load existing parent and root + SortingBatch parentBatch = null; + if (parentBatchIdStr != null) { + parentBatch = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(parentBatchIdStr)); + } - // Create lists to store all updates, then remove not updated items - Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); - if (target.getQuantificationMeasurements() != null) { - notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); - } - Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); - if (target.getSortingMeasurements() != null) { - notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); - } + // Or retrieve parent batch, from pmfm id + else { + // Retrieve category type + Integer pmfmId = measurementHelper.sampleCategory2PmfmId(source.getSampleCategoryType()); + 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()); - // Some mandatory properties : - target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); - target.setRootBatch(rootBatch); - target.setParentBatch(parentBatch); - target.setExhaustiveInventory(true); + parentBatch = catchBatchDao.getSortingBatch(catchBatch.getChildBatchs(), + "pmfmId", pmfmId, qualitativeValueId, + "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - // No taxon or taxon group - target.setReferenceTaxon(null); - target.setTaxonGroup(null); + // Parent Batch + target.setParentBatch(parentBatch); + } - // Sorting measurement - if (copyIfNull && (sortingPmfmId == null || sortingQualitativeValueId == null)) { - // Nothing to do : will be removed later, using notChangedSortingMeasurements - } else if (sortingPmfmId != null && sortingQualitativeValueId != null) { - SortingMeasurement sm = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, sortingPmfmId, sortingQualitativeValueId); - notChangedSortingMeasurements.remove(sm); - } - // Sampling Ratio - if (copyIfNull && (sampleWeight == null || weight == null)) { - target.setSamplingRatio(null); - target.setSamplingRatioText(null); - } else if (sampleWeight != null && weight != null) { - String samplingRatioText = weight + "/" + sampleWeight; - samplingRatioText = samplingRatioText.replaceAll(",", "."); - target.setSamplingRatioText(samplingRatioText); - target.setSamplingRatio(weight / sampleWeight); - } + 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."); + } - // Weight - if (copyIfNull && (sampleWeight == null && weight == null)) { - // Nothing to do : will be removed later, using notChangedQuantificationMeasurements - } else if (sampleWeight != null || weight != null) { - Float batchReferenceWeight = weight; - if (batchReferenceWeight == null) { - batchReferenceWeight = sampleWeight; - } - QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } + // Parent Batch + target.setParentBatch(parentBatch); + target.setRootBatch(catchBatch); + } - // Removed not changed measurements (in sorting and quantification measurement lists) - if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { - for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { - target.getQuantificationMeasurements().remove(qm); - } - } - if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { - for (SortingMeasurement sm : notChangedSortingMeasurements) { - target.getSortingMeasurements().remove(sm); - } - } - } + Integer convertSampleCategoryValueIntoQualitativeId(Serializable value) { + if (value == null) + return null; + Integer qualitativeValueId = null; + if (value instanceof CaracteristicQualitativeValue) { + CaracteristicQualitativeValue cqValue = (CaracteristicQualitativeValue) value; + qualitativeValueId = Integer.valueOf(cqValue.getId()); + } else if (value instanceof String) { + qualitativeValueId = Integer.valueOf((String) value); + } + return qualitativeValueId; + } - protected void beanToEntityReferenceTaxonBatch( - fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, - fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch, - fr.ifremer.adagio.core.dao.data.batch.SortingBatch target, - Integer recorderDepartmentId, - Integer referenceTaxonId, - Float weight, - Float sampleWeight, - boolean copyIfNull) { + protected void setSampleCategoryQualitative(SpeciesBatch target, Integer pmfmId, Float numericalvalue, String alphanumericalValue, + Integer qualitativeValueId) { + // skip if null or corresponding to the SORTING_TYPE PMFM (Expèce, Benthos, Plancton, etc.) + if (pmfmId == null || pmfmId.equals(enumeration.PMFM_ID_SORTING_TYPE)) { + return; + } - // Create lists to store all updates, then remove not updated items - Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); - if (target.getQuantificationMeasurements() != null) { - notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); - } - Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); - if (target.getSortingMeasurements() != null) { - notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); - } + SampleCategoryEnum sampleCategory = referentialService.getSampleCategoryByPmfmId(pmfmId); + Preconditions.checkNotNull(sampleCategory, "Unable to find corresponding SampleCategoryEnum for PMFM.ID : " + pmfmId); - // Some mandatory properties : - target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); - target.setRootBatch(rootBatch); - target.setParentBatch(parentBatch); - target.setExhaustiveInventory(true); + target.setSampleCategoryType(sampleCategory); + if (numericalvalue != null) { + target.setSampleCategoryValue(numericalvalue); + return; + } + if (alphanumericalValue != null) { + target.setSampleCategoryValue(alphanumericalValue); + return; + } - // Reference taxon - target.setReferenceTaxon(load(ReferenceTaxonImpl.class, referenceTaxonId)); - target.setTaxonGroup(null); + Caracteristic caracteristic = referentialService.getCaracteristic(pmfmId); + if (caracteristic == null || caracteristic.getCaracteristicType() != CaracteristicType.QUALITATIVE) { + return; + } + CaracteristicQualitativeValue value = null; + for (CaracteristicQualitativeValue qv : caracteristic.getQualitativeValue()) { + if (qualitativeValueId == Integer.parseInt(qv.getId())) { + value = qv; + break; + } + } + target.setSampleCategoryValue(value); + } - // Sampling Ratio - if (copyIfNull && (sampleWeight == null || weight == null)) { - target.setSamplingRatio(null); - target.setSamplingRatioText(null); - } else if (sampleWeight != null && weight != null) { - String samplingRatioText = weight + "/" + sampleWeight; - samplingRatioText = samplingRatioText.replaceAll(",", "."); - target.setSamplingRatioText(samplingRatioText); - target.setSamplingRatio(weight / sampleWeight); - } + protected void beanToEntity(SpeciesBatchFrequency source, SortingBatch target, SortingBatch parentBatch, short rankOrder, boolean copyIfNull) { + Preconditions.checkNotNull(source.getBatch()); + Preconditions.checkNotNull(source.getBatch().getId()); - // Weight - if (copyIfNull && (sampleWeight == null && weight == null)) { - // Nothing to do : will be removed later, using notChangedQuantificationMeasurements - } else if (sampleWeight != null || weight != null) { - Float batchReferenceWeight = weight; - if (batchReferenceWeight == null) { - batchReferenceWeight = sampleWeight; - } - QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, - enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); - notChangedQuantificationMeasurements.remove(quantificationMeasurement); - } + // Retrieve recorder department + Integer recorderDepartmentId = getRecorderDepartmentId(); - // Removed not changed measurements (in sorting and quantification measurement lists) - if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { - for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { - target.getQuantificationMeasurements().remove(qm); - } - } - if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { - for (SortingMeasurement sm : notChangedSortingMeasurements) { - target.getSortingMeasurements().remove(sm); - } - } - } - - protected Integer getRecorderDepartmentId() { - // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?) - return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT; - } + // Create lists to store all updates, then remove not updated items + Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); + if (target.getQuantificationMeasurements() != null) { + notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); + } + Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); + if (target.getSortingMeasurements() != null) { + notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); + } + + // 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 (copyIfNull && source.getWeight() == null) { + // Nothing to do : will be removed later, using notChangedSortingMeasurements + } else if (source.getWeight() != null) { + QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getWeight(), true); + notChangedQuantificationMeasurements.remove(quantificationMeasurement); + } + + // Sorting measurement + if (copyIfNull && (source.getLengthStepCaracteristic() == null || source.getLengthStep() == null)) { + // Nothing to do : will be removed later, using notChangedSortingMeasurements + } else if (source.getLengthStepCaracteristic() != null && source.getLengthStep() != null) { + Integer pmfmId = Integer.valueOf(source.getLengthStepCaracteristic().getId()); + SortingMeasurement sortingMeasurement = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, pmfmId, + source.getLengthStep()); + notChangedSortingMeasurements.remove(sortingMeasurement); + } + + // Individual count + if (copyIfNull && source.getNumber() == null) { + target.setIndividualCount(null); + } else if (source.getNumber() != null) { + target.setIndividualCount(source.getNumber()); + } + + // Species + target.setReferenceTaxon(null); + + // QualityFlag + target.setQualityFlag(parentBatch.getQualityFlag()); + + // Comments + if (copyIfNull && source.getComment() == null) { + target.setComments(null); + } else if (source.getComment() != null) { + 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 (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { + for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { + target.getQuantificationMeasurements().remove(qm); + } + } + if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { + for (SortingMeasurement sm : notChangedSortingMeasurements) { + target.getSortingMeasurements().remove(sm); + } + } + } + + protected UIWeight convertDatabase2UI(Float weight, Float samplingRatio, String samplingRatioText) { + UIWeight result = new UIWeight(); + + // Weight & sampleCategory Weight + if (samplingRatio == null) { + result.sampleCategoryWeight = weight; + } else if (weight != null) { + String startStr = weight.toString().replace(',', '.') + "/"; + if (samplingRatioText != null && samplingRatioText.startsWith(startStr)) { + String weightStr = samplingRatioText.substring(startStr.length()); + if (weightStr != null && !weightStr.isEmpty()) { + result.sampleCategoryWeight = Float.parseFloat(weightStr); + result.weight = weight; + } + } else { + result.sampleCategoryWeight = weight; + } + } + return result; + } + + static class UIWeight { + Float sampleCategoryWeight = null; + + Float weight = null; + } + + protected void beanToEntity(CatchBatch source, + fr.ifremer.adagio.core.dao.data.batch.CatchBatch target, + boolean copyIfNull) { + Preconditions.checkNotNull(source.getFishingOperation()); + Preconditions.checkNotNull(source.getFishingOperation().getId()); + + // Retrieve recorder department + Integer recorderDepartmentId = getRecorderDepartmentId(); + + // First initialization (when created) + Integer fishingOperationId = Integer.valueOf(source.getFishingOperation().getId()); + target.setFishingOperation(load(FishingOperationImpl.class, fishingOperationId)); + + target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); + target.setRankOrder((short) 1); + target.setSynchronizationStatus(SynchronizationStatus.DIRTY.getValue()); + + // Create lists to store all updates, then remove not updated items + Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); + if (target.getQuantificationMeasurements() != null) { + notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); + } + + // Total Weight + if (copyIfNull && source.getCatchTotalWeight() == null) { + // Nothing to do : will be removed later, using notChangedQuantificationMeasurements + } else if (source.getCatchTotalWeight() != null) { + QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, source.getCatchTotalWeight(), true); + notChangedQuantificationMeasurements.remove(quantificationMeasurement); + } + + // Removed not changed measurements (in sorting and quantification measurement lists) + if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { + for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { + target.getQuantificationMeasurements().remove(qm); + } + } + Map<Integer, SortingBatch> catchBatchChilds = getChildsMap(target, enumeration.PMFM_ID_SORTED_UNSORTED); + + // ----------------------------------------------------------------------------- + // Sorted Vrac + // ----------------------------------------------------------------------------- + { + SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_VRAC_ID); + if (batch == null) { + batch = SortingBatch.Factory.newInstance(); + target.getChildBatchs().add(batch); + } + beanToEntitySortingBatch(target, target, batch, recorderDepartmentId, + enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_VRAC_ID, + source.getCatchTotalSortedCarousselWeight(), source.getCatchTotalSortedTremisWeight(), + copyIfNull); + batch.setRankOrder((short) 1); + + // Manage childs : + { + Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE); + + // ----------------------------------------------------------------------------- + // Sorted Vrac / Species + // ----------------------------------------------------------------------------- + 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); + } + } + beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, + source.getSpeciesTotalSampleSortedWeight(), source.getSpeciesTotalSortedWeight(), + copyIfNull); + speciesBatch.setRankOrder((short) 1); + + { + + // ----------------------------------------------------------------------------- + // Sorted Vrac / Species / Alive not itemized + // ----------------------------------------------------------------------------- + SortingBatch aliveNotItemizedBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_LIFE); + if (aliveNotItemizedBatch == null) { + aliveNotItemizedBatch = SortingBatch.Factory.newInstance(); + if (speciesBatch.getChildBatchs() == null) { + speciesBatch.setChildBatchs(Lists.newArrayList((Batch) aliveNotItemizedBatch)); + } else { + speciesBatch.getChildBatchs().add(aliveNotItemizedBatch); + } + } + beanToEntityReferenceTaxonBatch(target, speciesBatch, aliveNotItemizedBatch, recorderDepartmentId, + enumeration.REFERENCE_TAXON_ID_LIFE, + source.getSpeciesTotalLivingNotItemizedWeight(), null, + copyIfNull); + aliveNotItemizedBatch.setRankOrder((short) 1); + + // ----------------------------------------------------------------------------- + // Sorted Vrac / Species / Inert (not alive) + // ----------------------------------------------------------------------------- + SortingBatch inertBatch = catchBatchDao.getSortingBatch(speciesBatch.getChildBatchs(), "referenceTaxonId", enumeration.REFERENCE_TAXON_ID_INERT); + if (inertBatch == null) { + inertBatch = SortingBatch.Factory.newInstance(); + speciesBatch.getChildBatchs().add(inertBatch); + } + beanToEntityReferenceTaxonBatch(target, speciesBatch, inertBatch, recorderDepartmentId, + enumeration.REFERENCE_TAXON_ID_INERT, + source.getSpeciesTotalInertWeight(), null, + copyIfNull); + inertBatch.setRankOrder((short) 2); + } + } + // TODO BL : benthos, plancton, macro déchet... + } + + // ----------------------------------------------------------------------------- + // Sorted Hors Vrac + // ----------------------------------------------------------------------------- + { + SortingBatch batch = catchBatchChilds.get(enumeration.QUALITATIVE_HORS_VRAC_ID); + if (batch == null) { + batch = SortingBatch.Factory.newInstance(); + target.getChildBatchs().add(batch); + } + beanToEntitySortingBatch(target, target, batch, recorderDepartmentId, + enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_HORS_VRAC_ID, + source.getCatchTotalUnsortedWeight(), null, + copyIfNull); + batch.setRankOrder((short) 2); + + // Manage childs : + { + Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE); + + // Species : + 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); + } + } + beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, + source.getSpeciesTotalUnsortedWeight(), null, + copyIfNull); + speciesBatch.setRankOrder((short) 1); + } + + // TODO BL : benthos, plancton, macro déchet... + } + + // ----------------------------------------------------------------------------- + // Unsorted (=rejected) + // ----------------------------------------------------------------------------- + // Unsorted : + SortingBatch unsortedBatch = catchBatchChilds.get(enumeration.QUALITATIVE_UNSORTED_ID); + if (unsortedBatch == null) { + unsortedBatch = SortingBatch.Factory.newInstance(); + target.getChildBatchs().add(unsortedBatch); + } + beanToEntitySortingBatch(target, target, unsortedBatch, recorderDepartmentId, + enumeration.PMFM_ID_SORTED_UNSORTED, enumeration.QUALITATIVE_UNSORTED_ID, + source.getCatchTotalRejectedWeight(), null, + copyIfNull); + unsortedBatch.setRankOrder((short) 3); + + } + + protected Map<Integer, SortingBatch> getChildsMap(Batch parentBatch, Integer pmfmId) { + Map<Integer, SortingBatch> batchByQualitativeValueId = new HashMap<Integer, SortingBatch>(); + if (parentBatch.getChildBatchs() == null) { + return batchByQualitativeValueId; + } + for (Batch childBatch : parentBatch.getChildBatchs()) { + SortingBatch childSortingBatch = (SortingBatch) childBatch; + SortingMeasurement sm = measurementHelper.getSortingMeasurement((SortingBatch) childBatch, pmfmId, null, false); + if (sm != null && sm.getQualitativeValue() != null && sm.getQualitativeValue().getId() != null) { + batchByQualitativeValueId.put(sm.getQualitativeValue().getId(), childSortingBatch); + } + } + return batchByQualitativeValueId; + } + + /** + * Retrieve child batchs if species is "Life" or "No life" + * (need to retrieve: speciesTotalLivingNotItemizedWeight and speciesTotalInertWeight) + * + * @param parentBatch + * @return + */ + protected Map<Integer, SortingBatch> getChildAliveNotSortedOrInert(Batch parentBatch) { + Map<Integer, SortingBatch> batchByQualitativeValueId = new HashMap<Integer, SortingBatch>(); + if (parentBatch.getChildBatchs() == null) { + return batchByQualitativeValueId; + } + for (Batch childBatch : parentBatch.getChildBatchs()) { + SortingBatch childSortingBatch = (SortingBatch) childBatch; + if (childSortingBatch.getReferenceTaxon() != null && childSortingBatch.getId().intValue() < 0) { + if (enumeration.REFERENCE_TAXON_ID_LIFE.equals(childSortingBatch.getId())) { + batchByQualitativeValueId.put(enumeration.REFERENCE_TAXON_ID_LIFE, childSortingBatch); + } else if (enumeration.REFERENCE_TAXON_ID_LIFE.equals(childSortingBatch.getId())) { + batchByQualitativeValueId.put(enumeration.REFERENCE_TAXON_ID_LIFE, childSortingBatch); + } + } + } + return batchByQualitativeValueId; + } + + protected void beanToEntitySortingBatch( + fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, + fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch, + fr.ifremer.adagio.core.dao.data.batch.SortingBatch target, + Integer recorderDepartmentId, + Integer sortingPmfmId, + Integer sortingQualitativeValueId, + Float weight, + Float sampleWeight, + boolean copyIfNull) { + + // Create lists to store all updates, then remove not updated items + Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); + if (target.getQuantificationMeasurements() != null) { + notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); + } + Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); + if (target.getSortingMeasurements() != null) { + notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); + } + + // Some mandatory properties : + target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); + target.setRootBatch(rootBatch); + target.setParentBatch(parentBatch); + target.setExhaustiveInventory(true); + + // No taxon or taxon group + target.setReferenceTaxon(null); + target.setTaxonGroup(null); + + // Sorting measurement + if (copyIfNull && (sortingPmfmId == null || sortingQualitativeValueId == null)) { + // Nothing to do : will be removed later, using notChangedSortingMeasurements + } else if (sortingPmfmId != null && sortingQualitativeValueId != null) { + SortingMeasurement sm = measurementHelper.setSortingMeasurement(target, recorderDepartmentId, sortingPmfmId, sortingQualitativeValueId); + notChangedSortingMeasurements.remove(sm); + } + + // Sampling Ratio + if (copyIfNull && (sampleWeight == null || weight == null)) { + target.setSamplingRatio(null); + target.setSamplingRatioText(null); + } else if (sampleWeight != null && weight != null) { + String samplingRatioText = weight + "/" + sampleWeight; + samplingRatioText = samplingRatioText.replaceAll(",", "."); + target.setSamplingRatioText(samplingRatioText); + target.setSamplingRatio(weight / sampleWeight); + } + + // Weight + if (copyIfNull && (sampleWeight == null && weight == null)) { + // Nothing to do : will be removed later, using notChangedQuantificationMeasurements + } else if (sampleWeight != null || weight != null) { + Float batchReferenceWeight = weight; + if (batchReferenceWeight == null) { + batchReferenceWeight = sampleWeight; + } + QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); + notChangedQuantificationMeasurements.remove(quantificationMeasurement); + } + + // Removed not changed measurements (in sorting and quantification measurement lists) + if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { + for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { + target.getQuantificationMeasurements().remove(qm); + } + } + if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { + for (SortingMeasurement sm : notChangedSortingMeasurements) { + target.getSortingMeasurements().remove(sm); + } + } + } + + protected void beanToEntityReferenceTaxonBatch( + fr.ifremer.adagio.core.dao.data.batch.CatchBatch rootBatch, + fr.ifremer.adagio.core.dao.data.batch.Batch parentBatch, + fr.ifremer.adagio.core.dao.data.batch.SortingBatch target, + Integer recorderDepartmentId, + Integer referenceTaxonId, + Float weight, + Float sampleWeight, + boolean copyIfNull) { + + // Create lists to store all updates, then remove not updated items + Set<QuantificationMeasurement> notChangedQuantificationMeasurements = new HashSet<QuantificationMeasurement>(); + if (target.getQuantificationMeasurements() != null) { + notChangedQuantificationMeasurements.addAll(target.getQuantificationMeasurements()); + } + Set<SortingMeasurement> notChangedSortingMeasurements = new HashSet<SortingMeasurement>(); + if (target.getSortingMeasurements() != null) { + notChangedSortingMeasurements.addAll(target.getSortingMeasurements()); + } + + // Some mandatory properties : + target.setQualityFlag(load(QualityFlagImpl.class, enumeration.QUALITY_FLAG_CODE_NOT_QUALIFIED)); + target.setRootBatch(rootBatch); + target.setParentBatch(parentBatch); + target.setExhaustiveInventory(true); + + // Reference taxon + target.setReferenceTaxon(load(ReferenceTaxonImpl.class, referenceTaxonId)); + target.setTaxonGroup(null); + + // Sampling Ratio + if (copyIfNull && (sampleWeight == null || weight == null)) { + target.setSamplingRatio(null); + target.setSamplingRatioText(null); + } else if (sampleWeight != null && weight != null) { + String samplingRatioText = weight + "/" + sampleWeight; + samplingRatioText = samplingRatioText.replaceAll(",", "."); + target.setSamplingRatioText(samplingRatioText); + target.setSamplingRatio(weight / sampleWeight); + } + + // Weight + if (copyIfNull && (sampleWeight == null && weight == null)) { + // Nothing to do : will be removed later, using notChangedQuantificationMeasurements + } else if (sampleWeight != null || weight != null) { + Float batchReferenceWeight = weight; + if (batchReferenceWeight == null) { + batchReferenceWeight = sampleWeight; + } + QuantificationMeasurement quantificationMeasurement = measurementHelper.setQuantificationMeasurement(target, + enumeration.PMFM_ID_WEIGHT_MEASURED, recorderDepartmentId, batchReferenceWeight, true); + notChangedQuantificationMeasurements.remove(quantificationMeasurement); + } + + // Removed not changed measurements (in sorting and quantification measurement lists) + if (target.getQuantificationMeasurements() != null && notChangedQuantificationMeasurements.size() > 0) { + for (QuantificationMeasurement qm : notChangedQuantificationMeasurements) { + target.getQuantificationMeasurements().remove(qm); + } + } + if (target.getSortingMeasurements() != null && notChangedSortingMeasurements.size() > 0) { + for (SortingMeasurement sm : notChangedSortingMeasurements) { + target.getSortingMeasurements().remove(sm); + } + } + } + + protected Integer getRecorderDepartmentId() { + // TODO BL : voir si on peut récupérer le departement (du 1er saisisseur ?) + return enumeration.DEPARTMENT_ID_UNKNOWN_RECORDER_DEPARTMENT; + } } \ No newline at end of file Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java 2013-02-15 20:28:55 UTC (rev 432) @@ -316,21 +316,21 @@ // Strata : Integer strataId = (Integer) source[colIndex++]; if (strataId != null) { - FishingOperationLocation strata = referentialService.getFishingOperationLocation(strataId.toString()); + FishingOperationLocation strata = referentialService.getFishingOperationLocation(strataId.toString()); result.setStrata(strata); } // Sub Strata : Integer subStrataId = (Integer) source[colIndex++]; if (subStrataId != null) { - FishingOperationLocation subStrata = referentialService.getFishingOperationLocation(subStrataId.toString()); + FishingOperationLocation subStrata = referentialService.getFishingOperationLocation(subStrataId.toString()); result.setSubStrata(subStrata); } // Localite : Integer localiteId = (Integer) source[colIndex++]; if (localiteId != null) { - FishingOperationLocation localite = referentialService.getFishingOperationLocation(localiteId.toString()); + FishingOperationLocation localite = referentialService.getFishingOperationLocation(localiteId.toString()); result.setLocation(localite); } @@ -372,9 +372,9 @@ Preconditions.checkNotNull(bean.getId()); Preconditions.checkNotNull(bean.getCruise()); Preconditions.checkNotNull(bean.getCruise().getId()); - + if (bean.getGearShootingStartDate() != null && bean.getGearShootingEndDate() != null) { - Preconditions.checkArgument(bean.getGearShootingStartDate().equals(bean.getGearShootingEndDate()) == false); + Preconditions.checkArgument(bean.getGearShootingStartDate().equals(bean.getGearShootingEndDate()) == false); } getCurrentSession().clear(); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-15 20:28:55 UTC (rev 432) @@ -188,9 +188,9 @@ Caracteristic getCaracteristic(Integer pmfmId); boolean isSortedQualitativeValue(CaracteristicQualitativeValue value); - + List<Integer> getSampleCategoryIds(); - + /** * Import given temporary species. * Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-15 20:28:55 UTC (rev 432) @@ -212,16 +212,16 @@ parentLocationLevelId); return result; } - + @Override public FishingOperationLocation getFishingOperationLocation(String id) { - Object[] source = queryUnique( + Object[] source = queryUnique( "fishingOperationLocationById", "locationId", IntegerType.INSTANCE, Integer.valueOf(id) - ); - if (source == null) { - return null; - } + ); + if (source == null) { + return null; + } FishingOperationLocation target = new FishingOperationLocation(); target.setId(String.valueOf(source[0])); target.setLabel((String) source[1]); @@ -822,10 +822,10 @@ */ public List<Integer> getSampleCategoryIds() { return Lists.newArrayList(enumeration.PMFM_ID_SORTED_UNSORTED - , enumeration.PMFM_ID_SIZE_CATEGORY - , enumeration.PMFM_ID_MATURITY - , enumeration.PMFM_ID_SEX - , enumeration.PMFM_ID_AGE); + , enumeration.PMFM_ID_SIZE_CATEGORY + , enumeration.PMFM_ID_MATURITY + , enumeration.PMFM_ID_SEX + , enumeration.PMFM_ID_AGE); } /** Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/TuttiEnumerationFile.java 2013-02-15 20:28:55 UTC (rev 432) @@ -193,7 +193,7 @@ @Value("${ReferenceTaxonId.INERT}") public final Integer REFERENCE_TAXON_ID_INERT = null; - + public void init() { Field[] declaredFields = getClass().getDeclaredFields(); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/measure/MeasurementPersistenceHelper.java 2013-02-15 20:28:55 UTC (rev 432) @@ -206,10 +206,10 @@ return sortingMeasurement; } - + public SortingMeasurement getInheritedSortingMeasurement( SortingBatch sortingBatch, Integer pmfmId) { - if (sortingBatch.getInheritedSortingMeasurements() != null) { + if (sortingBatch.getInheritedSortingMeasurements() != null) { for (SortingMeasurement qm : sortingBatch .getInheritedSortingMeasurements()) { if (pmfmId.equals(qm.getPmfm().getId())) { Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/synchro/TuttiTableMetadata.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/synchro/TuttiTableMetadata.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/synchro/TuttiTableMetadata.java 2013-02-15 20:28:55 UTC (rev 432) @@ -94,9 +94,11 @@ protected final boolean withUpdateDateColumn; public abstract String getCountDataToUpdateQueryWithNull(); + public abstract String getDataToUpdateQueryWithNull(); public abstract String getCountDataToUpdateQuery(); + public abstract String getDataToUpdateQuery(); public abstract boolean useUpdateDateColumn(); Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceReadTest.java 2013-02-15 20:28:55 UTC (rev 432) @@ -24,30 +24,28 @@ * #L% */ -import static org.junit.Assert.*; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.Map; - +import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.DatabaseResource; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; - import org.junit.Before; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Test; import org.springframework.dao.DataRetrievalFailureException; -import com.google.common.collect.Maps; +import java.util.List; +import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * To test {@link CatchBatchPersistenceService} for read operation. * @@ -60,14 +58,16 @@ public static final DatabaseResource dbResource = DatabaseResource.readDb(); protected BatchPersistenceService service; + protected FishingOperationPersistenceService fishingOperationService; + protected FishingOperation fishingOperation; @Before public void setUp() throws Exception { service = TuttiPersistenceServiceLocator.getBatchPersistenceService(); fishingOperationService = TuttiPersistenceServiceLocator.getFishingOperationPersistenceService(); - + List<FishingOperation> fishingOperations = fishingOperationService.getAllFishingOperation(dbResource.getFixtures().cruiseId()); assertNotNull(fishingOperations); assertTrue(fishingOperations.size() > 0); @@ -79,15 +79,14 @@ @Test public void getCatchBatchFromFishingOperation() throws Exception { - try { - CatchBatch catchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); - fail("batch tree must be invalid (old CGFS tree structure), for fishing operation id=" + fishingOperation.getId()); - } - catch(DataRetrievalFailureException drfe) { - // success - } + try { + CatchBatch catchBatch = service.getCatchBatchFromFishingOperation(fishingOperation.getId()); + fail("batch tree must be invalid (old CGFS tree structure), for fishing operation id=" + fishingOperation.getId()); + } catch (DataRetrievalFailureException drfe) { + // success + } } - + @Test public void getAllRootSpeciesBatch(/*String fishingOperationId*/) { } Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceWriteTest.java 2013-02-15 20:28:55 UTC (rev 432) @@ -24,6 +24,8 @@ * #L% */ +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.DatabaseResource; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; @@ -37,13 +39,9 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import org.junit.Before; import org.junit.ClassRule; -import org.junit.Ignore; import org.junit.Test; import org.springframework.dao.DataRetrievalFailureException; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -51,8 +49,10 @@ import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; /** * To test {@link CatchBatchPersistenceService} for write operation. @@ -70,29 +70,29 @@ protected CruisePersistenceService cruiseService; protected FishingOperationPersistenceService fishingOperationService; - + protected CatchBatchPersistenceService catchBatchService; - + protected ReferentialPersistenceService referentialService; protected Cruise cruise; protected FishingOperation fishingOperationNoCatchBatch; - + protected FishingOperation fishingOperationWithEmptyBatch; - + protected CatchBatch catchBacth; - + protected List<Species> species; - + protected Caracteristic sortedUnsortedPMFM; protected CaracteristicQualitativeValue horsVracQualitativeValue; protected CaracteristicQualitativeValue vracQualitativeValue; - + protected Caracteristic maturityPMFM; - + protected CaracteristicQualitativeValue firstMaturityQualitativeValue; protected Caracteristic sexPMFM; @@ -143,7 +143,7 @@ calendar.set(Calendar.MILLISECOND, 0); fishingOperationNoCatchBatch.setGearShootingEndDate(calendar.getTime()); fishingOperationNoCatchBatch = fishingOperationService.createFishingOperation(fishingOperationNoCatchBatch); - + // Create a second operation, with no cacth batch : to test CatchBatch insert/update : fishingOperationWithEmptyBatch = fishingOperations.get(1); fishingOperationWithEmptyBatch = fishingOperationService.getFishingOperation(fishingOperationWithEmptyBatch.getId()); @@ -162,7 +162,7 @@ catchBacth = new CatchBatch(); catchBacth.setFishingOperation(fishingOperationWithEmptyBatch); catchBacth = catchBatchService.createCatchBatch(catchBacth); - + sortedUnsortedPMFM = referentialService.getSortedUnsortedCaracteristic(); horsVracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(0); vracQualitativeValue = sortedUnsortedPMFM.getQualitativeValue(1); @@ -172,7 +172,7 @@ maleQualitativeValue = sexPMFM.getQualitativeValue(1); femaleQualitativeValue = sexPMFM.getQualitativeValue(2); unkQualitativeValue = sexPMFM.getQualitativeValue(3); - + List<Caracteristic> cara = referentialService.getAllCaracteristic(); for (Caracteristic caracteristic : cara) { if (caracteristic.getCaracteristicType() == CaracteristicType.NUMBER @@ -234,7 +234,7 @@ catchBatch.setCatchTotalRejectedWeight(15f); // Create and reload (test round trip) - assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); + assertCreateAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); // ----------------------------------------------------------------------------- // 2. Test save after modification @@ -245,10 +245,10 @@ catchBatch.setSpeciesTotalSampleSortedWeight(null); catchBatch.setCatchTotalUnsortedWeight(null); catchBatch.setSpeciesTotalUnsortedWeight(null); - - assertSaveAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); + + assertSaveAndReloadCatchBatch(catchBatch, fishingOperationNoCatchBatch.getId()); } - + @Test public void createAndSaveSpeciesBatchAndFrequencies() { SpeciesBatch esp1Batch = null; @@ -409,7 +409,7 @@ } } // And remove the last item (should be deleted in DB) - createdFrequencies.remove(createdFrequencies.size()-1); + createdFrequencies.remove(createdFrequencies.size() - 1); List<SpeciesBatchFrequency> savedFrequencies = service.saveSpeciesBatchFrequency(frequenciesParentBatch.getId(), frequencies); assertBatchFrequencies(createdFrequencies, savedFrequencies, true); } @@ -475,16 +475,16 @@ batch.setId(createdBatch.getId()); } - + protected void assertCreateAndReloadCatchBatch(CatchBatch catchBatch, String fishingOperationId) { CatchBatch createdCatchBatch = service.createCatchBatch(catchBatch); assertNotNull(createdCatchBatch); assertNotNull(createdCatchBatch.getId()); assertCatchBatch(catchBatch, createdCatchBatch, false); - + CatchBatch reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); assertCatchBatch(createdCatchBatch, reloadedCatchBatch, true); - + catchBatch.setId(createdCatchBatch.getId()); } @@ -493,20 +493,20 @@ assertNotNull(savedCatchBatch); assertNotNull(savedCatchBatch.getId()); assertCatchBatch(catchBatch, savedCatchBatch, false); - + CatchBatch reloadedCatchBatch = service.getCatchBatchFromFishingOperation(fishingOperationId); assertCatchBatch(savedCatchBatch, reloadedCatchBatch, true); } - - protected void assertCatchBatch(CatchBatch expectedCatchBatch,CatchBatch actualCatchBatch, boolean assertIdEquals) { - if (expectedCatchBatch == null) { - assertNull(actualCatchBatch); - return; - } - + + protected void assertCatchBatch(CatchBatch expectedCatchBatch, CatchBatch actualCatchBatch, boolean assertIdEquals) { + if (expectedCatchBatch == null) { + assertNull(actualCatchBatch); + return; + } + assertNotNull(actualCatchBatch); if (assertIdEquals) { - assertEquals(expectedCatchBatch.getId(), actualCatchBatch.getId()); + assertEquals(expectedCatchBatch.getId(), actualCatchBatch.getId()); } assertEquals(expectedCatchBatch.getCatchTotalWeight(), actualCatchBatch.getCatchTotalWeight()); assertEquals(expectedCatchBatch.getCatchTotalSortedCarousselWeight(), actualCatchBatch.getCatchTotalSortedCarousselWeight()); @@ -519,7 +519,7 @@ assertEquals(expectedCatchBatch.getSpeciesTotalInertWeight(), actualCatchBatch.getSpeciesTotalInertWeight()); assertEquals(expectedCatchBatch.getSpeciesTotalLivingNotItemizedWeight(), actualCatchBatch.getSpeciesTotalLivingNotItemizedWeight()); } - + protected void assertSpeciesBatch(SpeciesBatch expectedBatch, SpeciesBatch actualBatch, boolean assertIdEquals) { assertNotNull(actualBatch); assertNotNull(actualBatch.getId()); @@ -550,6 +550,7 @@ assertEquals(expectedBatch.getSpecies().getId(), actualBatch.getSpecies().getId()); } } + protected List<SpeciesBatchFrequency> assertCreateAndReloadSpeciesBatchFrequency(List<SpeciesBatchFrequency> frequencies, String parentBatchId) { // Create batch Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplUpTodateTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplUpTodateTest.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/synchro/ReferentialSynchronizeServiceImplUpTodateTest.java 2013-02-15 20:28:55 UTC (rev 432) @@ -38,7 +38,6 @@ import org.springframework.jdbc.support.JdbcUtils; import javax.swing.JDialog; -import java.awt.GraphicsEnvironment; import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; @@ -93,7 +92,7 @@ @After public void tearDown() throws Exception { - if (dialog!=null) { + if (dialog != null) { dialog.setVisible(false); } service = null; Modified: trunk/tutti-service/pom.xml =================================================================== --- trunk/tutti-service/pom.xml 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-service/pom.xml 2013-02-15 20:28:55 UTC (rev 432) @@ -79,6 +79,11 @@ </dependency> <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + </dependency> + + <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-02-15 20:28:55 UTC (rev 432) @@ -107,7 +107,7 @@ decoratorProvider = new DecoratorProvider() { @Override protected void loadDecorators() { - + registerTuttiDecorator(Zone.class, "${label}$s#${name}$s", SEPARATOR, " - "); registerTuttiDecorator(Cruise.class, "${name}$s", SEPARATOR, " - "); registerTuttiDecorator(TuttiProtocol.class, "${name}$s", SEPARATOR, " - "); @@ -226,6 +226,7 @@ return result; } } + public static class ProgramDecorator extends TuttiDecorator<Program> implements Cloneable { private static final long serialVersionUID = 1L; @@ -243,6 +244,7 @@ return result; } } + public static class VesselDecorator extends TuttiDecorator<Vessel> implements Cloneable { private static final long serialVersionUID = 1L; Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-02-15 20:28:55 UTC (rev 432) @@ -52,7 +52,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.util.List; @@ -324,25 +323,21 @@ } @Override - @Transactional(readOnly = false) public List<Species> importTemporarySpecies(List<Species> species) { return driver.importTemporarySpecies(species); } @Override - @Transactional(readOnly = false) public List<Vessel> importTemporaryVessel(List<Vessel> vessels) { return driver.importTemporaryVessel(vessels); } @Override - @Transactional(readOnly = false) public List<Person> importTemporaryPerson(List<Person> persons) { return driver.importTemporaryPerson(persons); } @Override - @Transactional(readOnly = false) public List<Gear> importTemporaryGear(List<Gear> gears) { return driver.importTemporaryGear(gears); } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDecorator.java 2013-02-15 20:28:55 UTC (rev 432) @@ -70,9 +70,9 @@ } protected TuttiDecorator(Class<O> internalClass, - String expression, - String separator, - String separatorReplacement) throws IllegalArgumentException, NullPointerException { + String expression, + String separator, + String separatorReplacement) throws IllegalArgumentException, NullPointerException { super(internalClass, expression, separator, Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/PersonModel.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/PersonModel.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/PersonModel.java 2013-02-15 20:28:55 UTC (rev 432) @@ -25,7 +25,6 @@ */ import fr.ifremer.tutti.persistence.entities.referential.Person; -import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.TuttiCsvUtil; /** Modified: trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties =================================================================== --- trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2013-02-15 20:28:55 UTC (rev 432) @@ -1,4 +1,4 @@ -tutti.option.basedir.description= +tutti.option.basedir.description=Répertoire principale tutti.option.csv.separator.description=Caractère séparateur pour les import / export de fichier au format csv. tutti.option.data.directory.description=Répertoire de données de l'application. Vous pouvez utiliser l'expression ${tutti.data.directory} pour le référence dans d'autres propriétés de configuration (ex\: ${tutti.data.directory}/tmp). tutti.option.inceptionYear.description=Année de démarrage du projet. Modified: trunk/tutti-ui-swing/pom.xml =================================================================== --- trunk/tutti-ui-swing/pom.xml 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/pom.xml 2013-02-15 20:28:55 UTC (rev 432) @@ -331,11 +331,6 @@ </dependency> <dependency> - <groupId>org.swinglabs.swingx</groupId> - <artifactId>swingx-action</artifactId> - </dependency> - - <dependency> <groupId>com.ezware.oxbow</groupId> <artifactId>swing-bits</artifactId> </dependency> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiAction.java 2013-02-15 20:28:55 UTC (rev 432) @@ -32,7 +32,7 @@ import fr.ifremer.tutti.ui.swing.util.action.TuttiActionUI; import fr.ifremer.tutti.ui.swing.util.action.TuttiActionUIModel; import jaxx.runtime.SwingUtil; -import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.beans.AbstractBean; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/AbstractTuttiUIHandler.java 2013-02-15 20:28:55 UTC (rev 432) @@ -34,7 +34,6 @@ import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.UIMessageNotifier; import fr.ifremer.tutti.ui.swing.util.editor.SimpleTimeEditor; -import java.awt.Color; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import jaxx.runtime.swing.editor.NumberEditor; @@ -43,7 +42,7 @@ import jaxx.runtime.swing.renderer.DecoratorListCellRenderer; import jaxx.runtime.validator.swing.SwingValidator; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.reflect.ConstructorUtils; +import org.apache.commons.lang3.reflect.ConstructorUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jdesktop.swingx.JXDatePicker; @@ -61,11 +60,13 @@ import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JRootPane; +import javax.swing.JTextField; import javax.swing.KeyStroke; import javax.swing.ListCellRenderer; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.text.JTextComponent; +import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; @@ -82,9 +83,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.swing.JTextField; -import javax.swing.UIManager; -import org.apache.commons.lang3.ArrayUtils; import static org.nuiton.i18n.I18n._; @@ -293,13 +291,13 @@ Object component = entry.getValue(); if (component instanceof NumberEditor) { initNumberEditor((NumberEditor) component); - + } else if (component instanceof JXDatePicker) { initDatePicker((JXDatePicker) component); - + } else if (component instanceof SimpleTimeEditor) { initTimeEditor((SimpleTimeEditor) component); - + } else if (component instanceof JLabel) { JLabel jLabel = (JLabel) component; Boolean strongStyle = (Boolean) jLabel.getClientProperty("strongStyle"); @@ -315,7 +313,7 @@ } jLabel.setText("<html>" + text + "</html>"); } - + } else if (component instanceof JTextField) { JTextField jTextField = (JTextField) component; Boolean computed = (Boolean) jTextField.getClientProperty("computed"); @@ -326,7 +324,7 @@ jTextField.setEnabled(!computed); jTextField.setDisabledTextColor(Color.BLUE); } - + } else if (component instanceof AbstractButton) { AbstractButton abstractButton = (AbstractButton) component; Class<? extends AbstractTuttiAction> actionName = (Class<? extends AbstractTuttiAction>) abstractButton.getClientProperty("tuttiAction"); @@ -581,11 +579,11 @@ } }); } - + protected Set<String> getPropertiesToIgnore() { return Sets.newHashSet( - AbstractTuttiBeanUIModel.PROPERTY_MODIFY, - AbstractTuttiBeanUIModel.PROPERTY_VALID); + AbstractTuttiBeanUIModel.PROPERTY_MODIFY, + AbstractTuttiBeanUIModel.PROPERTY_VALID); } public <B> void selectFirstInCombo(BeanComboBox<B> combo) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUI.java 2013-02-15 20:28:55 UTC (rev 432) @@ -24,10 +24,11 @@ * #L% */ -import java.awt.Font; -import javax.swing.UIManager; import jaxx.runtime.JAXXObject; +import javax.swing.UIManager; +import java.awt.Font; + /** * Contract to place on each generated jaxx ui. * @@ -119,7 +120,7 @@ * @since 0.1 */ public static final String DECIMAL3_PATTERN = "\\d{0,6}|\\d{1,6}\\.\\d{0,3}"; - + /** * Pattern to use for decimal numeric values with 2 digits + 3 decimal digits in * editors. @@ -129,6 +130,6 @@ public static final String DECIMAL2_3_PATTERN = "\\d{0,2}|\\d{1,2}\\.\\d{0,3}"; public static final Font TEXTFIELD_NORMAL_FONT = UIManager.getDefaults().getFont("TextField.font"); - + public static final Font TEXTFIELD_COMPUTED_FONT = UIManager.getDefaults().getFont("TextField.font").deriveFont(Font.ITALIC); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-02-15 20:28:55 UTC (rev 432) @@ -40,7 +40,6 @@ import fr.ifremer.tutti.ui.swing.content.operation.fishing.gearshooting.GearShootingTabUI; import fr.ifremer.tutti.ui.swing.content.operation.fishing.hydrology.HydrologyTabUI; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; -import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.util.decorator.Decorator; @@ -152,12 +151,12 @@ } protected EditFishingOperationAction(FishingOperationsUIHandler handler, - String name, - String icon, - String text, - String tip, - boolean hideBody) { - super(handler, name,icon,text,tip,hideBody); + String name, + String icon, + String text, + String tip, + boolean hideBody) { + super(handler, name, icon, text, tip, hideBody); } public void setFishingOperation(FishingOperation fishingOperation) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationUIModel.java 2013-02-15 20:28:55 UTC (rev 432) @@ -36,17 +36,15 @@ import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.editor.CoordinateEditorType; +import org.nuiton.util.DateUtil; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; import java.util.Calendar; import java.util.Date; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import static org.nuiton.i18n.I18n.n_; -import org.nuiton.util.DateUtil; /** * Model for UI {@link EditFishingOperationUI}. @@ -799,5 +797,5 @@ setTrawlDistance(distance.floatValue()); } } - + } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-02-15 20:28:55 UTC (rev 432) @@ -32,34 +32,36 @@ import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.util.List; -import java.util.Map; -import javax.swing.JOptionPane; -import javax.swing.JTextField; import jaxx.runtime.JAXXUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.swing.JOptionPane; +import javax.swing.JTextField; +import java.awt.Component; +import java.awt.event.ActionEvent; +import java.util.List; +import java.util.Map; + import static org.nuiton.i18n.I18n._; /** - * * @author kmorin <kmorin@codelutin.com> * @since 1.0 */ public class ComputeWeightsAction extends AbstractTuttiAction<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> { private static final long serialVersionUID = 1L; - + private static final Log log = LogFactory.getLog(ComputeWeightsAction.class); protected String errorMessage; + protected String errorTitle; + protected Component errorComponent; - + protected enum Weights { UNSORTED, SAMPLE_SORTED, SORTED, TOTAL } @@ -76,29 +78,29 @@ @Override protected void doAction(ActionEvent event) throws Exception { Map<Weights, Float> speciesWeights = computeSpeciesBatches(); - + EditCatchesUI ui = getUI(); setComputedValue(ui.getCatchTotalUnsortedWeightField(), - speciesWeights.get(Weights.UNSORTED)); + speciesWeights.get(Weights.UNSORTED)); setComputedValue(ui.getCatchTotalSortedWeightField(), - speciesWeights.get(Weights.SORTED)); - + speciesWeights.get(Weights.SORTED)); + EditCatchesUIModel model = getModel(); Float totalWeight = model.getCatchTotalWeight(); Float rejectedWeight = model.getCatchTotalRejectedWeight(); - + if (rejectedWeight == null && totalWeight != null) { if (!totalWeight.equals(speciesWeights.get(Weights.UNSORTED) - + speciesWeights.get(Weights.SORTED))) { + + speciesWeights.get(Weights.SORTED))) { errorMessage = _("tutti.action.computeWeights.error.incoherentTotal"); errorTitle = _("tutti.action.computeWeights.error.incoherentTotal.title"); errorComponent = ui.getCatchTotalWeightField(); - + } else { - - model.setCatchTotalRejectedComputedWeight(totalWeight - - speciesWeights.get(Weights.UNSORTED) - - speciesWeights.get(Weights.SORTED)); + + model.setCatchTotalRejectedComputedWeight(totalWeight + - speciesWeights.get(Weights.UNSORTED) + - speciesWeights.get(Weights.SORTED)); } } else if (totalWeight == null) { @@ -106,34 +108,34 @@ rejectedWeight = 0f; } model.setCatchTotalComputedWeight(speciesWeights.get(Weights.UNSORTED) - + speciesWeights.get(Weights.SORTED)+ rejectedWeight); - - } else if (rejectedWeight != null - && !totalWeight.equals(speciesWeights.get(Weights.UNSORTED) - + speciesWeights.get(Weights.SORTED) + rejectedWeight)) { + + speciesWeights.get(Weights.SORTED) + rejectedWeight); + + } else if (rejectedWeight != null + && !totalWeight.equals(speciesWeights.get(Weights.UNSORTED) + + speciesWeights.get(Weights.SORTED) + rejectedWeight)) { errorMessage = _("tutti.action.computeWeights.error.incoherentTotal"); errorTitle = _("tutti.action.computeWeights.error.incoherentTotal.title"); errorComponent = ui.getCatchTotalWeightField(); } - + } - + //------------------------------------------------------------------------// //-- Internal methods --// //------------------------------------------------------------------------// - + protected Map<Weights, Float> computeSpeciesBatches() { Map<Weights, Float> result = Maps.newEnumMap(Weights.class); - + PersistenceService persistenceService = getService(PersistenceService.class); EditCatchesUIModel model = getModel(); - + Float totalSortedWeight = 0f; Float totalUnsortedWeight = 0f; SpeciesBatchUI speciesUI = getUI().getSpeciesTabContent(); EditCatchesUI ui = getUI(); - + List<SpeciesBatchRowModel> roots = getUI().getSpeciesTabContent().getModel().getRows(); for (SpeciesBatchRowModel row : roots) { if (row.isBatchRoot()) { @@ -163,23 +165,23 @@ if (livingNotItemizedWeight != null) { totalSortedWeight += livingNotItemizedWeight.floatValue(); } - + setComputedValue(speciesUI.getSpeciesTotalSampleSortedWeightField(), - totalSortedWeight); + totalSortedWeight); setComputedValue(ui.getSpeciesTotalSampleSortedWeightField(), - totalSortedWeight); + totalSortedWeight); result.put(Weights.SAMPLE_SORTED, totalSortedWeight); - + Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); if (speciesTotalSortedWeight == null) { speciesTotalSortedWeight = totalSortedWeight; model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); - + } else if (speciesTotalSortedWeight < totalSortedWeight) { errorMessage = _("tutti.action.computeWeights.error.incoherentSpeciesTotalSorted"); errorTitle = _("tutti.action.computeWeights.error.incoherentSpeciesTotalSorted.title"); errorComponent = ui.getSpeciesTotalSortedWeightField(); - + } else if (speciesTotalSortedWeight < 1.05 * totalSortedWeight) { // TODO Si le "Poids total VRAC" est saisi est que sa valeur // est supérieure de moins de x% (x en configuration) @@ -188,32 +190,32 @@ // sinon la remplacer par le "Poids total Vrac trié" } result.put(Weights.SORTED, speciesTotalSortedWeight); - + setComputedValue(speciesUI.getSpeciesTotalUnsortedWeightField(), - totalUnsortedWeight); + totalUnsortedWeight); setComputedValue(ui.getSpeciesTotalUnsortedWeightField(), - totalUnsortedWeight); + totalUnsortedWeight); result.put(Weights.UNSORTED, totalUnsortedWeight); - + Float totalWeight = totalUnsortedWeight + speciesTotalSortedWeight; setComputedValue(speciesUI.getSpeciesTotalWeightField(), - totalWeight); + totalWeight); setComputedValue(ui.getSpeciesTotalWeightField(), - totalWeight); + totalWeight); result.put(Weights.TOTAL, speciesTotalSortedWeight); - + speciesUI.getTable().repaint(); - + return result; } protected Float computeSpeciesBatch(SpeciesBatchRowModel row) { SampleCategory finestCategory = row.getFinestCategory(); - + Float result = null; Float categoryWeight = finestCategory.getCategoryWeight(); Float rowWeight = row.getWeight(); - + List<SpeciesBatchRowModel> children = row.getChildBatch(); // if the row is not a leaf if (!row.isBatchLeaf()) { @@ -227,19 +229,19 @@ } sum += weight; } - + if (sum != null) { if (categoryWeight == null) { finestCategory.setComputedWeight(sum); for (SpeciesBatchRowModel child : children) { child.getFinestCategory().setSubSample(false); } - + } else if (categoryWeight < sum) { errorMessage = _("tutti.action.computeWeights.error.incoherentParentCategoryWeight"); errorTitle = _("tutti.action.computeWeights.error.incoherentParentCategoryWeight.title"); errorComponent = null; - + } else { boolean subSample = categoryWeight > sum; for (SpeciesBatchRowModel child : children) { @@ -248,12 +250,12 @@ } result = sum; } - + } else {// the row is a leaf row.setComputedWeight(null); - + List<SpeciesFrequencyRowModel> frequency = row.getFrequency(); - + if (CollectionUtils.isNotEmpty(frequency)) { // if there are frequencies, then compute their weight Float frequencyWeight = 0f; @@ -264,35 +266,35 @@ // can't sum when a null value appears frequencyWeight = null; break; - + } else if (frequencyWeight != null) { // still can sum weights frequencyWeight += w; } } - + if (categoryWeight == null && rowWeight != null) { errorMessage = _("tutti.action.computeWeights.error.incoherentRowWeightCategory"); errorTitle = _("tutti.action.computeWeights.error.incoherentRowWeightCategory.title"); errorComponent = null; - + } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, // then this weight is the result finestCategory.setComputedWeight(frequencyWeight); result = frequencyWeight; - - } else if (frequencyWeight != null - && !frequencyWeight.equals(categoryWeight)) { - + + } else if (frequencyWeight != null + && !frequencyWeight.equals(categoryWeight)) { + // if the weight of the frequencies is different from the category // weight, then set the weight of the sample if (categoryWeight != null && frequencyWeight > categoryWeight) { errorMessage = _("tutti.action.computeWeights.error.incoherentCategoryWeight"); errorTitle = _("tutti.action.computeWeights.error.incoherentCategoryWeight.title"); errorComponent = null; - + } else if (rowWeight == null) { row.setComputedWeight(frequencyWeight); @@ -302,11 +304,11 @@ errorComponent = null; } result = categoryWeight; - + } else { result = categoryWeight; } - + } else { result = categoryWeight; } @@ -314,7 +316,7 @@ return result; } - + protected void setComputedValue(JTextField textField, Float value) { String textValue; if (value != null) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-02-15 20:28:55 UTC (rev 432) @@ -37,7 +37,7 @@ fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI fr.ifremer.tutti.ui.swing.util.editor.TuttiComputedOrNotDataEditor - + org.jdesktop.swingx.JXTitledPanel jaxx.runtime.swing.CardLayout2Ext @@ -73,10 +73,10 @@ <BeanValidator id='validator' bean='model' errorTableModel='errorTableModel' uiClass='jaxx.runtime.validator.swing.ui.ImageValidationUI'> <field name='catchTotalWeight' component='catchTotalWeightField'/> -<!-- <field name='catchTotalSortedTremisWeight' - component='catchTotalSortedTremisWeightField'/> - <field name='catchTotalSortedCarousselWeight' - component='catchTotalSortedCarousselWeightField'/>--> + <!-- <field name='catchTotalSortedTremisWeight' + component='catchTotalSortedTremisWeightField'/> + <field name='catchTotalSortedCarousselWeight' + component='catchTotalSortedCarousselWeightField'/>--> <field name='catchTotalRejectedWeight' component='catchTotalRejectedWeightField'/> @@ -115,7 +115,7 @@ </cell> <cell columns='4' weightx='1.0'> <TuttiComputedOrNotDataEditor id='catchTotalWeightField' - constructorParams='this'/> + constructorParams='this'/> </cell> </row> <!-- Poids total trié balance tremie / caroussel--> @@ -126,20 +126,20 @@ <cell columns='4' weightx='1.0'> <JTextField id='catchTotalSortedWeightField'/> </cell> -<!-- <cell anchor='west'> - <JLabel id='catchTotalSortedCarousselWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='catchTotalSortedCarousselWeightField' - constructorParams='this'/> - </cell> - <cell anchor='west'> - <JLabel id='catchTotalSortedTremisWeightLabel'/> - </cell> - <cell weightx='1.0'> - <NumberEditor id='catchTotalSortedTremisWeightField' - constructorParams='this'/> - </cell>--> + <!-- <cell anchor='west'> + <JLabel id='catchTotalSortedCarousselWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='catchTotalSortedCarousselWeightField' + constructorParams='this'/> + </cell> + <cell anchor='west'> + <JLabel id='catchTotalSortedTremisWeightLabel'/> + </cell> + <cell weightx='1.0'> + <NumberEditor id='catchTotalSortedTremisWeightField' + constructorParams='this'/> + </cell>--> </row> <!--Poids total hors vrac--> <row> @@ -156,8 +156,9 @@ <JLabel id='catchTotalRejectedWeightLabel'/> </cell> <cell columns='4' weightx='1.0'> - <TuttiComputedOrNotDataEditor id='catchTotalRejectedWeightField' - constructorParams='this'/> + <TuttiComputedOrNotDataEditor + id='catchTotalRejectedWeightField' + constructorParams='this'/> </cell> </row> <row> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-02-15 20:28:55 UTC (rev 432) @@ -141,7 +141,7 @@ EditCatchesUIModel.PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, EditCatchesUIModel.PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, EditCatchesUIModel.PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT - )); + )); return result; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIModel.java 2013-02-15 20:28:55 UTC (rev 432) @@ -28,11 +28,12 @@ import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + import static org.nuiton.i18n.I18n._; /** @@ -44,7 +45,7 @@ private static final long serialVersionUID = 1L; public static final String PROPERTY_CATCH_TOTAL_WEIGHT = "catchTotalWeight"; - + public static final String PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT = "catchTotalComputedWeight"; public static final String PROPERTY_CATCH_TOTAL_SORTED_TREMIS_WEIGHT = "catchTotalSortedTremisWeight"; @@ -52,11 +53,11 @@ public static final String PROPERTY_CATCH_TOTAL_SORTED_CAROUSSEL_WEIGHT = "catchTotalSortedCarousselWeight"; public static final String PROPERTY_CATCH_TOTAL_REJECTED_WEIGHT = "catchTotalRejectedWeight"; - + public static final String PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT = "catchTotalRejectedComputedWeight"; public static final String PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT = "speciesTotalSortedWeight"; - + public static final String PROPERTY_SPECIES_TOTAL_SORTED_COMPUTED_WEIGHT = "speciesTotalSortedComputedWeight"; public static final String PROPERTY_SPECIES_TOTAL_INERT_WEIGHT = "speciesTotalInertWeight"; @@ -157,32 +158,32 @@ public EditCatchesUIModel() { super(CatchBatch.class, fromBeanBinder, toBeanBinder); speciesTotalSortedComputedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, + TuttiComputedOrNotData.PROPERTY_DATA, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, - evt.getOldValue(), evt.getNewValue()); - } - }); + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, + evt.getOldValue(), evt.getNewValue()); + } + }); catchTotalComputedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, + TuttiComputedOrNotData.PROPERTY_DATA, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_CATCH_TOTAL_WEIGHT, - evt.getOldValue(), evt.getNewValue()); - } - }); + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_CATCH_TOTAL_WEIGHT, + evt.getOldValue(), evt.getNewValue()); + } + }); catchTotalRejectedComputedOrNotWeight.addPropertyChangeListener( - TuttiComputedOrNotData.PROPERTY_DATA, + TuttiComputedOrNotData.PROPERTY_DATA, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, - evt.getOldValue(), evt.getNewValue()); - } - }); + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_CATCH_TOTAL_COMPUTED_WEIGHT, + evt.getOldValue(), evt.getNewValue()); + } + }); } @Override @@ -213,7 +214,7 @@ public TuttiComputedOrNotData<Float> getCatchTotalComputedOrNotWeight() { return catchTotalComputedOrNotWeight; } - + public Float getCatchTotalWeight() { return catchTotalComputedOrNotWeight.getData(); } @@ -223,7 +224,7 @@ this.catchTotalComputedOrNotWeight.setData(catchTotalWeight); firePropertyChange(PROPERTY_CATCH_TOTAL_WEIGHT, oldValue, catchTotalWeight); } - + public Float getCatchTotalComputedWeight() { return catchTotalComputedOrNotWeight.getComputedData(); } @@ -257,7 +258,7 @@ public TuttiComputedOrNotData<Float> getCatchTotalRejectedComputedOrNotWeight() { return catchTotalRejectedComputedOrNotWeight; } - + public Float getCatchTotalRejectedWeight() { return catchTotalRejectedComputedOrNotWeight.getData(); } @@ -277,11 +278,11 @@ this.catchTotalRejectedComputedOrNotWeight.setComputedData(catchTotalRejectedComputedWeight); firePropertyChange(PROPERTY_CATCH_TOTAL_REJECTED_COMPUTED_WEIGHT, oldValue, catchTotalRejectedComputedWeight); } - + public TuttiComputedOrNotData<Float> getSpeciesTotalSortedComputedOrNotWeight() { return speciesTotalSortedComputedOrNotWeight; } - + public Float getSpeciesTotalSortedWeight() { return speciesTotalSortedComputedOrNotWeight.getData(); } @@ -291,7 +292,7 @@ this.speciesTotalSortedComputedOrNotWeight.setData(speciesTotalSortedWeight); firePropertyChange(PROPERTY_SPECIES_TOTAL_SORTED_WEIGHT, oldValue, speciesTotalSortedWeight); } - + public Float getSpeciesTotalSortedComputedWeight() { return speciesTotalSortedComputedOrNotWeight.getComputedData(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategory.java 2013-02-15 20:28:55 UTC (rev 432) @@ -65,19 +65,19 @@ * @since 1.0 */ protected Float computedWeight; - + /** * Is this sample a subsample ? * Available only if the category is the finest category of the row - * + * * @since 1.0 */ protected boolean subSample; - + /** * Has the row only one frequency ? * Available only if the category is the finest category of the row - * + * * @since 1.0 */ protected boolean onlyOneFrequency; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SampleCategoryComponent.java 2013-02-15 20:28:55 UTC (rev 432) @@ -209,7 +209,7 @@ boolean hasFocus, int row, int column) { - + SampleCategory<C> sampleCategory = (SampleCategory<C>) value; String text = null; @@ -222,7 +222,7 @@ Float computedNumber = sampleCategory.getComputedWeight(); text = "<html>" + categoryDecorator.toString(categoryValue) + " /"; - + if (sampleCategory.isSubSample()) { text += "/"; } @@ -230,14 +230,14 @@ if (number != null) { text += String.format("%.3f", number); - + } else if (computedNumber != null) { if (sampleCategory.hasOnlyOneFrequency()) { text += String.format("%.3f", computedNumber); - + } else { String blue = Integer.toHexString(Color.BLUE.getRGB()).substring(2); - text += "<em style='color: #" + blue + "'>" + + text += "<em style='color: #" + blue + "'>" + String.format("%.3f", computedNumber) + "</em>"; } } else { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchRowModel.java 2013-02-15 20:28:55 UTC (rev 432) @@ -34,15 +34,14 @@ import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.frequency.SpeciesFrequencyRowModel; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import org.apache.commons.collections.CollectionUtils; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.util.Collections; import java.util.List; -import org.apache.commons.logging.LogFactory; /** * Represents a species batch (i.e a row in the batch table). @@ -99,7 +98,7 @@ public static final String PROPERTY_FREQUENCY = "frequency"; public static final String PROPERTY_COMPUTED_NUMBER = "computedOrNotNumber"; - + public static final String PROPERTY_COMPUTED_WEIGHT = "computedOrNotWeight"; public static final String PROPERTY_ATTACHMENTS = "attachments"; @@ -242,40 +241,40 @@ sexCategory = SampleCategory.newSample(SampleCategoryType.sex); maturityCategory = SampleCategory.newSample(SampleCategoryType.maturity); ageCategory = SampleCategory.newSample(SampleCategoryType.age); - + computedOrNotWeight.addPropertyChangeListener( TuttiComputedOrNotData.PROPERTY_DATA, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_WEIGHT, evt.getOldValue(), evt.getNewValue()); - } - }); + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_WEIGHT, evt.getOldValue(), evt.getNewValue()); + } + }); computedOrNotWeight.addPropertyChangeListener( TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_COMPUTED_WEIGHT, evt.getOldValue(), evt.getNewValue()); - } - }); - + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_COMPUTED_WEIGHT, evt.getOldValue(), evt.getNewValue()); + } + }); + computedOrNotNumber.addPropertyChangeListener( TuttiComputedOrNotData.PROPERTY_DATA, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_NUMBER, evt.getOldValue(), evt.getNewValue()); - } - }); + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_NUMBER, evt.getOldValue(), evt.getNewValue()); + } + }); computedOrNotNumber.addPropertyChangeListener( TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - firePropertyChange(PROPERTY_COMPUTED_NUMBER, evt.getOldValue(), evt.getNewValue()); - } - }); + public void propertyChange(PropertyChangeEvent evt) { + firePropertyChange(PROPERTY_COMPUTED_NUMBER, evt.getOldValue(), evt.getNewValue()); + } + }); } public SpeciesBatchRowModel(SpeciesBatch aBatch, @@ -343,7 +342,7 @@ } return finestCategory; } - + //------------------------------------------------------------------------// //-- Species category --// //------------------------------------------------------------------------// @@ -620,7 +619,7 @@ public void setComputedNumber(Integer computedNumber) { computedOrNotNumber.setComputedData(computedNumber); } - + public Float getComputedWeight() { return computedOrNotWeight.getComputedData(); } @@ -644,5 +643,5 @@ public void setComputedOrNotWeight(TuttiComputedOrNotData<Float> computedOrNotWeight) { this.computedOrNotWeight = computedOrNotWeight; } - + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchTableModel.java 2013-02-15 20:28:55 UTC (rev 432) @@ -33,7 +33,6 @@ import javax.swing.table.TableColumnModel; import java.util.Set; -import org.apache.commons.logging.LogFactory; import static org.nuiton.i18n.I18n.n_; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUI.jaxx 2013-02-15 20:28:55 UTC (rev 432) @@ -99,7 +99,7 @@ </cell> <cell weightx='1.0'> <TuttiComputedOrNotDataEditor id='speciesTotalSortedWeightField' - constructorParams='this'/> + constructorParams='this'/> </cell> </row> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-02-15 20:28:55 UTC (rev 432) @@ -420,7 +420,7 @@ } List<Species> speciesList = persistenceService.getAllSpecies(protocol); - + SPECIES_UNIVERSE_CONTEXT_ENTRY.setContextValue(ui, speciesList); FREQUENCY_LENGTH_CONTEXT_ENTRY.setContextValue(ui, lengthCaracterics); } @@ -585,11 +585,11 @@ { // Weight column addColumnToModel(columnModel, - TuttiComputedOrNotDataTableCell.newEditor( - Float.class, false, true, 3), - TuttiComputedOrNotDataTableCell.newRender( - defaultRenderer, true, 3), - SpeciesBatchTableModel.WEIGHT); + TuttiComputedOrNotDataTableCell.newEditor( + Float.class, false, true, 3), + TuttiComputedOrNotDataTableCell.newRender( + defaultRenderer, true, 3), + SpeciesBatchTableModel.WEIGHT); } { // Number column (from frequencies) @@ -864,7 +864,7 @@ SpeciesBatch catchBean = row.toBean(); catchBean.setFishingOperation(fishingOperation); - + SpeciesBatchRowModel parent = row.getParentBatch(); if (parent != null) { catchBean.setParentBatch(parent.toBean()); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIModel.java 2013-02-15 20:28:55 UTC (rev 432) @@ -149,7 +149,7 @@ public void setSpeciesTotalSortedWeight(Float speciesTotalSortedWeight) { catchesUIModel.setSpeciesTotalSortedWeight(speciesTotalSortedWeight); } - + public Float getSpeciesTotalSortedComputedWeight() { return catchesUIModel.getSpeciesTotalSortedComputedWeight(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-02-15 20:28:55 UTC (rev 432) @@ -26,7 +26,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import fr.ifremer.tutti.ui.swing.TuttiUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; @@ -47,7 +46,6 @@ import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; -import java.awt.Font; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -74,7 +72,7 @@ setHorizontalAlignment(CENTER); setIcon(SwingUtil.createActionIcon("show-frequency")); } - + public void setComputedOrNotText(TuttiComputedOrNotData<Integer> data) { String text; @@ -82,8 +80,8 @@ text = String.valueOf(data.getData()); } else if (data != null - && data.getComputedData() != null - && data.getComputedData() != 0) { + && data.getComputedData() != null + && data.getComputedData() != 0) { String blue = Integer.toHexString(Color.BLUE.getRGB()).substring(2); text = "<html><em style='color: #" + blue + "'>" + data.getComputedData() + "</em></html>"; @@ -172,7 +170,7 @@ // at close, synch back frequencies List<SpeciesFrequencyRowModel> frequency = Lists.newArrayList(); - + if (frequencyModel.isSimpleCountingMode()) { editRow.setNumber(frequencyModel.getSimpleCount()); @@ -226,7 +224,7 @@ } TuttiComputedOrNotData<Integer> data = (TuttiComputedOrNotData<Integer>) value; component.setComputedOrNotText(data); - + rowIndex = row; columnIndex = column; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/SpeciesFrequencyUIHandler.java 2013-02-15 20:28:55 UTC (rev 432) @@ -79,7 +79,7 @@ private Map<Integer, SpeciesProtocol> speciesProtocol; private Map<String, Caracteristic> lengthStepCaracteristics; - + protected Set<SpeciesFrequencyRowModel> withWeightRows = Sets.newHashSet(); public SpeciesFrequencyUIHandler(TuttiUIContext context, @@ -120,13 +120,13 @@ Object newValue) { boolean recomputeAllRows; - + if (row.getWeight() != null) { // check if no row had a weight, then if one of them now has a weight, // the other ones must have one too to be valid recomputeAllRows = withWeightRows.isEmpty(); withWeightRows.add(row); - + } else { withWeightRows.remove(row); // check if no row has a weight, then if none of them now has a weight, @@ -201,7 +201,7 @@ } } - + initBeanComboBox(ui.getLengthStepCaracteristicComboBox(), lengthStepCaracterics, model.getLengthStepCaracteristic()); @@ -278,7 +278,7 @@ initTable(table); installTableKeyListener(columnModel, table); - + listenValidatorValid(ui.getValidator(), model); } @@ -394,9 +394,9 @@ public void editBatch(SpeciesBatchRowModel speciesBatch, FrequencyCellEditor editor) { withWeightRows.clear(); - + frequencyEditor = editor; - + Caracteristic lengthStepCaracteristic = null; Float lengthStep = 1f; @@ -421,7 +421,7 @@ newRow.setNumber(rowModel.getNumber()); newRow.setWeight(rowModel.getWeight()); editFrequency.add(newRow); - + if (newRow.getWeight() != null) { withWeightRows.add(newRow); } @@ -440,7 +440,7 @@ lengthStep); } } - + if (lengthStepCaracteristic == null && protocol != null) { Species species = speciesBatch.getSpecies(); @@ -493,7 +493,7 @@ model.setRows(editFrequency); model.setLengthStepCaracteristic(lengthStepCaracteristic); - + // keep batch (will be used to push back editing entry) model.setBatch(speciesBatch); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiComputedOrNotData.java 2013-02-15 20:28:55 UTC (rev 432) @@ -27,25 +27,22 @@ * #L% */ -/** - * - * @author kmorin <kmorin@codelutin.com> - */ +/** @author kmorin <kmorin@codelutin.com> */ public class TuttiComputedOrNotData<N extends Number> extends AbstractBean { public static final String PROPERTY_DATA = "data"; - + public static final String PROPERTY_COMPUTED_DATA = "computedData"; - + protected N data; - + protected N computedData; - + public TuttiComputedOrNotData() { data = null; computedData = null; } - + public TuttiComputedOrNotData(N data, N computedData) { this.data = data; this.computedData = computedData; @@ -70,7 +67,7 @@ this.computedData = computedData; firePropertyChange(PROPERTY_COMPUTED_DATA, oldValue, computedData); } - + @Override public String toString() { String result = null; @@ -81,5 +78,5 @@ } return result; } - + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/TuttiUIUtil.java 2013-02-15 20:28:55 UTC (rev 432) @@ -325,21 +325,21 @@ } return duration; } - - public static int computeDistanceInMeters(Float startLatitude, + + public static int computeDistanceInMeters(Float startLatitude, Float startLongitude, - Float endLatitude, + Float endLatitude, Float endLongitude) { - + double sLat = startLatitude * Math.PI / 180; double sLong = startLongitude * Math.PI / 180; double eLat = endLatitude * Math.PI / 180; double eLong = endLongitude * Math.PI / 180; - + Double d = 6378288 * - (Math.PI/2 - Math.asin( Math.sin(eLat) * Math.sin(sLat) - + Math.cos(eLong - sLong) * Math.cos(eLat) * Math.cos(sLat))); + (Math.PI / 2 - Math.asin(Math.sin(eLat) * Math.sin(sLat) + + Math.cos(eLong - sLong) * Math.cos(eLat) * Math.cos(sLat))); return d.intValue(); - + } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/action/TuttiActionUI.jaxx 2013-02-15 20:28:55 UTC (rev 432) @@ -21,7 +21,8 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<JDialog layout='{new BorderLayout()}' width='300' height='200' modal='true' undecorated='true' +<JDialog layout='{new BorderLayout()}' width='300' height='200' modal='true' + undecorated='true' implements='fr.ifremer.tutti.ui.swing.TuttiUI<TuttiActionUIModel, TuttiActionUIHandler>'> <import> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2013-02-15 20:28:55 UTC (rev 432) @@ -31,6 +31,22 @@ import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.ComponentMover; +import jaxx.runtime.swing.ComponentResizer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.decorator.Decorator; + +import javax.swing.AbstractCellEditor; +import javax.swing.BorderFactory; +import javax.swing.JDialog; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; import java.awt.Frame; @@ -41,21 +57,6 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Collection; -import javax.swing.AbstractCellEditor; -import javax.swing.BorderFactory; -import javax.swing.JDialog; -import javax.swing.JTable; -import javax.swing.border.LineBorder; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import jaxx.runtime.JAXXUtil; -import jaxx.runtime.SwingUtil; -import jaxx.runtime.swing.ComponentMover; -import jaxx.runtime.swing.ComponentResizer; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.decorator.Decorator; import static org.nuiton.i18n.I18n._; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditor.jaxx 2013-02-15 20:28:55 UTC (rev 432) @@ -1,23 +1,23 @@ <jaxx.runtime.swing.editor.NumberEditor> - + <import> fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData </import> - + <String id='property' javaBean='TuttiComputedOrNotData.PROPERTY_DATA'/> - + <TuttiComputedOrNotData id='bean' genericType='?' javaBean='null'/> - + <!-- ui handler --> <TuttiComputedOrNotDataEditorHandler id='handler' constructorParams='this'/> - + <Integer id='decimalNumber' javaBean='null'/> - + <script><![CDATA[ public void setProperty(String property) { // cannot change the property } ]]> </script> - + </jaxx.runtime.swing.editor.NumberEditor> \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataEditorHandler.java 2013-02-15 20:28:55 UTC (rev 432) @@ -3,36 +3,32 @@ import fr.ifremer.tutti.ui.swing.TuttiUI; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.swing.editor.NumberEditorHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JTextField; import java.awt.Color; -import java.awt.Font; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.regex.Matcher; -import javax.swing.JTextField; -import javax.swing.UIManager; -import jaxx.runtime.JAXXUtil; -import jaxx.runtime.swing.editor.NumberEditorHandler; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** - * * @author kmorin <kmorin@codelutin.com> * @since 1.0 */ public class TuttiComputedOrNotDataEditorHandler extends NumberEditorHandler { private static final Log log = LogFactory.getLog(TuttiComputedOrNotDataEditorHandler.class); - + protected Integer decimalNumber; - + public TuttiComputedOrNotDataEditorHandler(TuttiComputedOrNotDataEditor ui) { super(ui); } - + @Override public void init() { final PropertyChangeListener l = new PropertyChangeListener() { @@ -41,7 +37,7 @@ setComputedTextIfNullModel(); } }; - + TuttiComputedOrNotData bean = (TuttiComputedOrNotData) editor.getBean(); if (bean != null) { bean.addPropertyChangeListener(TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, l); @@ -49,19 +45,19 @@ editor.addPropertyChangeListener(TuttiComputedOrNotDataEditor.PROPERTY_BEAN, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { - + TuttiComputedOrNotData bean = (TuttiComputedOrNotData) evt.getOldValue(); if (bean != null) { bean.removePropertyChangeListener(TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, l); } - + bean = (TuttiComputedOrNotData) evt.getNewValue(); if (bean != null) { bean.addPropertyChangeListener(TuttiComputedOrNotData.PROPERTY_COMPUTED_DATA, l); } } }); - + editor.getTextField().addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { @@ -77,31 +73,31 @@ setComputedTextIfNullModel(); } }); - + editor.addPropertyChangeListener(TuttiComputedOrNotDataEditor.PROPERTY_DECIMAL_NUMBER, - new PropertyChangeListener() { + new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - decimalNumber = (Integer) evt.getNewValue(); - } - }); + public void propertyChange(PropertyChangeEvent evt) { + decimalNumber = (Integer) evt.getNewValue(); + } + }); decimalNumber = ((TuttiComputedOrNotDataEditor) editor).getDecimalNumber(); - + super.init(); - + } - + protected void setComputedTextIfNullModel() { TuttiComputedOrNotData bean = (TuttiComputedOrNotData) editor.getBean(); if (bean != null && editor.getModel() == null) { JTextField tf = editor.getTextField(); tf.setFont(TuttiUI.TEXTFIELD_COMPUTED_FONT); tf.setForeground(Color.BLUE); - + String modelText; Number computedData = bean.getComputedData(); - if (editor.isUseFloat() - && decimalNumber != null && computedData != null) { + if (editor.isUseFloat() + && decimalNumber != null && computedData != null) { modelText = String.format("%." + decimalNumber + "f", computedData); } else { modelText = JAXXUtil.getStringValue(computedData); @@ -109,5 +105,5 @@ tf.setText(modelText); } } - + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java 2013-02-15 20:01:16 UTC (rev 431) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/TuttiComputedOrNotDataTableCell.java 2013-02-15 20:28:55 UTC (rev 432) @@ -2,11 +2,8 @@ import fr.ifremer.tutti.ui.swing.TuttiUI; import fr.ifremer.tutti.ui.swing.util.TuttiComputedOrNotData; -import java.awt.Color; -import java.awt.Component; -import java.awt.Font; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; +import jaxx.runtime.JAXXUtil; + import javax.swing.AbstractCellEditor; import javax.swing.JTable; import javax.swing.SwingConstants; @@ -17,7 +14,11 @@ import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; -import jaxx.runtime.JAXXUtil; +import java.awt.Color; +import java.awt.Component; +import java.awt.Font; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; /** * Editor for TuttiComputedOrNotData @@ -30,8 +31,8 @@ public static TableCellRenderer newRender(TableCellRenderer renderer, boolean useFloat, Integer decimalNumber) { - - return new TuttiComputedOrNotDataTableCellRenderer(renderer, + + return new TuttiComputedOrNotDataTableCellRenderer(renderer, useFloat, decimalNumber); } @@ -40,9 +41,9 @@ boolean useSign, boolean useFloat, Integer decimalNumber) { - - return new TuttiComputedOrNotDataTableCellEditor(type, useSign, - useFloat, decimalNumber); + + return new TuttiComputedOrNotDataTableCellEditor(type, useSign, + useFloat, decimalNumber); } public static class TuttiComputedOrNotDataTableCellEditor @@ -50,17 +51,17 @@ implements TableCellEditor, FocusListener, AncestorListener { private static final long serialVersionUID = 1L; + protected final TuttiComputedOrNotDataEditor numberEditor; + protected TuttiComputedOrNotData data; - /** - * constructor - */ - public TuttiComputedOrNotDataTableCellEditor(Class type, + /** constructor */ + public TuttiComputedOrNotDataTableCellEditor(Class type, boolean useSign, boolean useFloat, Integer decimalNumber) { - + numberEditor = new TuttiComputedOrNotDataEditor(); numberEditor.getTextField().setHorizontalAlignment(SwingConstants.RIGHT); numberEditor.getTextField().addFocusListener(this); @@ -78,7 +79,7 @@ @Override public Component getTableCellEditorComponent(JTable table, Object value, - boolean isSelected, int row, int column) { + boolean isSelected, int row, int column) { data = (TuttiComputedOrNotData) value; numberEditor.setModel(data.getData()); @@ -145,33 +146,33 @@ return result; } } - + public static class TuttiComputedOrNotDataTableCellRenderer<E> - implements TableCellRenderer { + implements TableCellRenderer { protected final TableCellRenderer delegate; - + protected Integer decimalNumber; - + protected boolean useFloat; public TuttiComputedOrNotDataTableCellRenderer( TableCellRenderer delegate, boolean useFloat, Integer decimalNumber) { - + this.delegate = delegate; this.useFloat = useFloat; this.decimalNumber = decimalNumber; } - - public Component getTableCellRendererComponent(JTable table, - Object value, - boolean isSelected, - boolean hasFocus, - int row, - int column) { - + + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + TuttiComputedOrNotData data = (TuttiComputedOrNotData) value; Number dataValue = data.getData(); Font font; @@ -180,7 +181,7 @@ dataValue = data.getComputedData(); font = TuttiUI.TEXTFIELD_COMPUTED_FONT; foreground = Color.BLUE; - + } else { font = TuttiUI.TEXTFIELD_NORMAL_FONT; foreground = Color.BLACK; @@ -192,18 +193,18 @@ } else { text = JAXXUtil.getStringValue(dataValue); } - + Component component = delegate.getTableCellRendererComponent(table, - text, - isSelected, - hasFocus, - row, - column); + text, + isSelected, + hasFocus, + row, + column); component.setFont(font); component.setForeground(foreground); - + return component; } - + } }
participants (1)
-
tchemit@users.forge.codelutin.com