This is an automated email from the git hooks/post-receive script. New commit to branch feature/6688 in repository tutti. See http://git.codelutin.com/tutti.git commit fe12fd6b45b35319b821d3495a5c3a604f635539 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Feb 21 20:16:47 2015 +0100 fix batch creation --- .../entities/data/SpeciesAbleBatchs.java | 7 ++- .../consumer/CsvConsumerForCatch.java | 71 ++++++++++++++++------ .../tutti/service/genericformat/csv/CatchRow.java | 3 +- .../genericformat/csv/ExportSampleCategory.java | 4 ++ 4 files changed, 62 insertions(+), 23 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java index f388142..7e9ac01 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/SpeciesAbleBatchs.java @@ -70,6 +70,11 @@ public class SpeciesAbleBatchs { } + public static <B extends SpeciesAbleBatch> List<B> getChildBatchs(B batch) { + return (List<B>) batch.getChildBatchs(); + } + + public static <B extends SpeciesAbleBatch> void setParentBatch(B parent, B child) { if (parent instanceof SpeciesBatch) { @@ -80,7 +85,7 @@ public class SpeciesAbleBatchs { } - public static <B extends SpeciesAbleBatch> void addChildBatch(B child, B parent) { + public static <B extends SpeciesAbleBatch> void addChildBatch(B parent, B child) { if (child instanceof SpeciesBatch) { ((SpeciesBatch) parent).addChildBatchs((SpeciesBatch) child); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java index 6a6b513..34cfd0a 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForCatch.java @@ -13,6 +13,7 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequencys; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; +import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.service.csv.CsvComsumer; import fr.ifremer.tutti.service.genericformat.GenericFormatImportContext; @@ -22,6 +23,8 @@ import fr.ifremer.tutti.service.genericformat.csv.CatchModel; import fr.ifremer.tutti.service.genericformat.csv.CatchRow; import fr.ifremer.tutti.service.genericformat.csv.ExportSampleCategory; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.csv.ImportRow; import java.nio.file.Path; @@ -34,6 +37,9 @@ import java.nio.file.Path; */ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { + /** Logger. */ + private static final Log log = LogFactory.getLog(CsvConsumerForCatch.class); + private final Predicate<CatchRow> catchRowVracPredicate; public CsvConsumerForCatch(Path file, char separator, SampleCategoryModel sampleCategoryModel, GenericFormatImportEntityParserFactory parserFactory) { @@ -43,7 +49,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { @Override public boolean apply(CatchRow input) { ExportSampleCategory exportSampleCategory = input.getSampleCategory().get(0); - return QualitativeValueId.SORTED_VRAC.getValue().equals(exportSampleCategory.getCategoryValue()); + return QualitativeValueId.SORTED_VRAC.getValue().equals(((CaracteristicQualitativeValue) exportSampleCategory.getCategoryValue()).getIdAsInt()); } }; @@ -60,6 +66,16 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { //TODO checks! CatchRow bean = row.getBean(); + for (ExportSampleCategory sampleCategory : bean.getSampleCategory()) { + + if (sampleCategory.isFilled()) { + + if (sampleCategory.getCategoryValue() == null) { + //TODO + } + } + } + } } @@ -96,6 +112,9 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { frequency.setLengthStep(bean.getFrequencyLengthStep()); frequency.setWeight(bean.getFrequencyWeight()); frequency.setNumber(bean.getBatchNumber()); + if (log.isInfoEnabled()) { + log.info("Create benthos frequency " + frequency.getNumber() + " for batch: " + batch.getSpecies().getName() + " - " + batch.getSampleCategoryId() + " - " + batch.getSampleCategoryValue()); + } fishingOperationContext.addBenthosFrequency(batch, frequency); @@ -117,6 +136,10 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { frequency.setWeight(bean.getFrequencyWeight()); frequency.setNumber(bean.getBatchNumber()); + if (log.isInfoEnabled()) { + log.info("Create species frequency " + frequency.getNumber() + " for batch: " + batch.getSpecies().getName() + " - " + batch.getSampleCategoryId() + " - " + batch.getSampleCategoryValue()); + } + fishingOperationContext.addSpeciesFrequency(batch, frequency); } else { @@ -143,17 +166,15 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { batch = BenthosBatchs.newBenthosBatch(); batch.setSpecies(species); batch.setFishingOperation(fishingOperationContext.getFishingOperation()); + if (log.isInfoEnabled()) { + log.info("Create benthos root batch (" + (vrac ? "VRAC" : "HORS VRAC") + ") batch species: " + species.getName() + " for " + fishingOperationContext.getFishingOperationLabel()); + } fishingOperationContext.addBenthosBatch(vrac, batch); } - for (ExportSampleCategory exportSampleCategory : bean.getFilledSampleCategories()) { - - batch = (BenthosBatch) fillBatchCategories(batch, exportSampleCategory); - - } - + batch = fillBatchCategories(batch, bean); return batch; } @@ -172,32 +193,32 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { batch = SpeciesBatchs.newSpeciesBatch(); batch.setSpecies(species); batch.setFishingOperation(fishingOperationContext.getFishingOperation()); + if (log.isInfoEnabled()) { + log.info("Create species root batch (" + (vrac ? "VRAC" : "HORS VRAC") + ") batch species: " + species.getName() + " for " + fishingOperationContext.getFishingOperationLabel()); + } fishingOperationContext.addSpeciesBatch(vrac, batch); } - for (ExportSampleCategory exportSampleCategory : bean.getFilledSampleCategories()) { - - batch = (SpeciesBatch) fillBatchCategories(batch, exportSampleCategory); - - } - + batch = fillBatchCategories(batch, bean); return batch; } - protected void fillBatchCategories(SpeciesAbleBatch batch, CatchRow bean) { + protected <A extends SpeciesAbleBatch> A fillBatchCategories(A batch, CatchRow bean) { for (ExportSampleCategory exportSampleCategory : bean.getFilledSampleCategories()) { batch = fillBatchCategories(batch, exportSampleCategory); } + return batch; + } - protected SpeciesAbleBatch fillBatchCategories(SpeciesAbleBatch batch, ExportSampleCategory sampleCategory) { + protected <A extends SpeciesAbleBatch> A fillBatchCategories(A batch, ExportSampleCategory sampleCategory) { - SpeciesAbleBatch result = null; + A result = null; if (batch.getSampleCategoryId() == null) { @@ -209,10 +230,15 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } else { - if (!batch.isChildBatchsEmpty()) { + if (batch.getSampleCategoryId().equals(sampleCategory.getCategoryId()) && + batch.getSampleCategoryValue().equals(sampleCategory.getCategoryValue())) { + + result = batch; + + } else if (!batch.isChildBatchsEmpty()) { // got some childs, try to find a matching one - for (SpeciesAbleBatch childBatch : batch.getChildBatchs()) { + for (A childBatch : SpeciesAbleBatchs.getChildBatchs(batch)) { if (childBatch.getSampleCategoryId().equals(sampleCategory.getCategoryId()) && childBatch.getSampleCategoryValue().equals(sampleCategory.getCategoryValue())) { @@ -228,8 +254,13 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { if (result == null) { // add a child - SpeciesAbleBatch childBatch = SpeciesAbleBatchs.createNewChild(batch); - result = fillBatchCategories(childBatch, sampleCategory); + result = SpeciesAbleBatchs.createNewChild(batch); + result.setSampleCategoryId(sampleCategory.getCategoryId()); + result.setSampleCategoryValue(sampleCategory.getCategoryValue()); + result.setSampleCategoryWeight(sampleCategory.getCategoryWeight()); + if (log.isInfoEnabled()) { + log.info("Create child batch for batch: " + batch.getSpecies().getName() + " - " + batch.getSampleCategoryId() + " - " + batch.getSampleCategoryValue()); + } } 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 01f1e48..79c79f6 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 @@ -297,9 +297,8 @@ public class CatchRow extends RowWithOperationContextSupport { List<ExportSampleCategory> result = new ArrayList<>(); for (ExportSampleCategory exportSampleCategory : sampleCategory) { - if (exportSampleCategory.getCategoryValue() != null) { + if (exportSampleCategory.isFilled()) { result.add(exportSampleCategory); - } } return result; diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/ExportSampleCategory.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/ExportSampleCategory.java index 4612542..189e09f 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/ExportSampleCategory.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/ExportSampleCategory.java @@ -96,4 +96,8 @@ public class ExportSampleCategory<S extends Serializable> extends SampleCategory return categoryDef.getCaracteristic(); } + public boolean isFilled() { + return getCategoryValue() != null; + } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.