r1766 - in trunk: tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport tutti-service/src/main/resources/i18n tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport tutti-service/src/test/resources/psion tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action tutti-ui-swing/src/main/resources/i18n
Author: tchemit Date: 2014-05-14 14:55:14 +0200 (Wed, 14 May 2014) New Revision: 1766 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1766 Log: report refs #5059 (l'import psion est ?\195?\160 corriger) (from version 3.4.2) Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportBatchModel.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportResult.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java 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-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java trunk/tutti-service/src/test/resources/psion/CC053.IWA trunk/tutti-service/src/test/resources/psion/FM001.IWA trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPsionAction.java trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportBatchModel.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportBatchModel.java 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportBatchModel.java 2014-05-14 12:55:14 UTC (rev 1766) @@ -150,6 +150,17 @@ return frequencies.size(); } + void merge(PsionImportBatchModel batchModel) { + setWeight(getWeight() + batchModel.getWeight()); + setSampleWeight(getSampleWeight() + batchModel.getSampleWeight()); + + for (Map.Entry<Float, MutableInt> entry : batchModel.getFrequencies().entrySet()) { + Float stepClass = entry.getKey(); + int number = entry.getValue().intValue(); + addFrequency(stepClass, number); + } + } + @Override public String toString() { return new ToStringBuilder(this) Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportModel.java 2014-05-14 12:55:14 UTC (rev 1766) @@ -24,19 +24,29 @@ * #L% */ +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; import com.google.common.collect.Sets; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.referential.Species; -import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import static org.nuiton.i18n.I18n.t; + /** * Created on 1/20/14. * @@ -48,40 +58,67 @@ /** Logger. */ private static final Log log = LogFactory.getLog(PsionImportModel.class); - protected final Map<String, PsionImportBatchModel> batchsByCategory; + /** + * All registred species in their registred order. + */ + protected final LinkedHashSet<Species> speciesSet; + /** + * All sorted batch indexed by their species. + * + * @since 3.4.2 + */ + protected final Multimap<Species, PsionImportBatchModel> sortedBatchsBySpecies; + + /** + * All unsorted batch indexed by their species. + * + * @since 3.4.2 + */ + protected final Multimap<Species, PsionImportBatchModel> unsortedBatchsBySpecies; + protected final List<String> errors; public PsionImportModel() { - batchsByCategory = Maps.newLinkedHashMap(); + speciesSet = new LinkedHashSet<>(); + sortedBatchsBySpecies = ArrayListMultimap.create(); + unsortedBatchsBySpecies = ArrayListMultimap.create(); errors = Lists.newArrayList(); } public boolean withBatchs() { - return !batchsByCategory.isEmpty(); + return !speciesSet.isEmpty(); } public Set<Species> getSpecies() { - Set<Species> result = Sets.newLinkedHashSet(); - for (PsionImportBatchModel batch : batchsByCategory.values()) { - result.add(batch.getSpecies()); + Set<Species> result = ImmutableSet.copyOf(speciesSet); + return result; + } + + public List<PsionImportBatchModel> getUnsortedBatches(Species species) { + Collection<PsionImportBatchModel> batches = unsortedBatchsBySpecies.get(species); + List<PsionImportBatchModel> result = null; + + if (batches != null) { + result = ImmutableList.copyOf(batches); + } return result; } - public List<PsionImportBatchModel> getBatchs(Species species) { - List<PsionImportBatchModel> result = Lists.newArrayList(); - for (PsionImportBatchModel batch : batchsByCategory.values()) { - if (species.equals(batch.getSpecies())) { - result.add(batch); - } + public List<PsionImportBatchModel> getSortedBatches(Species species) { + Collection<PsionImportBatchModel> batches = sortedBatchsBySpecies.get(species); + List<PsionImportBatchModel> result = null; + + if (batches != null) { + result = ImmutableList.copyOf(batches); } return result; } public Set<Integer> getSampleCategoryIdUsed() { Set<Integer> result = Sets.newHashSet(); - for (PsionImportBatchModel batch : batchsByCategory.values()) { + for (PsionImportBatchModel batch : sortedBatchsBySpecies.values()) { Iterator<PsionImportBatchModel.SampleCategory> categoryIterator = batch.getCategoryIterator(); while (categoryIterator.hasNext()) { PsionImportBatchModel.SampleCategory next = categoryIterator.next(); @@ -89,6 +126,14 @@ result.add(next.getCategoryId()); } } + for (PsionImportBatchModel batch : unsortedBatchsBySpecies.values()) { + Iterator<PsionImportBatchModel.SampleCategory> categoryIterator = batch.getCategoryIterator(); + while (categoryIterator.hasNext()) { + PsionImportBatchModel.SampleCategory next = categoryIterator.next(); + + result.add(next.getCategoryId()); + } + } return result; } @@ -96,32 +141,65 @@ return !errors.isEmpty(); } + public List<String> getErrors() { + return errors; + } + void addBatch(PsionImportBatchModel batchModel) { - String cacheCode = batchModel.getSpecies().getSurveyCode() + "_" + batchModel.getCategoryCode(); + Species species = batchModel.getSpecies(); + speciesSet.add(species); + + String categoryCode = batchModel.getCategoryCode(); + Float weight = batchModel.getWeight(); + Float sampleWeight = batchModel.getSampleWeight(); - PsionImportBatchModel mergeBatch = batchsByCategory.get(cacheCode); + Multimap<Species, PsionImportBatchModel> store; + // --- Guess if sorted or unsorted batch --- // + if (TuttiEntities.isGreaterWeight(weight, 0) && TuttiEntities.isEqualWeight(weight, sampleWeight)) { + + store = unsortedBatchsBySpecies; + if (log.isInfoEnabled()) { + log.info(String.format("Found a unsorted batch [%s] %s - %s", species.getSurveyCode(), weight, sampleWeight)); + } + } else { + + store = sortedBatchsBySpecies; + if (log.isInfoEnabled()) { + log.info(String.format("Found a sorted batch [%s] %s - %s", species.getSurveyCode(), weight, sampleWeight)); + } + } + + // --- Get if exist the previous batch --- // + + Collection<PsionImportBatchModel> psionImportBatchModels = store.get(species); + + PsionImportBatchModel mergeBatch = null; + + if (CollectionUtils.isNotEmpty(psionImportBatchModels)) { + + for (PsionImportBatchModel importBatchModel : psionImportBatchModels) { + if (categoryCode.equals(importBatchModel.getCategoryCode())) { + mergeBatch = importBatchModel; + break; + } + } + } + if (mergeBatch == null) { // new batch - batchsByCategory.put(cacheCode, batchModel); + store.put(species, batchModel); if (log.isDebugEnabled()) { log.debug("Added " + batchModel); } } else { - // merge data with this batch + // merge batch + mergeBatch.merge(batchModel); - mergeBatch.setWeight(mergeBatch.getWeight() + batchModel.getWeight()); - mergeBatch.setSampleWeight(mergeBatch.getSampleWeight() + batchModel.getSampleWeight()); - - for (Map.Entry<Float, MutableInt> entry : batchModel.getFrequencies().entrySet()) { - Float stepClass = entry.getKey(); - int number = entry.getValue().intValue(); - mergeBatch.addFrequency(stepClass, number); - } if (log.isDebugEnabled()) { log.debug("Merged " + batchModel + " to " + mergeBatch); } @@ -132,7 +210,72 @@ errors.add(error); } - public List<String> getErrors() { - return errors; + void cleanSortedBatches() { + + for (Species species : sortedBatchsBySpecies.keySet()) { + + for (PsionImportBatchModel batchModel : sortedBatchsBySpecies.get(species)) { + + Float weight = batchModel.getWeight(); + Float sampleWeight = batchModel.getSampleWeight(); + + if (TuttiEntities.isEqualWeight(weight, 0) && TuttiEntities.isGreaterWeight(sampleWeight, 0)) { + + // POID = 0 et TAIL != POID : un seul poids à positionner + batchModel.setWeight(sampleWeight); + batchModel.setSampleWeight(null); + + } + + } + + } } + + void cleanUnsortedBatches() { + + for (Species species : unsortedBatchsBySpecies.keySet()) { + + for (PsionImportBatchModel batchModel : unsortedBatchsBySpecies.get(species)) { + + // POID = TAIL un seul poids à positionner + batchModel.setSampleWeight(null); + } + + } + } + + void checkSortedBatches() throws IOException { + + Set<Species> speciesSet = sortedBatchsBySpecies.keySet(); + + for (Species species : speciesSet) { + + Collection<PsionImportBatchModel> sortedBatches = sortedBatchsBySpecies.get(species); + + Map<String, Float> weightByCategory = new HashMap<>(); + + for (PsionImportBatchModel sortedBatch : sortedBatches) { + Float weight = sortedBatch.getWeight(); + if (TuttiEntities.isGreaterWeight(weight, 0)) { + + Float rootweight = weightByCategory.get(sortedBatch.getCategoryCode()); + + if (rootweight == null) { + + // first time + weightByCategory.put(sortedBatch.getCategoryCode(), weight); + } else if (!TuttiEntities.isEqualWeight(rootweight, weight)) { + + // can't have 2 batches with different vrac batch weight + throw new IOException( + t("tutti.service.psionimport.error.inconsistentVracWeight.message", species.getSurveyCode())); + } + + } + } + } + + } + } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportResult.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportResult.java 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportResult.java 2014-05-14 12:55:14 UTC (rev 1766) @@ -41,8 +41,10 @@ protected final List<String> errors; - protected int nbImported; + protected int nbSortedImported; + protected int nbUnsortedImported; + public PsionImportResult(File importFile, List<String> errors) { this.importFile = importFile; this.errors = Lists.newArrayList(errors); @@ -52,18 +54,26 @@ return importFile; } - public int getNbImported() { - return nbImported; + public int getNbSortedImported() { + return nbSortedImported; } + public int getNbUnsortedImported() { + return nbUnsortedImported; + } + public List<String> getErrors() { return errors; } - void incrementNbImported() { - this.nbImported++; + void incrementNbSortedImported() { + this.nbSortedImported++; } + void incrementNbUnsortedImported() { + this.nbUnsortedImported++; + } + void addError(String error) { errors.add(error); } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java 2014-05-14 12:55:14 UTC (rev 1766) @@ -55,6 +55,7 @@ import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.type.WeightUnit; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.mutable.MutableInt; @@ -230,33 +231,48 @@ if (log.isWarnEnabled()) { log.warn("Won't import psion file, errors detected."); } - } else { - // check sample categories exists + return result; + } - SampleCategoryModel sampleCategoryModel = context.getSampleCategoryModel(); - Set<Integer> sampleCategoryIdUsed = importModel.getSampleCategoryIdUsed(); - List<String> missingCategories = Lists.newArrayList(); - for (Integer categoryId : sampleCategoryIdUsed) { - if (!sampleCategoryModel.containsCategoryId(categoryId)) { - missingCategories.add("<li>" + categoryId + "</li>"); - } + // --- Check sample category id used --- // + SampleCategoryModel sampleCategoryModel = context.getSampleCategoryModel(); + Set<Integer> sampleCategoryIdUsed = importModel.getSampleCategoryIdUsed(); + List<String> missingCategories = Lists.newArrayList(); + for (Integer categoryId : sampleCategoryIdUsed) { + if (!sampleCategoryModel.containsCategoryId(categoryId)) { + missingCategories.add("<li>" + categoryId + "</li>"); } + } - if (!missingCategories.isEmpty()) { + if (!missingCategories.isEmpty()) { - result.addError( - t("tutti.service.psionimport.error.invalidSampleCategoryModel.message", - Joiner.on("").join(missingCategories)) - ); - } else { + result.addError( + t("tutti.service.psionimport.error.invalidSampleCategoryModel.message", + Joiner.on("").join(missingCategories)) + ); - // persist in db - persist(result, importModel, operation, catchBatch); - } + return result; + } + // --- Check sorted batches --- // + try { + importModel.checkSortedBatches(); + } catch (IOException e) { + result.addError(e.getMessage()); + return result; } + // --- clean sorted batches --- // + importModel.cleanSortedBatches(); + + // --- clean unsorted batches --- // + importModel.cleanUnsortedBatches(); + + // --- Ok no error, can persist --- // + + persist(result, importModel, operation, catchBatch); + return result; } @@ -283,7 +299,7 @@ throw new IOException(t("tutti.service.psionimport.error.invalid.date.format")); } - boolean correctOperation = Objects.equals(operationCode, operation.getStationNumber()) && + boolean correctOperation = Objects.equals(operationCode, String.valueOf(operation.getFishingOperationNumber())) && Objects.equals(operationDate, operation.getGearShootingStartDate()); if (!correctOperation) { @@ -494,106 +510,199 @@ for (Species specy : species) { - List<PsionImportBatchModel> batchs = importModel.getBatchs(specy); + List<PsionImportBatchModel> sortedBatchs = importModel.getSortedBatches(specy); - if (batchs.size() == 1 && !batchs.get(0).withCategories()) { + if (CollectionUtils.isNotEmpty(sortedBatchs)) { + persistSortedBatches(operation, specy, sortedBatchs); - PsionImportBatchModel batchModel = batchs.get(0); + result.incrementNbSortedImported(); + } - // simple batch with no category - SpeciesBatch batch = createSpeciesBatch(operation, - batchModel.getSpecies(), - batchModel.getWeight(), - batchModel.getSampleWeight(), + List<PsionImportBatchModel> unsortedBatchs = importModel.getUnsortedBatches(specy); + + if (CollectionUtils.isNotEmpty(unsortedBatchs)) { + persistUnsortedBatches(operation, specy, unsortedBatchs); + + result.incrementNbUnsortedImported(); + } + + } + + persistenceService.saveCatchBatch(catchBatch); + } + + protected void persistSortedBatches(FishingOperation operation, + Species specy, + List<PsionImportBatchModel> batchs) { + + if (batchs.size() == 1 && !batchs.get(0).withCategories()) { + + PsionImportBatchModel batchModel = batchs.get(0); + + // simple batch with no category + SpeciesBatch batch = createSpeciesBatch(operation, + batchModel.getSpecies(), + batchModel.getWeight(), + batchModel.getSampleWeight(), + PmfmId2.SORTED_UNSORTED.getValue(), + sortedCaracteristic); + + + batch = persistenceService.createSpeciesBatch(batch, null); + + persistFrequencies(batch, batchModel); + + } else { + + // batch with categories + + // Is there two weights ? If so then the weight has to be placed in the sorted batch + + Float sortedBatchWeight = null; + + Float weight = batchs.get(0).getWeight(); + Float sampleWeight = batchs.get(0).getSampleWeight(); + + if (sampleWeight != null) { + + // use the weight as sorted batch weight + sortedBatchWeight = weight; + } + + SpeciesBatch rootBatch = createSpeciesBatch(operation, + specy, + sortedBatchWeight, + null, PmfmId2.SORTED_UNSORTED.getValue(), sortedCaracteristic); - batch = persistenceService.createSpeciesBatch(batch, null); + rootBatch = persistenceService.createSpeciesBatch(rootBatch, null); - persistFrequencies(batch, batchModel); + createCategoryBatches(operation, specy, batchs, rootBatch, sortedBatchWeight != null); - } else { + } - // batch with categories + } - SpeciesBatch rootBatch = createSpeciesBatch(operation, - specy, - null, - null, - PmfmId2.SORTED_UNSORTED.getValue(), - sortedCaracteristic); + protected void persistUnsortedBatches(FishingOperation operation, + Species specy, + List<PsionImportBatchModel> batchs) { - rootBatch = persistenceService.createSpeciesBatch(rootBatch, null); + if (batchs.size() == 1 && !batchs.get(0).withCategories()) { + PsionImportBatchModel batchModel = batchs.get(0); - for (PsionImportBatchModel batchModel : batchs) { + // simple batch with no category + SpeciesBatch batch = createSpeciesBatch(operation, + batchModel.getSpecies(), + batchModel.getWeight(), + batchModel.getSampleWeight(), + PmfmId2.SORTED_UNSORTED.getValue(), + unsortedCaracteristic); - SpeciesBatch parentBatch = rootBatch; + batch = persistenceService.createSpeciesBatch(batch, null); - SpeciesBatch childBatch = null; + persistFrequencies(batch, batchModel); - Iterator<PsionImportBatchModel.SampleCategory> categoryIterator = batchModel.getCategoryIterator(); + } else { - while (categoryIterator.hasNext()) { - PsionImportBatchModel.SampleCategory sampleCategory = categoryIterator.next(); + // batch with categories - boolean lastCategory = !categoryIterator.hasNext(); + SpeciesBatch rootBatch = createSpeciesBatch(operation, + specy, + null, + null, + PmfmId2.SORTED_UNSORTED.getValue(), + unsortedCaracteristic); - Integer categoryId = sampleCategory.getCategoryId(); - Serializable categoryValue = sampleCategory.getCategoryValue(); + rootBatch = persistenceService.createSpeciesBatch(rootBatch, null); - if (lastCategory) { + createCategoryBatches(operation, specy, batchs, rootBatch, false); - // always create the leaf - childBatch = createSpeciesBatch(operation, - specy, - batchModel.getWeight(), - batchModel.getSampleWeight(), - categoryId, - categoryValue); - } else { + } - // try to find child in parent children + } - childBatch = null; - for (SpeciesBatch speciesBatch : parentBatch.getChildBatchs()) { + protected void createCategoryBatches(FishingOperation operation, + Species specy, + List<PsionImportBatchModel> batchs, + SpeciesBatch rootBatch, + boolean applyOnlySampleWeight) { - if (speciesBatch.getSampleCategoryId().equals(categoryId) && - speciesBatch.getSampleCategoryValue().equals(categoryValue)) { - childBatch = speciesBatch; - break; - } - } + for (PsionImportBatchModel batchModel : batchs) { - if (childBatch == null) { + SpeciesBatch parentBatch = rootBatch; - // must create it - childBatch = createSpeciesBatch(operation, - specy, - null, - null, - categoryId, - categoryValue); - } - } + SpeciesBatch childBatch = null; - if (TuttiEntities.isNew(childBatch)) { + Iterator<PsionImportBatchModel.SampleCategory> categoryIterator = batchModel.getCategoryIterator(); - // persist it - childBatch = persistenceService.createSpeciesBatch(childBatch, parentBatch.getId()); - parentBatch.addChildBatchs(childBatch); + while (categoryIterator.hasNext()) { + PsionImportBatchModel.SampleCategory sampleCategory = categoryIterator.next(); + + boolean lastCategory = !categoryIterator.hasNext(); + + Integer categoryId = sampleCategory.getCategoryId(); + Serializable categoryValue = sampleCategory.getCategoryValue(); + + if (lastCategory) { + + // always create the leaf + + Float weight; + Float sampleWeight; + + if (applyOnlySampleWeight) { + weight = batchModel.getSampleWeight(); + sampleWeight = null; + } else { + weight = batchModel.getWeight(); + sampleWeight = batchModel.getSampleWeight(); + } + childBatch = createSpeciesBatch(operation, + specy, + weight, + sampleWeight, + categoryId, + categoryValue); + } else { + + // try to find child in parent children + + childBatch = null; + for (SpeciesBatch speciesBatch : parentBatch.getChildBatchs()) { + + if (speciesBatch.getSampleCategoryId().equals(categoryId) && + speciesBatch.getSampleCategoryValue().equals(categoryValue)) { + childBatch = speciesBatch; + break; } + } - parentBatch = childBatch; + if (childBatch == null) { + + // must create it + childBatch = createSpeciesBatch(operation, + specy, + null, + null, + categoryId, + categoryValue); } + } - persistFrequencies(childBatch, batchModel); + if (TuttiEntities.isNew(childBatch)) { + + // persist it + childBatch = persistenceService.createSpeciesBatch(childBatch, parentBatch.getId()); + parentBatch.addChildBatchs(childBatch); } + + parentBatch = childBatch; } - result.incrementNbImported(); + + persistFrequencies(childBatch, batchModel); } - - persistenceService.saveCatchBatch(catchBatch); } protected PsionImportBatchModel.SampleCategory guessCategory(String categoryCode) { 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 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties 2014-05-14 12:55:14 UTC (rev 1766) @@ -160,6 +160,7 @@ tutti.service.protocol.import.species.error= tutti.service.protocol.import.taxonUsed.error= tutti.service.psion.import.attachment.comment= +tutti.service.psionimport.error.inconsistentVracWeight.message= tutti.service.psionimport.error.invalid.category.syntax= tutti.service.psionimport.error.invalid.command.syntax= tutti.service.psionimport.error.invalid.date.format= 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 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties 2014-05-14 12:55:14 UTC (rev 1766) @@ -159,6 +159,7 @@ tutti.service.protocol.import.species.error=Erreur lors de l'import des espèces du protocole %1s du fichier %2s tutti.service.protocol.import.taxonUsed.error=Le taxon référent d'id %s est déjà utilisé tutti.service.psion.import.attachment.comment=Import Psion du %s +tutti.service.psionimport.error.inconsistentVracWeight.message=Pour l'espèce '%s', il existe deux enregistrements de lot vrac avec le champs 'POID' différent, ce qui est interdit tutti.service.psionimport.error.invalid.category.syntax=Ligne %s, catégorisation '%s' inconnue, l'espèce %s sera ignorée tutti.service.psionimport.error.invalid.command.syntax=Ligne %s, la commande '%s' n'est pas reconnue tutti.service.psionimport.error.invalid.date.format=Format de la date du trait incorrecte (mm-dd-aaaa) Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/psionimport/PsionImportServiceTest.java 2014-05-14 12:55:14 UTC (rev 1766) @@ -24,11 +24,16 @@ * #L% */ +import com.google.common.base.Predicate; +import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId2; +import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; import fr.ifremer.tutti.TuttiConfigurationOption; import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; 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.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ServiceDbResource; @@ -79,6 +84,8 @@ protected File dataDirectory; + protected Predicate<SpeciesAbleBatch> vracPredicate; + @Before public void setUp() throws Exception { @@ -99,6 +106,8 @@ progressionModel.setTotal(9); dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 3, OPERATION_2_ID, OPERATION_1_ID, OPERATION_3_ID); + + vracPredicate = TuttiEntities.newSpeciesAbleBatchCategoryPredicate(PmfmId2.SORTED_UNSORTED.getValue(), QualitativeValueId.VRAC.getValue()); } @Test @@ -111,24 +120,55 @@ catchBatch.setFishingOperation(operation); BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId(), false); - int oldNbBatchs = rootSpeciesBatch.sizeChildren(); + int oldSortedBatchs = 0; + int oldUnsortedBatchs = 0; + for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { + boolean sorted = vracPredicate.apply(speciesBatch); + + if (sorted) { + oldSortedBatchs++; + } else { + oldUnsortedBatchs++; + } + } + PsionImportResult importResult = service.importFile(importFile, operation, catchBatch); - int nbAdded = importResult.getNbImported(); + int nbSortedAdded = importResult.getNbSortedImported(); + int nbUnsortedAdded = importResult.getNbUnsortedImported(); List<String> errors = importResult.getErrors(); if (log.isInfoEnabled()) { - log.info("Imported: " + nbAdded); + log.info("Sorted Imported: " + nbSortedAdded); + log.info("Unsorted Imported: " + nbUnsortedAdded); log.info("Errors: " + errors.size()); } - Assert.assertEquals(17, nbAdded); + int nbNewSortedBatchs = 10; + int nbNewUnsortedBatchs = 9; + Assert.assertEquals(nbNewSortedBatchs, nbSortedAdded); + Assert.assertEquals(nbNewUnsortedBatchs, nbUnsortedAdded); Assert.assertEquals(0, errors.size()); // no batch imported BatchContainer<SpeciesBatch> rootSpeciesBatchAfter = persistenceService.getRootSpeciesBatch(operation.getId(), false); - Assert.assertEquals(oldNbBatchs + 17, rootSpeciesBatchAfter.sizeChildren()); + + int totalSortedBatchs = 0; + int totalUnsortedBatchs = 0; + for (SpeciesBatch speciesBatch : rootSpeciesBatchAfter.getChildren()) { + + boolean sorted = vracPredicate.apply(speciesBatch); + + if (sorted) { + totalSortedBatchs++; + } else { + totalUnsortedBatchs++; + } + } + + Assert.assertEquals(oldSortedBatchs + nbNewSortedBatchs, totalSortedBatchs); + Assert.assertEquals(oldUnsortedBatchs + nbNewUnsortedBatchs, totalUnsortedBatchs); } @Test @@ -141,23 +181,54 @@ catchBatch.setFishingOperation(operation); BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId(), false); - int oldNbBatchs = rootSpeciesBatch.sizeChildren(); + int oldSortedBatchs = 0; + int oldUnsortedBatchs = 0; + for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { + boolean sorted = vracPredicate.apply(speciesBatch); + + if (sorted) { + oldSortedBatchs++; + } else { + oldUnsortedBatchs++; + } + } + PsionImportResult importResult = service.importFile(importFile, operation, catchBatch); - int nbAdded = importResult.getNbImported(); + int nbSortedAdded = importResult.getNbSortedImported(); + int nbUnsortedAdded = importResult.getNbUnsortedImported(); List<String> errors = importResult.getErrors(); if (log.isInfoEnabled()) { - log.info("Imported: " + nbAdded); + log.info("Sorted Imported: " + nbSortedAdded); + log.info("Unsorted Imported: " + nbUnsortedAdded); log.info("Errors: " + errors.size()); } - Assert.assertEquals(10, nbAdded); + int nbNewSortedBatchs = 0; + int nbNewUnsortedBatchs = 10; + Assert.assertEquals(nbNewSortedBatchs, nbSortedAdded); + Assert.assertEquals(nbNewUnsortedBatchs, nbUnsortedAdded); Assert.assertEquals(0, errors.size()); BatchContainer<SpeciesBatch> rootSpeciesBatchAfter = persistenceService.getRootSpeciesBatch(operation.getId(), false); - Assert.assertEquals(oldNbBatchs + 10, rootSpeciesBatchAfter.sizeChildren()); + + int totalSortedBatchs = 0; + int totalUnsortedBatchs = 0; + for (SpeciesBatch speciesBatch : rootSpeciesBatchAfter.getChildren()) { + + boolean sorted = vracPredicate.apply(speciesBatch); + + if (sorted) { + totalSortedBatchs++; + } else { + totalUnsortedBatchs++; + } + } + + Assert.assertEquals(oldSortedBatchs + nbNewSortedBatchs, totalSortedBatchs); + Assert.assertEquals(oldUnsortedBatchs + nbNewUnsortedBatchs, totalUnsortedBatchs); } @Test @@ -173,15 +244,18 @@ int oldNbBatchs = rootSpeciesBatch.sizeChildren(); PsionImportResult importResult = service.importFile(importFile, operation, catchBatch); - int nbAdded = importResult.getNbImported(); + int nbSortedAdded = importResult.getNbSortedImported(); + int nbUnsortedAdded = importResult.getNbUnsortedImported(); List<String> errors = importResult.getErrors(); if (log.isInfoEnabled()) { - log.info("Imported: " + nbAdded); + log.info("Sorted Imported: " + nbSortedAdded); + log.info("Unsorted Imported: " + nbUnsortedAdded); log.info("Errors: " + errors.size()); } - Assert.assertEquals(0, nbAdded); + Assert.assertEquals(0, nbSortedAdded); + Assert.assertEquals(0, nbUnsortedAdded); Assert.assertEquals(1, errors.size()); // no batch imported Modified: trunk/tutti-service/src/test/resources/psion/CC053.IWA =================================================================== --- trunk/tutti-service/src/test/resources/psion/CC053.IWA 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/test/resources/psion/CC053.IWA 2014-05-14 12:55:14 UTC (rev 1766) @@ -1,5 +1,5 @@ cc -A +1 07-01-2013 07:19:11 Modified: trunk/tutti-service/src/test/resources/psion/FM001.IWA =================================================================== --- trunk/tutti-service/src/test/resources/psion/FM001.IWA 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-service/src/test/resources/psion/FM001.IWA 2014-05-14 12:55:14 UTC (rev 1766) @@ -1,5 +1,5 @@ fm -A +1 07-01-2013 18:28:13 Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPsionAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPsionAction.java 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportPsionAction.java 2014-05-14 12:55:14 UTC (rev 1766) @@ -125,7 +125,7 @@ if (importResult.isDone()) { sendMessage(t("tutti.editSpeciesBatch.action.importPsion.success", - importResult.getNbImported())); + importResult.getNbSortedImported(), importResult.getNbUnsortedImported())); } else { StringBuilder sb = new StringBuilder(); 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 2014-05-14 12:32:05 UTC (rev 1765) +++ trunk/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties 2014-05-14 12:55:14 UTC (rev 1766) @@ -984,7 +984,7 @@ tutti.editSpeciesBatch.action.importPsion.no.matching.data=Import psion non réalisé (des erreurs ont été détectées lors de la lecture du fichier) tutti.editSpeciesBatch.action.importPsion.no.matching.fishingOperation=L'import Psion n'a pas été réalisé, des erreurs ont été détectées \:<ul>%s</ul><br/>Aucun lot n'a donc été importé. tutti.editSpeciesBatch.action.importPsion.no.matching.fishingOperation.title=Import Psion -tutti.editSpeciesBatch.action.importPsion.success=Import Psion réussi \: %1s espèces importées +tutti.editSpeciesBatch.action.importPsion.success=Import Psion réussi \: %1s espèces importées (Vrac), %2s espèces importées (Hors-Vrac) tutti.editSpeciesBatch.action.importPsion.tip=Import Psion tutti.editSpeciesBatch.action.importPupitri=Import Pupitri tutti.editSpeciesBatch.action.importPupitri.existingData.help=Que voulez-vous faire ?<ul><li><strong>Annuler</strong> pour ne pas importer les données Pupitri et conserver les espèces saisies</li><li><strong>OK</strong> pour supprimer les espèces existantes et les remplacer par les données de Pupitri</li></ul>
participants (1)
-
tchemit@users.forge.codelutin.com