This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit e03f99d6701a6885a089618a0866c12b99e69ed7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Feb 7 14:54:36 2015 +0100 - add Benthos column on catch export - clean code --- .../service/genericformat/csv/CatchModel.java | 6 +- .../tutti/service/genericformat/csv/CatchRow.java | 16 +-- .../producer/CsvProducerForCatch.java | 151 ++++++++++++--------- 3 files changed, 96 insertions(+), 77 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java index 5ae5c28..d5343cc 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java @@ -33,8 +33,8 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.csv.TuttiCsvUtil; import fr.ifremer.tutti.service.csv.AbstractTuttiImportExportModel; +import fr.ifremer.tutti.service.csv.TuttiCsvUtil; import fr.ifremer.tutti.service.genericformat.GlobalImportContext; /** @@ -91,6 +91,7 @@ public class CatchModel extends AbstractTuttiImportExportModel<CatchRow> { newColumnForExport("ReferenceTaxonId", SpeciesBatch.PROPERTY_SPECIES + "." + Species.PROPERTY_REFERENCE_TAXON_ID, TuttiCsvUtil.INTEGER); newColumnForExport("Code_Espece_Campagne", SpeciesBatch.PROPERTY_SPECIES + "." + Species.PROPERTY_SURVEY_CODE); newColumnForExport("Nom_scientifique", SpeciesBatch.PROPERTY_SPECIES + "." + Species.PROPERTY_NAME); + newColumnForExport("Benthos", CatchRow.PROPOERTY_BENTHOS, TuttiCsvUtil.BOOLEAN); newColumnForExport("Commentaire", SpeciesBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); for (SampleCategoryModelEntry entry : sampleCategoryModel.getCategory()) { @@ -135,11 +136,12 @@ public class CatchModel extends AbstractTuttiImportExportModel<CatchRow> { newMandatoryColumn("Engin", FishingOperation.PROPERTY_GEAR, globalImportContext.getOptionalGearParser()); newMandatoryColumn("ReferenceTaxonId", SpeciesBatch.PROPERTY_SPECIES, globalImportContext.getSpeciesParser()); + newColumnForExport("Benthos", CatchRow.PROPOERTY_BENTHOS, TuttiCsvUtil.BOOLEAN); // newColumnForExport("Code_Espece_Campagne", SpeciesBatch.PROPERTY_SPECIES + "." + Species.PROPERTY_SURVEY_CODE); // newColumnForExport("Nom_scientifique", SpeciesBatch.PROPERTY_SPECIES + "." + Species.PROPERTY_NAME); newMandatoryColumn("Commentaire", SpeciesBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); - //FIXME + //TODO for (SampleCategoryModelEntry entry : sampleCategoryModel.getCategory()) { String headerPrefix = entry.getCode(); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java index 74938d9..7fbc73d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchRow.java @@ -54,6 +54,8 @@ public class CatchRow implements Serializable { /** Logger. */ private static final Log log = LogFactory.getLog(CatchRow.class); + public static final String PROPOERTY_BENTHOS = "benthos"; + public static final String FREQUENCY_LENGTH_STEP = "frequency.lengthStep"; public static final String FREQUENCY_NUMBER = "frequency.number"; @@ -76,8 +78,6 @@ public class CatchRow implements Serializable { public static final String FINAL_RAISING_FACTOR = "finalRaisingFactor"; - public static final String BENTHOS_ROW = "benthosRow"; - protected Cruise cruise; protected FishingOperation fishingOperation; @@ -100,15 +100,15 @@ public class CatchRow implements Serializable { protected String batchWeightUnit; - protected final boolean benthosRow; + protected final boolean benthos; protected final boolean vrac; protected final List<String> comment = new ArrayList<>(); - public CatchRow(boolean vrac, boolean benthosRow) { + public CatchRow(boolean vrac, boolean benthos) { this.vrac = vrac; - this.benthosRow = benthosRow; + this.benthos = benthos; } public void setCruise(Cruise cruise) { @@ -235,12 +235,12 @@ public class CatchRow implements Serializable { return !isVrac(); } - public boolean isBenthosRow() { - return benthosRow; + public boolean isBenthos() { + return benthos; } public CatchRow copy() { - CatchRow result = new CatchRow(vrac, benthosRow); + CatchRow result = new CatchRow(vrac, benthos); result.setCruise(cruise); result.setFishingOperation(fishingOperation); result.sampleCategory.addAll(sampleCategory); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java index d5033df..749220a 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForCatch.java @@ -48,37 +48,28 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { Caracteristic weightMeasuredCaracteristic = operationExportContext.getWeightMeasuredCaracteristic(); String batchWeightUnit = weightMeasuredCaracteristic.getUnit(); - for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { - - boolean vracBatch = operationExportContext.isVracBatch(speciesBatch); - - CatchRow row = new CatchRow(vracBatch, false); - row.setCruise(operationExportContext.getCruise()); - row.setFishingOperation(operationExportContext.getOperation()); - row.setSpecies(speciesBatch.getSpecies()); - row.setBatchWeightUnit(batchWeightUnit); + addSpeciesBatches(operationExportContext, rootSpeciesBatch, speciesCatchRaisingFactor, batchWeightUnit, rows); + addBenthosBatches(operationExportContext, rootBenthosBatch, benthosCatchRaisingFactor, batchWeightUnit, rows); - float raisingFactor = speciesCatchRaisingFactor; + // compute final raising factor + // see http://forge.codelutin.com/issues/4135 + // see http://forge.codelutin.com/issues/5110 + for (CatchRow row : rows) { - if (!vracBatch) { + float finalRaisingFactor = computeFinalRaisingFactor(row, speciesCatchRaisingFactor, benthosCatchRaisingFactor); + row.setFinalRaisingFactor(finalRaisingFactor); - // for HV, always use a 1.0 raising factor - raisingFactor = 1.f; - } + } - Float batchWeight = Numbers.getValueOrComputedValue( - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight()); + return rows; - float totalBatchWeight = batchWeight == null ? 0 : raisingFactor * batchWeight; + } - addSpeciesBatch(operationExportContext, - row, - rows, - speciesBatch, - totalBatchWeight - ); - } + protected void addBenthosBatches(OperationExportContext operationExportContext, + BatchContainer<BenthosBatch> rootBenthosBatch, + Float benthosCatchRaisingFactor, + String batchWeightUnit, + List<CatchRow> rows) { for (BenthosBatch benthosBatch : rootBenthosBatch.getChildren()) { @@ -108,52 +99,49 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { row, rows, benthosBatch, - totalBatchWeight - ); - } + totalBatchWeight); - // compute final raising factor - // see http://forge.codelutin.com/issues/4135 - // see http://forge.codelutin.com/issues/5110 - for (CatchRow row : rows) { + } - float finalRaisingFactor; + } - if (row.isVrac()) { + protected void addSpeciesBatches(OperationExportContext operationExportContext, + BatchContainer<SpeciesBatch> rootSpeciesBatch, + Float speciesCatchRaisingFactor, + String batchWeightUnit, + List<CatchRow> rows) { - finalRaisingFactor = row.isBenthosRow() ? benthosCatchRaisingFactor : speciesCatchRaisingFactor; + for (SpeciesBatch speciesBatch : rootSpeciesBatch.getChildren()) { - } else { + boolean vracBatch = operationExportContext.isVracBatch(speciesBatch); - finalRaisingFactor = 1f; + CatchRow row = new CatchRow(vracBatch, false); + row.setCruise(operationExportContext.getCruise()); + row.setFishingOperation(operationExportContext.getOperation()); + row.setSpecies(speciesBatch.getSpecies()); + row.setBatchWeightUnit(batchWeightUnit); - } + float raisingFactor = speciesCatchRaisingFactor; - for (ExportSampleCategory exportSampleCategory : row.getSampleCategory()) { + if (!vracBatch) { - if (exportSampleCategory != null) { - Float totalWeight = exportSampleCategory.getCategoryWeight(); - Float sampleWeight = Numbers.getValueOrComputedValue( - exportSampleCategory.getSampleWeight(), - exportSampleCategory.getSampleComputedWeight()); + // for HV, always use a 1.0 raising factor + raisingFactor = 1.f; + } - if (totalWeight != null && sampleWeight != null && sampleWeight != 0f) { + Float batchWeight = Numbers.getValueOrComputedValue( + speciesBatch.getSampleCategoryWeight(), + speciesBatch.getSampleCategoryComputedWeight()); + float totalBatchWeight = batchWeight == null ? 0 : raisingFactor * batchWeight; - float currentRate = totalWeight / sampleWeight; - if (Weights.isNotEqualWeight(1.0f, currentRate)) { + addSpeciesBatch(operationExportContext, + row, + rows, + speciesBatch, + totalBatchWeight); - // the only case which can change the final rate - finalRaisingFactor *= currentRate; - } - } - } - } - row.setFinalRaisingFactor(finalRaisingFactor); } - - return rows; - } protected void addSpeciesBatch(OperationExportContext operationExportContext, @@ -292,16 +280,6 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { Integer rankOrder = benthosBatch.getRankOrder(); - if (currentRow.getSampleCategory().isEmpty()) { - - //FIXME Remove this when improve export for import - // See http://forge.codelutin.com/issues/5175 - // See http://forge.codelutin.com/issues/5754 - // Add 1000 to each benthos only batch rank-order - - rankOrder += 1000; - } - addBatchSampleCategory(operationExportContext.getSampleCategoryModel(), currentRow, benthosBatch.getSampleCategoryId(), @@ -407,6 +385,45 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { } } + protected float computeFinalRaisingFactor(CatchRow row, Float speciesCatchRaisingFactor, Float benthosCatchRaisingFactor) { + + float finalRaisingFactor; + + if (row.isVrac()) { + + finalRaisingFactor = row.isBenthos() ? benthosCatchRaisingFactor : speciesCatchRaisingFactor; + + } else { + + finalRaisingFactor = 1f; + + } + + for (ExportSampleCategory exportSampleCategory : row.getSampleCategory()) { + + if (exportSampleCategory != null) { + Float totalWeight = exportSampleCategory.getCategoryWeight(); + Float sampleWeight = Numbers.getValueOrComputedValue( + exportSampleCategory.getSampleWeight(), + exportSampleCategory.getSampleComputedWeight()); + + if (totalWeight != null && sampleWeight != null && sampleWeight != 0f) { + + + float currentRate = totalWeight / sampleWeight; + if (Weights.isNotEqualWeight(1.0f, currentRate)) { + + // the only case which can change the final rate + finalRaisingFactor *= currentRate; + } + } + } + } + + return finalRaisingFactor; + + } + protected void setRaisingFactor(CatchRow row, float totalBatchWeight, Float referenceWeight) { row.setReferenceWeight(referenceWeight); row.setRaisingFactor(referenceWeight == null ? 1.0f : (totalBatchWeight / referenceWeight)); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.