r739 - in trunk: . tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tutti/service/catches tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data tutti-service/src/main/resources/i18n tutti-ui-swing/src/main/filtered-resources tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing tutti-ui-swing/src/m
Author: kmorin Date: 2013-04-05 15:36:16 +0200 (Fri, 05 Apr 2013) New Revision: 739 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/739 Log: fixes #2230 [PROTOCOLE] - erreur ?\195?\160 l'import d'un .csv refs #2232 [CAPTURE] - Import/Export PUPITRI : ne pas demander le fichier pupitri ?\195?\160 ce stade fixes #2237 [CAPTURE] Ne pas prendre en compte les poids de tr?\195?\169mie et carrousel pour l'?\195?\169l?\195?\169vation refs #1868 [CAPTURE] - Import/Export PUPITRI refs #2079: [CONTROLE] - Contr?\195?\180le / Validation apr?\195?\168s la saisie Added: trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-error-validation.xml Modified: trunk/pom.xml trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/Program-error-validation.xml trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.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.css 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/ImportPupitriAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.css trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategory.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/CreateBenthosMelagAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/CreateSpeciesMelagAction.java 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/split/SplitSpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolBenthosAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/pom.xml 2013-04-05 13:36:16 UTC (rev 739) @@ -270,11 +270,6 @@ </dependency> <!-- swing widgets --> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-widgets</artifactId> - <version>1.1.1</version> - </dependency> <dependency> <groupId>org.swinglabs.swingx</groupId> Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-04-05 13:36:16 UTC (rev 739) @@ -128,6 +128,10 @@ return Multimaps.index(list, GET_TAXON_ID); } + public static Multimap<String, Species> splitByRefTaxCode(Iterable<Species> list) { + return Multimaps.index(list, GET_REF_TAX_CODE); + } + public static final Function<Species, String> GET_TAXON_ID = new Function<Species, String>() { @Override public String apply(Species input) { @@ -135,6 +139,13 @@ } }; + public static final Function<Species, String> GET_REF_TAX_CODE = new Function<Species, String>() { + @Override + public String apply(Species input) { + return String.valueOf(input.getRefTaxCode()); + } + }; + public static final Function<TuttiEntity, String> GET_ID = new Function<TuttiEntity, String>() { @Override public String apply(TuttiEntity input) { 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-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/DecoratorService.java 2013-04-05 13:36:16 UTC (rev 739) @@ -60,6 +60,8 @@ public static final String BY_NAME = "byName"; + public static final String ONLY_NAME = "onlyName"; + public static final String SEPARATOR = "#"; /** Delegate decorator provider. */ @@ -112,6 +114,7 @@ }); registerDecorator(new VesselDecorator()); registerDecorator(new ProgramDecorator()); + registerTuttiDecorator(Program.class, ONLY_NAME, "${name}$s", SEPARATOR, " - "); registerDecorator(new SpeciesDecorator()); registerDecorator(FROM_PROTOCOL, new SpeciesFromProtocolDecorator()); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/ValidationService.java 2013-04-05 13:36:16 UTC (rev 739) @@ -27,6 +27,7 @@ import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.Program; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import org.nuiton.validator.NuitonValidator; import org.nuiton.validator.NuitonValidatorFactory; @@ -63,4 +64,10 @@ NuitonValidatorResult result = validator.validate(fishingOperation); return result; } + + public NuitonValidatorResult validateSpeciesBatch(SpeciesBatch speciesBatch) { + NuitonValidator<SpeciesBatch> validator = NuitonValidatorFactory.newValidator(SpeciesBatch.class); + NuitonValidatorResult result = validator.validate(speciesBatch); + return result; + } } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java 2013-04-05 13:36:16 UTC (rev 739) @@ -1,44 +1,18 @@ package fr.ifremer.tutti.service.catches; -/* - * #%L - * Tutti :: Service - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - import fr.ifremer.tutti.TuttiBusinessException; -import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.SortedUnsortedEnum; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; +import fr.ifremer.tutti.persistence.entities.data.*; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; +import fr.ifremer.tutti.service.ValidationService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.validator.NuitonValidatorResult; +import javax.swing.*; import java.util.List; import static org.nuiton.i18n.I18n._; @@ -54,15 +28,18 @@ protected PersistenceService persistenceService; + protected ValidationService validationService; + @Override public void setServiceContext(TuttiServiceContext context) { super.setServiceContext(context); persistenceService = getService(PersistenceService.class); + validationService = getService(ValidationService.class); } public void computeCatchBatchWeights(CatchBatch catchBatch, - BatchContainer<SpeciesBatch> rootSpeciesBatch, - BatchContainer<SpeciesBatch> rootBenthosBatch) { + BatchContainer<SpeciesBatch> rootSpeciesBatch, + BatchContainer<SpeciesBatch> rootBenthosBatch) { // Species Float speciesTotalComputedSortedWeight = 0f; @@ -173,15 +150,11 @@ catchBatch.setBenthosTotalComputedWeight(benthosTotalWeight); // Catch - Float carrouselWeight = catchBatch.getCatchTotalSortedCarousselWeight(); Float totalUnsortedWeight = catchBatch.getSpeciesTotalUnsortedComputedWeight() + catchBatch.getBenthosTotalUnsortedComputedWeight(); - Float totalSortedWeight; - if (carrouselWeight != null) { - totalSortedWeight = carrouselWeight; - } else { - totalSortedWeight = speciesTotalSortedWeight + benthosTotalSortedWeight; - } + + Float totalSortedWeight = speciesTotalSortedWeight + benthosTotalSortedWeight; + catchBatch.setCatchTotalSortedComputedWeight(totalSortedWeight); catchBatch.setCatchTotalUnsortedComputedWeight(totalUnsortedWeight); @@ -193,10 +166,11 @@ + totalSortedWeight)) { throw new TuttiBusinessException(_("tutti.service.catches.computeWeights.error.incoherentTotal")); + } else { + catchBatch.setCatchTotalRejectedComputedWeight(totalWeight + - totalUnsortedWeight + - totalSortedWeight); } - catchBatch.setCatchTotalRejectedComputedWeight(totalWeight - - totalUnsortedWeight - - totalSortedWeight); } else if (totalWeight == null) { if (rejectedWeight == null) { @@ -204,8 +178,8 @@ catchBatch.setCatchTotalRejectedComputedWeight(0f); } catchBatch.setCatchTotalComputedWeight(totalUnsortedWeight - + totalSortedWeight - + rejectedWeight); + + totalSortedWeight + + rejectedWeight); } else if (!totalWeight.equals(totalUnsortedWeight + totalSortedWeight + rejectedWeight)) { throw new TuttiBusinessException(_("tutti.service.catches.computeWeights.error.incoherentTotal")); @@ -220,7 +194,8 @@ if (rootSpeciesBatch != null) { List<SpeciesBatch> roots = rootSpeciesBatch.getChildren(); - for (SpeciesBatch batch : roots) { + for (int i = 0; i < roots.size(); i++) { + SpeciesBatch batch = roots.get(i); computeSpeciesBatch(batch); } } @@ -235,7 +210,8 @@ List<SpeciesBatch> roots = rootBenthosBatch.getChildren(); - for (SpeciesBatch batch : roots) { + for (int i = 0; i < roots.size(); i++) { + SpeciesBatch batch = roots.get(i); computeSpeciesBatch(batch); } @@ -247,6 +223,12 @@ Float categoryWeight = batch.getSampleCategoryWeight(); Float rowWeight = batch.getWeight(); + NuitonValidatorResult validation = validationService.validateSpeciesBatch(batch); + if (!validation.isValid()) { + List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); + throw new TuttiBusinessException(_(messages.get(0))); + } + List<SpeciesBatch> children = batch.getChildBatchs(); // if the row is not a leaf if (batch.sizeChildBatchs() > 0) { @@ -262,23 +244,6 @@ } if (sum != null) { -// if (categoryWeight == null) { -// finestCategory.setComputedWeight(sum); -// for (SpeciesBatchRowModel child : children) { -// child.getFinestCategory().setSubSample(false); -// } -// -// } else if (categoryWeight < sum) { -// throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentParentCategoryWeight")); -// -// } else { -// boolean subSample = categoryWeight > sum; -// for (SpeciesBatchRowModel child : children) { -// child.getFinestCategory().setSubSample(subSample); -// } -// sum = categoryWeight; -// } -// result = sum; if (categoryWeight == null) { batch.setSampleCategoryComputedWeight(sum); @@ -316,7 +281,7 @@ } if (categoryWeight == null && rowWeight != null) { - throw new TuttiBusinessException(_("tutti.service.catches.computeWeights.error.incoherentRowWeightCategory")); +// throw new TuttiBusinessException(_("tutti.service.catches.computeWeights.error.incoherentRowWeightCategory")); } else if (categoryWeight == null && frequencyWeight != null) { // if the category weight is null and the frequencies have a weight, @@ -325,7 +290,7 @@ result = frequencyWeight; } else if (frequencyWeight != null - && !frequencyWeight.equals(categoryWeight)) { + && !frequencyWeight.equals(categoryWeight)) { // if the weight of the frequencies is different from the category // weight, then set the weight of the sample Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-04-05 13:36:16 UTC (rev 739) @@ -27,13 +27,11 @@ import com.google.common.base.Charsets; import com.google.common.base.Function; import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Multimap; -import com.google.common.collect.Multimaps; +import com.google.common.collect.*; import com.google.common.io.Files; import fr.ifremer.tutti.TuttiTechnicalException; import fr.ifremer.tutti.persistence.entities.TuttiBeanFactory; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; @@ -49,6 +47,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.TuttiDataContext; import fr.ifremer.tutti.service.TuttiServiceContext; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; @@ -62,10 +61,7 @@ import java.io.File; import java.io.IOException; import java.io.Reader; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author kmorin <kmorin@codelutin.com> @@ -78,6 +74,8 @@ protected PersistenceService persistenceService; + protected TuttiDataContext dataContext; + protected CaracteristicQualitativeValue sortedCaracteristic; protected CaracteristicQualitativeValue unsortedCaracteristic; @@ -96,6 +94,7 @@ public void setServiceContext(TuttiServiceContext context) { super.setServiceContext(context); persistenceService = getService(PersistenceService.class); + dataContext = context.getDataContext(); // get the sorted/unsorted caracteristics Caracteristic sortedUnsortedcaracteristic = @@ -113,22 +112,29 @@ bigCaracteristic = SizeEnum.BIG.getValue(sizeCaracteristic); } - public void importPupitri(File trunkFile, + /** + * + * @param trunkFile + * @param carrouselFile + * @param operation + * @param catchBatch + * @return the number of rows of the .car file which have not been imported + */ + public int importPupitri(File trunkFile, File carrouselFile, - File speciesFile, FishingOperation operation, - CatchBatch catchBatch, - List<Species> referentSpecies) { + CatchBatch catchBatch) { importPupitriTrunk(trunkFile, operation, catchBatch); - importPupitriCarrousel(carrouselFile, speciesFile, operation, catchBatch, referentSpecies); + int result = importPupitriCarrousel(carrouselFile, operation, catchBatch); addFileAsAttachment(trunkFile, catchBatch); addFileAsAttachment(carrouselFile, catchBatch); - addFileAsAttachment(speciesFile, catchBatch); persistenceService.saveCatchBatch(catchBatch); + + return result; } protected void addFileAsAttachment(File f, CatchBatch catchBatch) { @@ -213,66 +219,43 @@ } - protected void importPupitriCarrousel(File carrouselFile, - File speciesFile, + protected int importPupitriCarrousel(File carrouselFile, FishingOperation operation, - CatchBatch catchBatch, - List<Species> referentSpecies) { + CatchBatch catchBatch) { if (log.isInfoEnabled()) { log.info("Will import pupitri operation [" + operation.toString() + "] carrousel from file: " + carrouselFile); } + int result = 0; Reader reader = null; File fileWithHeaders = null; - Import<SpeciesRow> speciesImporter = null; Import<CarrouselRow> carrouselImporter = null; - - char speciesSeparator = ';'; - SpeciesRowModel speciesCsvModel = new SpeciesRowModel(speciesSeparator); char carrouselSeparator = ','; CarrouselRowModel carrouselCsvModel = new CarrouselRowModel(carrouselSeparator); try { - // import the species - String[] header = new String[]{ - SpeciesRow.PROPERTY_CODE_FIRST_PART, - SpeciesRow.PROPERTY_CODE_SECOND_PART, - SpeciesRow.PROPERTY_SCIENTIFIC_NAME - }; - fileWithHeaders = createFileWithHeaders(speciesFile, header, speciesSeparator); - reader = Files.newReader(fileWithHeaders, Charsets.UTF_8); - speciesImporter = Import.newImport(speciesCsvModel, reader); - // get the map of species by survey code - Multimap<String, Species> speciesBySurveyCode = - Multimaps.index(referentSpecies, new Function<Species, String>() { - @Override - public String apply(Species input) { - String surveyCode = String.valueOf(input.getSurveyCode()); - int end = Math.min(surveyCode.length(), 7); - return surveyCode.substring(0, end); - } - }); - // keep only the species whose survey code and name are the same - // in theimported file and the referent species - Map<String, Species> speciesMap = Maps.newHashMap(); - for (SpeciesRow bean : speciesImporter) { - String code = bean.getCodeFirstPart() + bean.getCodeSecondPart(); - Collection<Species> speciesCollection = speciesBySurveyCode.get(code.trim()); - for (Species species : speciesCollection) { - if (species.getName().equals(bean.getScientificName())) { - speciesMap.put(code, species); - break; - } - } - } + ListMultimap<String, Species> speciesBySurveyCode = ArrayListMultimap.create(); + speciesBySurveyCode.putAll( + Multimaps.index(dataContext.getReferentSpeciesWithSurveyCode(), + new Function<Species, String>() { + @Override + public String apply(Species input) { + String surveyCode = String.valueOf(input.getSurveyCode()); + int end = Math.min(surveyCode.length(), 7); + return surveyCode.substring(0, end); + } + }) + ); + speciesBySurveyCode.putAll(TuttiEntities.splitByRefTaxCode(dataContext.getReferentSpecies())); + // import the batches - header = new String[]{ + String[] header = new String[]{ CarrouselRow.PROPERTY_FILE_ORIGIN, CarrouselRow.PROPERTY_DATE, CarrouselRow.PROPERTY_TIME, @@ -296,13 +279,15 @@ Float carrouselSortedWeight = 0f; List<PupitriCatch> catches = Lists.newArrayList(); + Set<String> notFoundSpecies = Sets.newHashSet(); + for (CarrouselRow bean : carrouselImporter) { // is the bean from the current operation and rig ? if (bean.getOperationCode().equals(operationNumber) && bean.getRigNumber().equals(rigNumber)) { String speciesId = bean.getSpeciesId(); - Species species = speciesMap.get(speciesId); + List<Species> speciesList = speciesBySurveyCode.get(speciesId); Float beanWeight = bean.getWeight(); if (beanWeight < 0f) { beanWeight = 0f; @@ -318,8 +303,9 @@ carrouselSortedWeight += beanWeight; } - if (species != null) { + if (!CollectionUtils.isEmpty(speciesList)) { + Species species = speciesList.get(0); PupitriCatch pupitriCatch = new PupitriCatch(species, sorted); int catchIndex = catches.indexOf(pupitriCatch); if (catchIndex >= 0) { @@ -328,9 +314,13 @@ catches.add(pupitriCatch); } pupitriCatch.addToSign(bean.getSign(), beanWeight); + + } else { + notFoundSpecies.add(speciesId); } } } + result = notFoundSpecies.size(); catchBatch.setCatchTotalSortedCarousselWeight(carrouselSortedWeight); BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId()); @@ -398,7 +388,6 @@ } carrouselImporter.close(); - speciesImporter.close(); reader.close(); } catch (Exception e) { @@ -406,10 +395,11 @@ } finally { IOUtils.closeQuietly(carrouselImporter); - IOUtils.closeQuietly(speciesImporter); IOUtils.closeQuietly(reader); FileUtils.deleteQuietly(fileWithHeaders); } + + return result; } public void exportSpecies(List<Species> species, File target) { Modified: trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/Program-error-validation.xml =================================================================== --- trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/Program-error-validation.xml 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/Program-error-validation.xml 2013-04-05 13:36:16 UTC (rev 739) @@ -36,7 +36,7 @@ <field-validator type="collectionUniqueKey" short-circuit="true"> <param name="collectionFieldName">existingPrograms</param> - <param name="keys">name, zone</param> + <param name="keys">name</param> <param name="againstMe">true</param> <param name="nullValueSkipped">true</param> <message>tutti.validator.error.program.existingKey</message> Added: trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-error-validation.xml =================================================================== --- trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-error-validation.xml (rev 0) +++ trunk/tutti-service/src/main/resources/fr/ifremer/tutti/persistence/entities/data/SpeciesBatch-error-validation.xml 2013-04-05 13:36:16 UTC (rev 739) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE validators PUBLIC + "-//Apache Struts//XWork Validator 1.0.3//EN" + "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> +<validators> + + <field name="weight"> + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ !(sampleCategoryWeight == null && weight != null) ]]> + </param> + <message>tutti.service.catches.computeWeights.error.incoherentRowWeightCategory</message> + </field-validator> + + <field-validator type="fieldexpression" short-circuit="true"> + <param name="expression"> + <![CDATA[ weight == null || sampleCategoryWeight == null || weight <= sampleCategoryWeight ]]> + </param> + <message>tutti.service.catches.computeWeights.error.incoherentSampleWeight</message> + </field-validator> + </field> + +</validators> \ No newline at end of file Modified: trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties =================================================================== --- trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties 2013-04-05 13:36:16 UTC (rev 739) @@ -52,6 +52,7 @@ tutti.service.catches.computeWeights.error.incoherentParentCategoryWeight= tutti.service.catches.computeWeights.error.incoherentRowWeightCategory= tutti.service.catches.computeWeights.error.incoherentRowWeightFrequency= +tutti.service.catches.computeWeights.error.incoherentSampleWeight= tutti.service.catches.computeWeights.error.incoherentSpeciesTotalSorted= tutti.service.catches.computeWeights.error.incoherentTotal= tutti.validator.error.comment.too.long= @@ -97,5 +98,6 @@ tutti.validator.error.program.zone.required= tutti.validator.error.protocol.name.alreadyUsed= tutti.validator.error.protocol.name.required= +tutti.validator.error.speciesBatch.species.required= tutti.validator.warning.latitude.outOfBounds= tutti.validator.warning.longitude.outOfBounds= 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-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2013-04-05 13:36:16 UTC (rev 739) @@ -7,7 +7,6 @@ tutti.config.option.tmp.directory.description=Répertoire temporaire utilisée par l'application (est nettoyé à chaque démarrage de l'application). tutti.config.option.version.description=Version courante de l'application tutti.config.service=Configuration des services de Tutti -tutti.editCatchBatch.action.computeWeights.error.incoherentParentCategoryWeight= tutti.property.attachment=Pièce jointe tutti.property.caracteristic=Caractéristique tutti.property.country=Pays @@ -49,6 +48,7 @@ tutti.service.catches.computeWeights.error.incoherentParentCategoryWeight=Le poids de la catégorie est différent de la somme des poids de ses sous-catégories tutti.service.catches.computeWeights.error.incoherentRowWeightCategory=Le poids de la catégorie ne peut pas être nul si le poids de sous-échantillonage est renseigné tutti.service.catches.computeWeights.error.incoherentRowWeightFrequency=Le poids total des mensurations est différent du poids du sous-échantillon +tutti.service.catches.computeWeights.error.incoherentSampleWeight=Le poids de sous-échantillonage est supérieur au poids de la catégorie tutti.service.catches.computeWeights.error.incoherentSpeciesTotalSorted=Le poids total Vrac des espèces est inférieur à la somme des poids Vrac triés, inerte trié et vivant non détaillé trié tutti.service.catches.computeWeights.error.incoherentTotal=Le poids total de la capture ne correspond pas à la somme des poids totaux Vrac, Hors Vrac et non triés tutti.validator.error.comment.too.long=Taille de commentaire trop longue (limitée à %s caractères) @@ -89,10 +89,11 @@ tutti.validator.error.longitude.start.required=La longitude de début de traîne est obligatoire tutti.validator.error.program.description.required=La description de la série est obligatoire tutti.validator.error.program.description.too.long=Taille de la description trop longue (limitée à %s caractères) -tutti.validator.error.program.existingKey=Le couple nom/zone existe déjà +tutti.validator.error.program.existingKey=Le nom du programme est déjà utilisé tutti.validator.error.program.name.required=Le nom de la série est obligatoire tutti.validator.error.program.zone.required=La zone de la série est obligatoire tutti.validator.error.protocol.name.alreadyUsed=Le nom du protocol est déjà utilisé tutti.validator.error.protocol.name.required=Le nom du protocol est obligatoire +tutti.validator.error.speciesBatch.species.required= tutti.validator.warning.latitude.outOfBounds=La Latitude doit être comprise entre -90.0 et 90.0 tutti.validator.warning.longitude.outOfBounds=La longitude doit être comprise entre -180.0 et 180.0 Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-en.properties 2013-04-05 13:36:16 UTC (rev 739) @@ -22,7 +22,7 @@ # #L% ### #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Thu Apr 04 20:09:11 CEST 2013 +#Fri Mar 29 10:09:57 CET 2013 tutti.createBenthosBatch.action.addSpecies.help=createBenthosBatch.html\#actions tutti.createBenthosBatch.action.cancel.help=createBenthosBatch.html\#actions tutti.createBenthosBatch.action.save.help=createBenthosBatch.html\#actions Modified: trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties =================================================================== --- trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/filtered-resources/tutti-help-fr.properties 2013-04-05 13:36:16 UTC (rev 739) @@ -22,7 +22,7 @@ # #L% ### #Generated by org.nuiton.jaxx.plugin.GenerateHelpIdsMojo -#Thu Apr 04 20:09:11 CEST 2013 +#Fri Mar 29 10:09:57 CET 2013 tutti.createBenthosBatch.action.addSpecies.help=createBenthosBatch.html\#actions tutti.createBenthosBatch.action.cancel.help=createBenthosBatch.html\#actions tutti.createBenthosBatch.action.save.help=createBenthosBatch.html\#actions Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java 2013-04-05 13:36:16 UTC (rev 739) @@ -35,6 +35,7 @@ import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiDataContext; import fr.ifremer.tutti.service.TuttiServiceContext; +import fr.ifremer.tutti.service.catches.TuttiWeightComputingService; import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService; import fr.ifremer.tutti.service.pupitri.TuttiPupitriImportExportService; import fr.ifremer.tutti.service.referential.TuttiReferentialImportExportService; @@ -517,6 +518,10 @@ return serviceContext.getService(TuttiReferentialImportExportService.class); } + public TuttiWeightComputingService getTuttiWeightComputingService() { + return serviceContext.getService(TuttiWeightComputingService.class); + } + public boolean useRealPersistenceService() { return isDbExist() && isDbLoaded(); } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/cruise/EditCruiseUIHandler.java 2013-04-05 13:36:16 UTC (rev 739) @@ -33,6 +33,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Vessel; +import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.util.CloseableUI; @@ -181,7 +182,8 @@ initBeanFilterableComboBox(ui.getProgramComboBox(), persistenceService.getAllProgram(), - model.getProgram()); + model.getProgram(), + DecoratorService.ONLY_NAME); initBeanFilterableComboBox(ui.getDepartureLocationComboBox(), persistenceService.getAllHarbour(), 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-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ComputeWeightsAction.java 2013-04-05 13:36:16 UTC (rev 739) @@ -25,8 +25,13 @@ * #L% */ +import com.google.common.collect.Lists; import fr.ifremer.tutti.TuttiBusinessException; +import fr.ifremer.tutti.persistence.entities.data.BatchContainer; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.SortedUnsortedEnum; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.service.catches.TuttiWeightComputingService; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.BenthosBatchRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.benthos.frequency.BenthosFrequencyRowModel; import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchRowModel; @@ -53,121 +58,23 @@ @Override protected void doAction() throws Exception { - EditCatchesUIModel model = getModel(); + TuttiWeightComputingService tuttiWeightComputingService = getContext().getTuttiWeightComputingService(); - computeSpeciesBatches(); - computeBenthosBatches(); - - Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = model.getSpeciesTotalSortedComputedWeight(); - } - - Float benthosTotalSortedWeight = model.getBenthosTotalSortedWeight(); - if (benthosTotalSortedWeight == null) { - benthosTotalSortedWeight = model.getBenthosTotalSortedComputedWeight(); - } - - Float carrouselWeight = model.getCatchTotalSortedCarousselWeight(); - Float totalUnsortedWeight = model.getSpeciesTotalUnsortedComputedWeight() + - model.getBenthosTotalUnsortedComputedWeight(); - Float totalSortedWeight; - if (carrouselWeight != null) { - totalSortedWeight = carrouselWeight; - } else { - totalSortedWeight = speciesTotalSortedWeight + benthosTotalSortedWeight; - } - model.setCatchTotalSortedComputedWeight(totalSortedWeight); - model.setCatchTotalUnsortedComputedWeight(totalUnsortedWeight); - - Float totalWeight = model.getCatchTotalWeight(); - Float rejectedWeight = model.getCatchTotalRejectedWeight(); - - if (rejectedWeight == null && totalWeight != null) { - if (!totalWeight.equals(totalUnsortedWeight - + totalSortedWeight)) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentTotal")); - - } else { - model.setCatchTotalRejectedComputedWeight(totalWeight - - totalUnsortedWeight - - totalSortedWeight); - } - - } else if (totalWeight == null) { - if (rejectedWeight == null) { - rejectedWeight = 0f; - model.setCatchTotalRejectedComputedWeight(0f); - } - model.setCatchTotalComputedWeight(totalUnsortedWeight - + totalSortedWeight - + rejectedWeight); - - } else if (!totalWeight.equals(totalUnsortedWeight + totalSortedWeight + rejectedWeight)) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentTotal")); - } - } - - @Override - public void postSuccessAction() { - super.postSuccessAction(); - - getUI().repaint(); - } - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - - protected void computeSpeciesBatches() { EditCatchesUIModel model = getModel(); - Float totalSortedWeight = 0f; - Float totalUnsortedWeight = 0f; + BatchContainer<SpeciesBatch> computedSpeciesBatches = + tuttiWeightComputingService.getComputedSpeciesBatches(model.getFishingOperation()); + Float totalSpeciesSortedWeight = computeSpeciesBatches(computedSpeciesBatches); - List<SpeciesBatchRowModel> roots = getUI().getSpeciesTabContent().getModel().getRows(); - for (int i = 0; i < roots.size(); i++) { - SpeciesBatchRowModel row = roots.get(i); - if (row.isBatchRoot()) { - Float weight = computeSpeciesBatch(row); - if (weight == null) { - AbstractSelectTableAction.doSelectCell(getUI().getSpeciesTabContent().getTable(), i, 1); - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.noWeight")); - } - if (SortedUnsortedEnum.SORTED.matchValue(row.getSortedUnsortedCategory().getCategoryValue())) { - totalSortedWeight += weight; - } else { - totalUnsortedWeight += weight; - } - } - } + BatchContainer<SpeciesBatch> computedBenthosBatches = + tuttiWeightComputingService.getComputedBenthosBatches(model.getFishingOperation()); + Float totalBenthosSortedWeight = computeBenthosBatches(computedBenthosBatches); - Number inertWeight = model.getSpeciesTotalInertWeight(); - if (inertWeight != null) { - totalSortedWeight += inertWeight.floatValue(); - } else { - model.setSpeciesTotalInertComputedWeight(0f); - } - - Number livingNotItemizedWeight = model.getSpeciesTotalLivingNotItemizedWeight(); - if (livingNotItemizedWeight != null) { - totalSortedWeight += livingNotItemizedWeight.floatValue(); - } else { - model.setSpeciesTotalLivingNotItemizedComputedWeight(0f); - } - - model.setSpeciesTotalSampleSortedComputedWeight(totalSortedWeight); - - Float speciesTotalSortedWeight = model.getSpeciesTotalSortedWeight(); Float rate = getConfig().getDifferenceRateBetweenSortedAndTotalWeights(); - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = totalSortedWeight; - model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); + if (model.getSpeciesTotalSortedWeight() != null + && model.getSpeciesTotalSortedWeight() >= totalSpeciesSortedWeight + && model.getSpeciesTotalSortedWeight() < (1 + rate / 100) * totalSpeciesSortedWeight) { - } else if (speciesTotalSortedWeight < totalSortedWeight) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentSpeciesTotalSorted")); - - } else if (speciesTotalSortedWeight < (1 + rate / 100) * totalSortedWeight) { // Si le "Poids total VRAC" est saisi est que sa valeur // est supérieure de moins de x% (x en configuration) // du "Poids total Vrac trié", demander confirmation que @@ -179,175 +86,20 @@ _("tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.help")); int answer = JOptionPane.showConfirmDialog(getContext().getActionUI(), - htmlMessage, - _("tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.title"), - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); + htmlMessage, + _("tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.title"), + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.NO_OPTION) { model.setSpeciesTotalSortedWeight(null); - speciesTotalSortedWeight = totalSortedWeight; - model.setSpeciesTotalSortedComputedWeight(totalSortedWeight); + model.setSpeciesTotalSortedComputedWeight(totalSpeciesSortedWeight); } } + if (model.getBenthosTotalSortedWeight() != null + && model.getBenthosTotalSortedWeight() >= totalBenthosSortedWeight + && model.getBenthosTotalSortedWeight() < (1 + rate / 100) * totalSpeciesSortedWeight) { - model.setSpeciesTotalUnsortedComputedWeight(totalUnsortedWeight); - - Float totalWeight = totalUnsortedWeight + speciesTotalSortedWeight; - model.setSpeciesTotalComputedWeight(totalWeight); - } - - 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()) { - Float sum = 0f; - // make the sum of the children weights - for (SpeciesBatchRowModel child : children) { - Float weight = computeSpeciesBatch(child); - if (weight == null) { - sum = null; - break; - } - sum += weight; - } - - if (sum != null) { - if (categoryWeight == null) { - finestCategory.setComputedWeight(sum); - for (SpeciesBatchRowModel child : children) { - child.getFinestCategory().setSubSample(false); - } - - } else if (categoryWeight < sum) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentParentCategoryWeight")); - - } else { - boolean subSample = categoryWeight > sum; - for (SpeciesBatchRowModel child : children) { - child.getFinestCategory().setSubSample(subSample); - } - sum = categoryWeight; - } - 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; - for (SpeciesFrequencyRowModel frequencyModel : frequency) { - Float w = frequencyModel.getWeight(); - if (w == null) { - - // 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) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentRowWeightCategory")); - - } 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)) { - - // if the weight of the frequencies is different from the category - // weight, then set the weight of the sample - if (frequencyWeight > categoryWeight) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentCategoryWeight")); - - } else if (rowWeight == null) { - row.setComputedWeight(frequencyWeight); - - } else if (!rowWeight.equals(frequencyWeight)) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentRowWeightFrequency")); - } - result = categoryWeight; - - } else { - result = categoryWeight; - } - - } else { - result = categoryWeight; - } - } - - return result; - } - - protected void computeBenthosBatches() { - - EditCatchesUIModel model = getModel(); - - Float totalSortedWeight = 0f; - Float totalUnsortedWeight = 0f; - - List<BenthosBatchRowModel> roots = getUI().getBenthosTabContent().getModel().getRows(); - for (int i = 0; i < roots.size(); i++) { - BenthosBatchRowModel row = roots.get(i); - if (row.isBatchRoot()) { - Float weight = computeBenthosBatch(row); - if (weight == null) { - AbstractSelectTableAction.doSelectCell(getUI().getBenthosTabContent().getTable(), i, 1); - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.noWeight")); - } - if (SortedUnsortedEnum.SORTED.matchValue(row.getSortedUnsortedCategory().getCategoryValue())) { - totalSortedWeight += weight; - } else { - totalUnsortedWeight += weight; - } - } - } - - Number inertWeight = model.getBenthosTotalInertWeight(); - if (inertWeight != null) { - totalSortedWeight += inertWeight.floatValue(); - } else { - model.setBenthosTotalInertComputedWeight(0f); - } - - Number livingNotItemizedWeight = model.getBenthosTotalLivingNotItemizedWeight(); - if (livingNotItemizedWeight != null) { - totalSortedWeight += livingNotItemizedWeight.floatValue(); - } else { - model.setBenthosTotalLivingNotItemizedComputedWeight(0f); - } - - model.setBenthosTotalSampleSortedComputedWeight(totalSortedWeight); - - Float benthosTotalSortedWeight = model.getBenthosTotalSortedWeight(); - Float rate = getConfig().getDifferenceRateBetweenSortedAndTotalWeights(); - if (benthosTotalSortedWeight == null) { - benthosTotalSortedWeight = totalSortedWeight; - model.setBenthosTotalSortedComputedWeight(totalSortedWeight); - - } else if (benthosTotalSortedWeight < totalSortedWeight) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentSpeciesTotalSorted")); - - } else if (benthosTotalSortedWeight < (1 + rate / 100) * totalSortedWeight) { // Si le "Poids total VRAC" est saisi est que sa valeur // est supérieure de moins de x% (x en configuration) // du "Poids total Vrac trié", demander confirmation que @@ -359,122 +111,95 @@ _("tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.help")); int answer = JOptionPane.showConfirmDialog(getContext().getActionUI(), - htmlMessage, - _("tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.title"), - JOptionPane.YES_NO_OPTION, - JOptionPane.QUESTION_MESSAGE); + htmlMessage, + _("tutti.editCatchBatch.action.computeWeights.replaceTotalSortedWeight.title"), + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); if (answer == JOptionPane.NO_OPTION) { - model.setSpeciesTotalSortedWeight(null); - benthosTotalSortedWeight = totalSortedWeight; - model.setBenthosTotalSortedComputedWeight(totalSortedWeight); + model.setBenthosTotalSortedWeight(null); + model.setBenthosTotalSortedComputedWeight(totalBenthosSortedWeight); } } - model.setBenthosTotalUnsortedComputedWeight(totalUnsortedWeight); + boolean modified = model.isModify(); + CatchBatch catchBatch = model.toBean(); + tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, + computedSpeciesBatches, + computedBenthosBatches); + model.setCatchBatch(catchBatch); + model.fromBean(catchBatch); + model.setModify(modified); + } - Float totalWeight = totalUnsortedWeight + benthosTotalSortedWeight; - model.setBenthosTotalComputedWeight(totalWeight); + @Override + public void postSuccessAction() { + super.postSuccessAction(); + + getUI().repaint(); } - protected Float computeBenthosBatch(BenthosBatchRowModel row) { - SampleCategory finestCategory = row.getFinestCategory(); + //------------------------------------------------------------------------// + //-- Internal methods --// + //------------------------------------------------------------------------// - Float result = null; - Float categoryWeight = finestCategory.getCategoryWeight(); - Float rowWeight = row.getWeight(); + protected Float computeSpeciesBatches(BatchContainer<SpeciesBatch> computedSpeciesBatches) { + Float totalSortedWeight = 0f; - List<BenthosBatchRowModel> children = row.getChildBatch(); - // if the row is not a leaf - if (!row.isBatchLeaf()) { - Float sum = 0f; - // make the sum of the children weights - for (BenthosBatchRowModel child : children) { - Float weight = computeBenthosBatch(child); - if (weight == null) { - sum = null; - break; - } - sum += weight; + List<SpeciesBatchRowModel> rows = Lists.newArrayList(); + List<SpeciesBatch> children = computedSpeciesBatches.getChildren(); + int rowIndex = 0; + for (SpeciesBatch batch : children) { + SpeciesBatchRowModel row = getUI().getSpeciesTabContent().getHandler().loadBatch(batch, null, rows); + Float weight = row.getSortedUnsortedCategoryWeight(); + if (weight == null) { + weight = row.getSortedUnsortedCategoryComputedWeight(); } + if (weight == null) { + AbstractSelectTableAction.doSelectCell(getUI().getSpeciesTabContent().getTable(), rowIndex, 1); + throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.noWeight")); - if (sum != null) { - if (categoryWeight == null) { - finestCategory.setComputedWeight(sum); - for (BenthosBatchRowModel child : children) { - child.getFinestCategory().setSubSample(false); - } - - } else if (categoryWeight < sum) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentParentCategoryWeight")); - - } else { - boolean subSample = categoryWeight > sum; - for (BenthosBatchRowModel child : children) { - child.getFinestCategory().setSubSample(subSample); - } - sum = categoryWeight; - } - result = sum; + } else if (SortedUnsortedEnum.SORTED.matchValue( + row.getSortedUnsortedCategoryValue())) { + totalSortedWeight += weight; } + rowIndex++; + if (row.getChildBatch() != null) { + rowIndex += row.getChildBatch().size(); + } + } + getUI().getSpeciesTabContent().getModel().setRows(rows); - } else {// the row is a leaf - row.setComputedWeight(null); + return totalSortedWeight; + } - List<BenthosFrequencyRowModel> frequency = row.getFrequency(); + protected Float computeBenthosBatches(BatchContainer<SpeciesBatch> computedBenthosBatches) { + Float totalSortedWeight = 0f; - if (CollectionUtils.isNotEmpty(frequency)) { - // if there are frequencies, then compute their weight - Float frequencyWeight = 0f; - for (BenthosFrequencyRowModel frequencyModel : frequency) { - Float w = frequencyModel.getWeight(); - if (w == null) { + List<BenthosBatchRowModel> rows = Lists.newArrayList(); + List<SpeciesBatch> children = computedBenthosBatches.getChildren(); + int rowIndex = 0; + for (SpeciesBatch batch : children) { + BenthosBatchRowModel row = getUI().getBenthosTabContent().getHandler().loadBatch(batch, null, rows); + Float weight = row.getSortedUnsortedCategoryWeight(); + if (weight == null) { + weight = row.getSortedUnsortedCategoryComputedWeight(); + } + if (weight == null) { + AbstractSelectTableAction.doSelectCell(getUI().getBenthosTabContent().getTable(), rowIndex, 1); + throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.noWeight")); - // 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) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentRowWeightCategory")); - - } 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)) { - - // if the weight of the frequencies is different from the category - // weight, then set the weight of the sample - if (frequencyWeight > categoryWeight) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentCategoryWeight")); - - } else if (rowWeight == null) { - row.setComputedWeight(frequencyWeight); - - } else if (!rowWeight.equals(frequencyWeight)) { - throw new TuttiBusinessException(_("tutti.editCatchBatch.action.computeWeights.error.incoherentRowWeightFrequency")); - } - result = categoryWeight; - - } else { - result = categoryWeight; - } - - } else { - result = categoryWeight; + } else if (SortedUnsortedEnum.SORTED.matchValue( + row.getSortedUnsortedCategoryValue())) { + totalSortedWeight += weight; } + rowIndex++; + if (row.getChildBatch() != null) { + rowIndex += row.getChildBatch().size(); + } } + getUI().getBenthosTabContent().getModel().setRows(rows); - return result; + return totalSortedWeight; } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.css 2013-04-05 13:36:16 UTC (rev 739) @@ -105,6 +105,10 @@ _computed: true; } +#tremieCarrouselRow { + visible: {model.getFishingOperation().getVessel() != null && model.getFishingOperation().getVessel().getId().equals(handler.getConfig().getTremieCarousselVesselId())}; +} + #catchTotalSortedTremisWeightLabel { text: "tutti.editCatchBatch.field.catchTotalSortedTremisWeight"; toolTipText: {"tutti.editCatchBatch.field.catchTotalSortedTremisWeight.tip"}; 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-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUI.jaxx 2013-04-05 13:36:16 UTC (rev 739) @@ -100,9 +100,6 @@ <CardLayout2Ext id='marineLitterTabPanelLayout' constructorParams='this, "marineLitterTabPanel"'/> - <CardLayout2Ext id='catchTotalSortedWeightPanelLayout' - constructorParams='this, "catchTotalSortedWeightPanel"'/> - <TuttiHelpBroker id='broker' constructorParams='"tutti.editCatchBatch.help"'/> <JToolBar id='catchesCaracteristicsTabToolBar'> @@ -138,33 +135,32 @@ <JLabel id='catchTotalSortedWeightLabel'/> </cell> <cell columns='4' weightx='1.0'> - <JPanel id='catchTotalSortedWeightPanel'> - <JTextField id='catchTotalSortedWeightField' - constraints='EditCatchesUIHandler.CLASSIC_VESSEL'/> - <Table - constraints='EditCatchesUIHandler.CAROUSSEL_TREMIE_VESSEL' - fill='both'> - <row> - <cell anchor='west'> - <JLabel - id='catchTotalSortedCarousselWeightLabel'/> - </cell> - <cell weightx='1.0'> - <JTextField - id='catchTotalSortedCarousselWeightField'/> - </cell> - <cell anchor='west'> - <JLabel id='catchTotalSortedTremisWeightLabel'/> - </cell> - <cell weightx='1.0'> - <JTextField - id='catchTotalSortedTremisWeightField'/> - </cell> - </row> - </Table> - </JPanel> + <JTextField id='catchTotalSortedWeightField'/> </cell> </row> + <row> + <cell columns='5'> + <Table fill='both' id='tremieCarrouselRow'> + <row> + <cell anchor='west'> + <JLabel + id='catchTotalSortedCarousselWeightLabel'/> + </cell> + <cell weightx='1.0'> + <JTextField + id='catchTotalSortedCarousselWeightField'/> + </cell> + <cell anchor='west'> + <JLabel id='catchTotalSortedTremisWeightLabel'/> + </cell> + <cell weightx='1.0'> + <JTextField + id='catchTotalSortedTremisWeightField'/> + </cell> + </row> + </Table> + </cell> + </row> <!--Poids total hors vrac--> <row> <cell> 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-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/EditCatchesUIHandler.java 2013-04-05 13:36:16 UTC (rev 739) @@ -123,14 +123,6 @@ setCustomTab(2, ui.getBenthosTabContent().getModel()); setCustomTab(3, ui.getMarineLitterTabContent().getModel()); - getParentUi().getFishingOperationTabContent().getModel() - .addPropertyChangeListener(EditFishingOperationUIModel.PROPERTY_VESSEL, new PropertyChangeListener() { - - public void propertyChange(PropertyChangeEvent evt) { - Vessel vessel = (Vessel) evt.getNewValue(); - selectCatchTotalSortedWeightPanel(vessel); - } - }); } @Override @@ -407,15 +399,4 @@ } } - public void selectCatchTotalSortedWeightPanel(Vessel vessel) { - String card; - String carousselTremieVesselId = getConfig().getTremieCarousselVesselId(); - if (vessel != null && vessel.getId().equals(carousselTremieVesselId)) { - card = CAROUSSEL_TREMIE_VESSEL; - } else { - card = CLASSIC_VESSEL; - } - ui.getCatchTotalSortedWeightPanelLayout().setSelected(card); - } - } \ No newline at end of file Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriAction.java 2013-04-05 13:36:16 UTC (rev 739) @@ -54,8 +54,6 @@ protected File importedCarrouselFile; - protected File importedSpeciesFile; - protected ImportPupitriPopupUI importPupitriDialog; protected TuttiProtocol currentProtocol; @@ -80,25 +78,11 @@ @Override protected boolean prepareAction() throws Exception { - boolean result; + boolean result = true; + currentProtocol = getDataContext().getProtocol(); - if (!getContext().isProtocolFilled()) { - result = false; - - } else { - currentProtocol = getDataContext().getProtocol(); - result = currentProtocol != null && !currentProtocol.getSpecies().isEmpty(); - } - - if (!result) { - JOptionPane.showMessageDialog(getContext().getActionUI(), - _("tutti.editCatchBatch.action.importPupitri.noProtocol.message"), - _("tutti.editCatchBatch.action.importPupitri.noProtocol.title"), - JOptionPane.ERROR_MESSAGE); - } - SpeciesBatchUIModel speciesBatchUIModel = getUI().getSpeciesTabContent().getModel(); - if (result && speciesBatchUIModel.getRowCount() > 0) { + if (speciesBatchUIModel.getRowCount() > 0) { String htmlMessage = String.format( AbstractTuttiUIHandler.CONFIRMATION_FORMAT, _("tutti.editCatchBatch.action.importPupitri.existingData.message"), @@ -117,10 +101,8 @@ importPupitriDialog.open(); importedTrunkFile = importPupitriDialog.getTrunkFile().getSelectedFile(); importedCarrouselFile = importPupitriDialog.getCarrouselFile().getSelectedFile(); - importedSpeciesFile = importPupitriDialog.getSpeciesFile().getSelectedFile(); result = importedTrunkFile != null - && importedCarrouselFile != null - && importedSpeciesFile != null; + && importedCarrouselFile != null; } return result; @@ -136,27 +118,21 @@ FishingOperation operation = model.getFishingOperation(); CatchBatch catchBatch = model.getCatchBatch(); - // import trunk - pupitriImportExportService.importPupitri(importedTrunkFile, - importedCarrouselFile, - importedSpeciesFile, - operation, - catchBatch, - getDataContext().getReferentSpeciesWithSurveyCode()); + // import + int rejectedSpeciesNb = + pupitriImportExportService.importPupitri(importedTrunkFile, + importedCarrouselFile, + operation, + catchBatch); String fishingOperationText = getEditAction().getFishingOperationTitle(operation); getEditAction().loadCatchBatch(operation, fishingOperationText, true); + sendMessage(_("tutti.editCatchBatch.action.importPupitri.success", getUI().getSpeciesTabContent().getModel().getRootNumber(), rejectedSpeciesNb)); } @Override - public void postSuccessAction() { - super.postSuccessAction(); - sendMessage("TODO"); - } - - @Override protected void releaseAction() { super.releaseAction(); importedTrunkFile = null; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.css =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.css 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.css 2013-04-05 13:36:16 UTC (rev 739) @@ -51,18 +51,6 @@ acceptAllFileFilterUsed: false; } -#speciesFileLabel { - text: "tutti.importPupitri.field.speciesFile"; - labelFor: {carrouselFile}; -} - -#speciesFile { - directoryEnabled: false; - exts: {_("tutti.importPupitri.speciesFile.extension")}; - extsDescription: {_("tutti.importPupitri.speciesFile.extension.description")}; - acceptAllFileFilterUsed: false; -} - #cancelButton { actionIcon: cancel; text: "tutti.common.cancel"; Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUI.jaxx 2013-04-05 13:36:16 UTC (rev 739) @@ -81,15 +81,6 @@ </row> <row> - <cell> - <JLabel id='speciesFileLabel'/> - </cell> - <cell weightx='1'> - <FileEditor id='speciesFile'/> - </cell> - </row> - - <row> <cell columns='2'> <JPanel layout='{new GridLayout(1,0)}'> <JButton id='cancelButton' onActionPerformed='handler.cancel()'/> Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/ImportPupitriPopupUIHandler.java 2013-04-05 13:36:16 UTC (rev 739) @@ -67,7 +67,6 @@ protected void resetFields() { ui.getTrunkFile().setSelectedFile((String) null); ui.getCarrouselFile().setSelectedFile((String) null); - ui.getSpeciesFile().setSelectedFile((String) null); } public void open() { @@ -83,8 +82,7 @@ public void validate() { if (ui.getTrunkFile().getSelectedFile() != null - && ui.getCarrouselFile().getSelectedFile() != null - && ui.getSpeciesFile().getSelectedFile() != null) { + && ui.getCarrouselFile().getSelectedFile() != null) { ui.dispose(); } else { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategory.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategory.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/SampleCategory.java 2013-04-05 13:36:16 UTC (rev 739) @@ -154,6 +154,14 @@ return isEmpty() || isValid(); } + public Float getNotNullWeight() { + Float result = categoryWeight; + if (result == null) { + result = computedWeight; + } + return result; + } + @Override public String toString() { return new ReflectionToStringBuilder(this). Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchRowModel.java 2013-04-05 13:36:16 UTC (rev 739) @@ -68,7 +68,7 @@ public static final String PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT = "sortedUnsortedCategoryWeight"; - public static final String PROPERTY_SORTED_UNSORTED_COMPUTED_WEIGHT = "sortedUnsortedComputedWeight"; + public static final String PROPERTY_SORTED_UNSORTED_CATEGORY_COMPUTED_WEIGHT = "sortedUnsortedComputedWeight"; public static final String PROPERTY_SIZE_CATEGORY = "sizeCategory"; @@ -76,22 +76,30 @@ public static final String PROPERTY_SIZE_CATEGORY_WEIGHT = "sizeCategoryWeight"; + public static final String PROPERTY_SIZE_CATEGORY_COMPUTED_WEIGHT = "sexCategoryComputedWeight"; + public static final String PROPERTY_SEX_CATEGORY = "sexCategory"; public static final String PROPERTY_SEX_CATEGORY_VALUE = "sexCategoryValue"; public static final String PROPERTY_SEX_CATEGORY_WEIGHT = "sexCategoryWeight"; + public static final String PROPERTY_SEX_CATEGORY_COMPUTED_WEIGHT = "sexCategoryComputedWeight"; + public static final String PROPERTY_MATURITY_CATEGORY = "maturityCategory"; public static final String PROPERTY_MATURITY_CATEGORY_VALUE = "maturityCategoryValue"; + public static final String PROPERTY_MATURITY_CATEGORY_COMPUTED_WEIGHT = "maturityCategoryComputedWeight"; + public static final String PROPERTY_MATURITY_CATEGORY_WEIGHT = "maturityCategoryWeight"; public static final String PROPERTY_AGE_CATEGORY = "ageCategory"; public static final String PROPERTY_AGE_CATEGORY_VALUE = "ageCategoryValue"; + public static final String PROPERTY_AGE_CATEGORY_COMPUTED_WEIGHT = "ageCategoryComputedWeight"; + public static final String PROPERTY_AGE_CATEGORY_WEIGHT = "ageCategoryWeight"; public static final String PROPERTY_WEIGHT = "weight"; @@ -349,10 +357,12 @@ Object oldCategory = getSortedUnsortedCategory(); Object oldValue = getSortedUnsortedCategoryValue(); Object oldWeight = getSortedUnsortedCategoryWeight(); + Object oldComputedWeight = getSortedUnsortedCategoryComputedWeight(); this.sortedUnsortedCategory = sortedUnsortedCategory; firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY, oldCategory, sortedUnsortedCategory); firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY_VALUE, oldValue, getSortedUnsortedCategoryValue()); firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT, oldWeight, getSortedUnsortedCategoryWeight()); + firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY_COMPUTED_WEIGHT, oldComputedWeight, getSortedUnsortedCategoryComputedWeight()); } public CaracteristicQualitativeValue getSortedUnsortedCategoryValue() { @@ -369,6 +379,16 @@ firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY_WEIGHT, oldValue, sortedUnsortedCategoryWeight); } + public Float getSortedUnsortedCategoryComputedWeight() { + return sortedUnsortedCategory.getComputedWeight(); + } + + public void setSortedUnsortedCategoryComputedWeight(Float sortedUnsortedCategoryComputedWeight) { + Object oldValue = getSortedUnsortedCategoryComputedWeight(); + sortedUnsortedCategory.setComputedWeight(sortedUnsortedCategoryComputedWeight); + firePropertyChange(PROPERTY_SORTED_UNSORTED_CATEGORY_COMPUTED_WEIGHT, oldValue, sortedUnsortedCategoryComputedWeight); + } + //------------------------------------------------------------------------// //-- Size category --// //------------------------------------------------------------------------// @@ -381,10 +401,12 @@ Object oldCategory = getSizeCategory(); Object oldValue = getSizeCategoryValue(); Object oldWeight = getSizeCategoryWeight(); + Object oldComputedWeight = getSizeCategoryComputedWeight(); this.sizeCategory = sizeCategory; firePropertyChange(PROPERTY_SIZE_CATEGORY, oldCategory, sizeCategory); firePropertyChange(PROPERTY_SIZE_CATEGORY_VALUE, oldValue, getSizeCategoryValue()); firePropertyChange(PROPERTY_SIZE_CATEGORY_WEIGHT, oldWeight, getSizeCategoryWeight()); + firePropertyChange(PROPERTY_SIZE_CATEGORY_COMPUTED_WEIGHT, oldComputedWeight, getSizeCategoryComputedWeight()); } public CaracteristicQualitativeValue getSizeCategoryValue() { @@ -401,6 +423,16 @@ firePropertyChange(PROPERTY_SIZE_CATEGORY_WEIGHT, oldValue, sizeCategoryWeight); } + public Float getSizeCategoryComputedWeight() { + return sizeCategory.getComputedWeight(); + } + + public void setSizeCategoryComputedWeight(Float sizeCategoryComputedWeight) { + Object oldValue = getSizeCategoryComputedWeight(); + this.sizeCategory.setComputedWeight(sizeCategoryComputedWeight); + firePropertyChange(PROPERTY_SIZE_CATEGORY_COMPUTED_WEIGHT, oldValue, sizeCategoryComputedWeight); + } + //------------------------------------------------------------------------// //-- Sex category --// //------------------------------------------------------------------------// @@ -413,10 +445,12 @@ Object oldCategory = getSexCategory(); Object oldValue = getSexCategoryValue(); Object oldWeight = getSexCategoryWeight(); + Object oldComputedWeight = getSexCategoryComputedWeight(); this.sexCategory = sexCategory; firePropertyChange(PROPERTY_SEX_CATEGORY, oldCategory, sexCategory); firePropertyChange(PROPERTY_SEX_CATEGORY_VALUE, oldValue, getSexCategoryValue()); firePropertyChange(PROPERTY_SEX_CATEGORY_WEIGHT, oldWeight, getSexCategoryWeight()); + firePropertyChange(PROPERTY_SEX_CATEGORY_COMPUTED_WEIGHT, oldComputedWeight, getSexCategoryComputedWeight()); } public CaracteristicQualitativeValue getSexCategoryValue() { @@ -433,6 +467,16 @@ firePropertyChange(PROPERTY_SEX_CATEGORY_WEIGHT, oldValue, sexCategoryWeight); } + public Float getSexCategoryComputedWeight() { + return sexCategory.getComputedWeight(); + } + + public void setSexCategoryComputedWeight(Float sexCategoryComputedWeight) { + Object oldValue = getSexCategoryComputedWeight(); + this.sexCategory.setComputedWeight(sexCategoryComputedWeight); + firePropertyChange(PROPERTY_SEX_CATEGORY_COMPUTED_WEIGHT, oldValue, sexCategoryComputedWeight); + } + //------------------------------------------------------------------------// //-- Maturity category --// //------------------------------------------------------------------------// @@ -445,10 +489,12 @@ Object oldCategory = getMaturityCategory(); Object oldValue = getMaturityCategoryValue(); Object oldWeight = getMaturityCategoryWeight(); + Object oldComputedWeight = getMaturityCategoryComputedWeight(); this.maturityCategory = maturityCategory; firePropertyChange(PROPERTY_MATURITY_CATEGORY, oldCategory, maturityCategory); firePropertyChange(PROPERTY_MATURITY_CATEGORY_VALUE, oldValue, getMaturityCategoryValue()); firePropertyChange(PROPERTY_MATURITY_CATEGORY_WEIGHT, oldWeight, getMaturityCategoryWeight()); + firePropertyChange(PROPERTY_MATURITY_CATEGORY_COMPUTED_WEIGHT, oldComputedWeight, getMaturityCategoryComputedWeight()); } public CaracteristicQualitativeValue getMaturityCategoryValue() { @@ -465,6 +511,16 @@ firePropertyChange(PROPERTY_MATURITY_CATEGORY_WEIGHT, oldValue, maturityCategoryWeight); } + public Float getMaturityCategoryComputedWeight() { + return maturityCategory.getComputedWeight(); + } + + public void setMaturityCategoryComputedWeight(Float maturityCategoryComputedWeight) { + Object oldValue = getMaturityCategoryComputedWeight(); + this.maturityCategory.setComputedWeight(maturityCategoryComputedWeight); + firePropertyChange(PROPERTY_MATURITY_CATEGORY_COMPUTED_WEIGHT, oldValue, maturityCategoryComputedWeight); + } + //------------------------------------------------------------------------// //-- Age category --// //------------------------------------------------------------------------// @@ -477,11 +533,12 @@ Object oldCategory = getAgeCategory(); Object oldValue = getAgeCategoryValue(); Object oldWeight = getAgeCategoryWeight(); + Object oldComputedWeight = getAgeCategoryComputedWeight(); this.ageCategory = ageCategory; - firePropertyChange(PROPERTY_AGE_CATEGORY, oldCategory, ageCategory); firePropertyChange(PROPERTY_AGE_CATEGORY_VALUE, oldValue, getAgeCategoryValue()); firePropertyChange(PROPERTY_AGE_CATEGORY_WEIGHT, oldWeight, getAgeCategoryWeight()); + firePropertyChange(PROPERTY_AGE_CATEGORY_COMPUTED_WEIGHT, oldComputedWeight, getAgeCategoryComputedWeight()); } public Float getAgeCategoryValue() { @@ -498,6 +555,16 @@ firePropertyChange(PROPERTY_AGE_CATEGORY_WEIGHT, oldValue, ageCategoryWeight); } + public Float getAgeCategoryComputedWeight() { + return ageCategory.getComputedWeight(); + } + + public void setAgeCategoryComputedWeight(Float ageCategoryComputedWeight) { + Object oldValue = getAgeCategoryComputedWeight(); + ageCategory.setComputedWeight(ageCategoryComputedWeight); + firePropertyChange(PROPERTY_AGE_CATEGORY_COMPUTED_WEIGHT, oldValue, ageCategoryComputedWeight); + } + //------------------------------------------------------------------------// //-- Navigation properties --// //------------------------------------------------------------------------// Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-04-05 13:36:16 UTC (rev 739) @@ -983,7 +983,7 @@ } } - protected BenthosBatchRowModel loadBatch(SpeciesBatch aBatch, + public BenthosBatchRowModel loadBatch(SpeciesBatch aBatch, BenthosBatchRowModel parentRow, List<BenthosBatchRowModel> rows) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/CreateBenthosMelagAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/CreateBenthosMelagAction.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/CreateBenthosMelagAction.java 2013-04-05 13:36:16 UTC (rev 739) @@ -72,12 +72,9 @@ tableModel.getEntry(selectedRowIndex); Float sampleWeight = null; - if (selectedRow.getFinestCategory().getCategoryWeight() != null) { - alreadyKnownWeights += selectedRow.getFinestCategory().getCategoryWeight(); + if (selectedRow.getFinestCategory().getNotNullWeight() != null) { + alreadyKnownWeights += selectedRow.getFinestCategory().getNotNullWeight(); - } else if (selectedRow.getFinestCategory().getComputedWeight() != null) { - alreadyKnownWeights += selectedRow.getFinestCategory().getComputedWeight(); - } else if (selectedRow.getWeight() != null) { sampleWeight = selectedRow.getWeight(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/CreateSpeciesMelagAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/CreateSpeciesMelagAction.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/CreateSpeciesMelagAction.java 2013-04-05 13:36:16 UTC (rev 739) @@ -72,12 +72,9 @@ tableModel.getEntry(selectedRowIndex); Float sampleWeight = null; - if (selectedRow.getFinestCategory().getCategoryWeight() != null) { - alreadyKnownWeights += selectedRow.getFinestCategory().getCategoryWeight(); + if (selectedRow.getFinestCategory().getNotNullWeight() != null) { + alreadyKnownWeights += selectedRow.getFinestCategory().getNotNullWeight(); - } else if (selectedRow.getFinestCategory().getComputedWeight() != null) { - alreadyKnownWeights += selectedRow.getFinestCategory().getComputedWeight(); - } else if (selectedRow.getWeight() != null) { sampleWeight = selectedRow.getWeight(); 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-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-04-05 13:36:16 UTC (rev 739) @@ -742,7 +742,9 @@ } } - public void splitBatch(SampleCategoryEnum sampleCategoryEnum, List<SplitSpeciesBatchRowModel> rows) { + public void splitBatch(SampleCategoryEnum sampleCategoryEnum, + List<SplitSpeciesBatchRowModel> rows, + Float totalRowWeight) { JXTable table = getTable(); // get selected row @@ -753,6 +755,9 @@ // Create rows in batch table model + Float parentWeight = parentBatch.getFinestCategory().getNotNullWeight(); + boolean subSample = parentWeight != null && totalRowWeight != null + && parentWeight > totalRowWeight; List<SpeciesBatchRowModel> newBatches = Lists.newArrayList(); for (SplitSpeciesBatchRowModel row : rows) { if (row.isValid()) { @@ -764,8 +769,11 @@ newBatch, sampleCategoryEnum, row.getCategoryValue(), - row.getWeight()); + row.getWeight(), + null); + newBatch.getFinestCategory().setSubSample(subSample); + recomputeRowValidState(newBatch); newBatches.add(newBatch); @@ -991,7 +999,7 @@ } } - protected SpeciesBatchRowModel loadBatch(SpeciesBatch aBatch, + public SpeciesBatchRowModel loadBatch(SpeciesBatch aBatch, SpeciesBatchRowModel parentRow, List<SpeciesBatchRowModel> rows) { @@ -1026,7 +1034,8 @@ newRow, sampleCategoryEnum, aBatch.getSampleCategoryValue(), - aBatch.getSampleCategoryWeight()); + aBatch.getSampleCategoryWeight(), + aBatch.getSampleCategoryComputedWeight()); rows.add(newRow); @@ -1037,10 +1046,28 @@ List<SpeciesBatchRowModel> batchChilds = Lists. newArrayListWithCapacity(aBatch.sizeChildBatchs()); + Float childrenWeights = 0f; for (SpeciesBatch childBatch : aBatch.getChildBatchs()) { SpeciesBatchRowModel childRow = loadBatch(childBatch, newRow, rows); + if (childrenWeights != null) { + Float weight = childRow.getFinestCategory().getNotNullWeight(); + if (weight == null) { + childrenWeights = null; + } else { + childrenWeights += weight; + } + } + batchChilds.add(childRow); } + + Float rowWeight = newRow.getFinestCategory().getNotNullWeight(); + boolean subSample = rowWeight != null && childrenWeights != null + && childrenWeights < rowWeight; + for (SpeciesBatchRowModel childRow : batchChilds) { + childRow.getFinestCategory().setSubSample(subSample); + } + newRow.setChildBatch(batchChilds); } @@ -1051,7 +1078,8 @@ SpeciesBatchRowModel newRow, SampleCategoryEnum sampleCategoryEnum, Serializable categoryValue, - Float categoryWeight) { + Float categoryWeight, + Float categoryComputedWeight) { // get sample category from his type SampleCategory sampleCategory = @@ -1060,6 +1088,7 @@ // fill it sampleCategory.setCategoryValue(categoryValue); sampleCategory.setCategoryWeight(categoryWeight); + sampleCategory.setComputedWeight(categoryComputedWeight); // push it back to row as his *main* sample category newRow.setSampleCategory(sampleCategory); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/split/SplitSpeciesBatchUIHandler.java 2013-04-05 13:36:16 UTC (rev 739) @@ -304,7 +304,8 @@ if (model.isValid()) { parent.getSpeciesTabContent().getHandler().splitBatch( model.getSelectedCategory(), - model.getRows()); + model.getRows(), + model.getSampleWeight()); } // close dialog Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolBenthosAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolBenthosAction.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolBenthosAction.java 2013-04-05 13:36:16 UTC (rev 739) @@ -119,8 +119,10 @@ // update rows in model model.setBenthosRow(rows); + getHandler().getBenthosTableModel().setRows(rows); + int nbSynonym = 0; - for (SpeciesProtocol speciesProtocol : protocol.getSpecies()) { + for (SpeciesProtocol speciesProtocol : protocol.getBenthos()) { if (!speciesProtocol.isMadeFromAReferentTaxon()) { nbSynonym++; } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/protocol/ImportProtocolSpeciesAction.java 2013-04-05 13:36:16 UTC (rev 739) @@ -119,6 +119,8 @@ // update rows in model model.setSpeciesRow(rows); + getHandler().getSpeciesTableModel().setRows(rows); + int nbSynonym = 0; for (SpeciesProtocol speciesProtocol : protocol.getSpecies()) { if (!speciesProtocol.isMadeFromAReferentTaxon()) { Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_en_GB.properties 2013-04-05 13:36:16 UTC (rev 739) @@ -310,6 +310,7 @@ tutti.editCatchBatch.action.importPupitri.mnemonic= tutti.editCatchBatch.action.importPupitri.noProtocol.message= tutti.editCatchBatch.action.importPupitri.noProtocol.title= +tutti.editCatchBatch.action.importPupitri.success= tutti.editCatchBatch.action.importPupitri.tip= tutti.editCatchBatch.action.saveCatchBatch= tutti.editCatchBatch.action.saveCatchBatch.mnemonic= Modified: trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties =================================================================== --- trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-04-04 19:49:47 UTC (rev 738) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2013-04-05 13:36:16 UTC (rev 739) @@ -108,7 +108,7 @@ tutti.createBenthosBatch.field.sortedUnsortedCategory.tip= tutti.createBenthosBatch.field.species=Espèce du lot tutti.createBenthosBatch.field.species.tip= -tutti.createBenthosBatch.title=Créer un lôt +tutti.createBenthosBatch.title=Créer un lot tutti.createBenthosMelag.action.cancel=Annuler tutti.createBenthosMelag.action.cancel.mnemonic=A tutti.createBenthosMelag.action.cancel.tip=Annuler la création du MELAG @@ -319,6 +319,7 @@ tutti.editCatchBatch.action.importPupitri.mnemonic=I tutti.editCatchBatch.action.importPupitri.noProtocol.message= tutti.editCatchBatch.action.importPupitri.noProtocol.title= +tutti.editCatchBatch.action.importPupitri.success= tutti.editCatchBatch.action.importPupitri.tip=Import Pupitri tutti.editCatchBatch.action.saveCatchBatch=Sauver tutti.editCatchBatch.action.saveCatchBatch.mnemonic=S @@ -1101,4 +1102,4 @@ tutti.vesselUseFeatureTable.action.removeCaracteristic.tip=Supprimer la caractéristique tutti.vesselUseFeatureTable.table.header.key=Caractéristique tutti.vesselUseFeatureTable.table.header.value=Valeur -tutti.vesselUseFeatureTable.title=Hydrologie et paramètres environnementaux +tutti.vesselUseFeatureTable.title=Autres paramètres
participants (1)
-
kmorin@users.forge.codelutin.com