Author: tchemit Date: 2014-03-21 16:22:11 +0100 (Fri, 21 Mar 2014) New Revision: 1632 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1632 Log: fixes #4797: [EXPORT GENERIQUE] Export du Hors vrac Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportModel.java Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportModel.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportModel.java 2014-03-21 14:04:03 UTC (rev 1631) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportModel.java 2014-03-21 15:22:11 UTC (rev 1632) @@ -115,26 +115,45 @@ row.setSpecies(speciesBatch.getSpecies()); row.setBatchWeightUnit(batchWeightUnit); - if (persistenceService.isVracBatch(speciesBatch)) { + if (!persistenceService.isVracBatch(speciesBatch)) { - // compute species total weight in catch + // for HV, always use a 1.0 raising factor + speciesCatchRaisingFactor = 1.f; + } - Float sortedBatchWeight = TuttiEntities.getValueOrComputedValue( - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight()); + Float batchWeight = TuttiEntities.getValueOrComputedValue( + speciesBatch.getSampleCategoryWeight(), + speciesBatch.getSampleCategoryComputedWeight()); - float totalBatchWeight = sortedBatchWeight == null ? 0 : speciesCatchRaisingFactor * - sortedBatchWeight; + float totalBatchWeight = batchWeight == null ? 0 : speciesCatchRaisingFactor * + batchWeight; - prepareSortedRows(persistenceService, - row, - rows, - speciesBatch, - totalBatchWeight); - } else { - prepareUnsortedRows(row, rows, speciesBatch); - } + prepareRows(persistenceService, + row, + rows, + speciesBatch, + totalBatchWeight); +// if (persistenceService.isVracBatch(speciesBatch)) { +// +// // compute species total weight in catch +// +// Float sortedBatchWeight = TuttiEntities.getValueOrComputedValue( +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight()); +// +// float totalBatchWeight = sortedBatchWeight == null ? 0 : speciesCatchRaisingFactor * +// sortedBatchWeight; +// +// prepareSortedRows(persistenceService, +// row, +// rows, +// speciesBatch, +// totalBatchWeight); +// } else { +// prepareUnsortedRows(row, rows, speciesBatch); +// } + } for (BenthosBatch benthosBatch : rootBenthosBatch.getChildren()) { CatchExportRow row = new CatchExportRow(); @@ -143,25 +162,44 @@ row.setSpecies(benthosBatch.getSpecies()); row.setBatchWeightUnit(batchWeightUnit); - if (persistenceService.isVracBatch(benthosBatch)) { + if (!persistenceService.isVracBatch(benthosBatch)) { - // compute species total weight in catch + // for HV, always use a 1.0 raising factor + benthosCatchRaisingFactor = 1.f; + } - Float sortedBatchWeight = TuttiEntities.getValueOrComputedValue( - benthosBatch.getSampleCategoryWeight(), - benthosBatch.getSampleCategoryComputedWeight()); + Float batchWeight = TuttiEntities.getValueOrComputedValue( + benthosBatch.getSampleCategoryWeight(), + benthosBatch.getSampleCategoryComputedWeight()); - float totalBatchWeight = sortedBatchWeight == null ? 0 : benthosCatchRaisingFactor * - sortedBatchWeight; + float totalBatchWeight = batchWeight == null ? 0 : benthosCatchRaisingFactor * + batchWeight; - prepareSortedRows(persistenceService, - row, - rows, - benthosBatch, - totalBatchWeight); - } else { - prepareUnsortedRows(row, rows, benthosBatch); - } + prepareRows(persistenceService, + row, + rows, + benthosBatch, + totalBatchWeight); + +// if (persistenceService.isVracBatch(benthosBatch)) { +// +// // compute species total weight in catch +// +// Float sortedBatchWeight = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight()); +// +// float totalBatchWeight = sortedBatchWeight == null ? 0 : benthosCatchRaisingFactor * +// sortedBatchWeight; +// +// prepareSortedRows(persistenceService, +// row, +// rows, +// benthosBatch, +// totalBatchWeight); +// } else { +// prepareUnsortedRows(row, rows, benthosBatch); +// } } // compute final raising factor @@ -188,11 +226,11 @@ } } - protected void prepareSortedRows(PersistenceService persistenceService, - CatchExportRow currentRow, - List<CatchExportRow> rows, - SpeciesBatch speciesBatch, - final float totalBatchWeight) { + protected void prepareRows(PersistenceService persistenceService, + CatchExportRow currentRow, + List<CatchExportRow> rows, + SpeciesBatch speciesBatch, + float totalBatchWeight) { currentRow.addComment(speciesBatch.getComment()); @@ -276,11 +314,11 @@ } else { for (SpeciesBatch childBatch : speciesBatch.getChildBatchs()) { - prepareSortedRows(persistenceService, - currentRow, - rows, - childBatch, - totalBatchWeight + prepareRows(persistenceService, + currentRow, + rows, + childBatch, + totalBatchWeight ); } } @@ -289,37 +327,12 @@ currentRow.popLastComment(); } - protected void prepareUnsortedRows(CatchExportRow currentRow, - List<CatchExportRow> rows, - SpeciesBatch speciesBatch) { - Integer number = TuttiEntities.getValueOrComputedValue(speciesBatch.getNumber(), - speciesBatch.getComputedNumber()); + protected void prepareRows(PersistenceService persistenceService, + CatchExportRow currentRow, + List<CatchExportRow> rows, + BenthosBatch benthosBatch, + final float totalBatchWeight) { - prepareBatch(currentRow, - speciesBatch.getSampleCategoryId(), - speciesBatch.getSampleCategoryValue(), - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight(), - speciesBatch.getWeight(), - number, - speciesBatch.getRankOrder()); - - CatchExportRow row = currentRow.copy(); - row.addComment(speciesBatch.getComment()); - float referenceWeight = TuttiEntities.getValueOrComputedValue( - speciesBatch.getSampleCategoryWeight(), - speciesBatch.getSampleCategoryComputedWeight()); - - setRaisingFactor(row, referenceWeight, referenceWeight); - rows.add(row); - } - - protected void prepareSortedRows(PersistenceService persistenceService, - CatchExportRow currentRow, - List<CatchExportRow> rows, - BenthosBatch benthosBatch, - final float totalBatchWeight) { - currentRow.addComment(benthosBatch.getComment()); Integer number = TuttiEntities.getValueOrComputedValue( @@ -404,11 +417,11 @@ } else { for (BenthosBatch childBatch : benthosBatch.getChildBatchs()) { - prepareSortedRows(persistenceService, - currentRow, - rows, - childBatch, - totalBatchWeight); + prepareRows(persistenceService, + currentRow, + rows, + childBatch, + totalBatchWeight); } } @@ -416,35 +429,263 @@ currentRow.popLastComment(); } - protected void prepareUnsortedRows(CatchExportRow currentRow, - List<CatchExportRow> rows, - BenthosBatch benthosBatch) { +// protected void prepareSortedRows(PersistenceService persistenceService, +// CatchExportRow currentRow, +// List<CatchExportRow> rows, +// SpeciesBatch speciesBatch, +// float totalBatchWeight) { +// +// currentRow.addComment(speciesBatch.getComment()); +// +// Integer number = TuttiEntities.getValueOrComputedValue(speciesBatch.getNumber(), +// speciesBatch.getComputedNumber()); +// prepareBatch(currentRow, +// speciesBatch.getSampleCategoryId(), +// speciesBatch.getSampleCategoryValue(), +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight(), +// speciesBatch.getWeight(), +// number, +// speciesBatch.getRankOrder()); +// +// if (speciesBatch.isChildBatchsEmpty()) { +// +// // on a leaf, get frequencies +// +// List<SpeciesBatchFrequency> speciesBatchFrequency = +// persistenceService.getAllSpeciesBatchFrequency(speciesBatch.getId()); +// +// if (CollectionUtils.isEmpty(speciesBatchFrequency)) { +// +// // no frequency +// +// CatchExportRow row = currentRow.copy(); +// +// // Get reference weight +// +// Float referenceWeight = TuttiEntities.getValueOrComputedValue( +// speciesBatch.getWeight(), +// speciesBatch.getComputedWeight()); +// +// if (referenceWeight == null) { +// +// referenceWeight = TuttiEntities.getValueOrComputedValue( +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight()); +// } +// setRaisingFactor(row, totalBatchWeight, referenceWeight); +// rows.add(row); +// } else { +// +// // there is some frequencies +// +// boolean withNoWeightOnFrequencies = +// speciesBatchFrequency.get(0).getWeight() == null; +// +// Float referenceWeight = null; +// +// if (withNoWeightOnFrequencies) { +// +// // no weight on frequencies use upper reference weight +// +// referenceWeight = TuttiEntities.getValueOrComputedValue( +// speciesBatch.getWeight(), +// speciesBatch.getComputedWeight()); +// +// if (referenceWeight == null) { +// referenceWeight = TuttiEntities.getValueOrComputedValue( +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight()); +// } +// } +// +// for (SpeciesBatchFrequency batchFrequency : speciesBatchFrequency) { +// CatchExportRow row = currentRow.copy(); +// row.setSpeciesFrequency(batchFrequency); +// rows.add(row); +// +// if (!withNoWeightOnFrequencies) { +// +// // use concrete frequency weight +// referenceWeight = batchFrequency.getWeight(); +// } +// +// setRaisingFactor(row, totalBatchWeight, referenceWeight); +// } +// } +// +// } else { +// +// for (SpeciesBatch childBatch : speciesBatch.getChildBatchs()) { +// prepareSortedRows(persistenceService, +// currentRow, +// rows, +// childBatch, +// totalBatchWeight +// ); +// } +// } +// +// // remove last comment (otherwise next brother will have this one too...) +// currentRow.popLastComment(); +// } - Integer number = TuttiEntities.getValueOrComputedValue( - benthosBatch.getNumber(), - benthosBatch.getComputedNumber()); +// protected void prepareUnsortedRows(CatchExportRow currentRow, +// List<CatchExportRow> rows, +// SpeciesBatch speciesBatch) { +// Integer number = TuttiEntities.getValueOrComputedValue(speciesBatch.getNumber(), +// speciesBatch.getComputedNumber()); +// +// prepareBatch(currentRow, +// speciesBatch.getSampleCategoryId(), +// speciesBatch.getSampleCategoryValue(), +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight(), +// speciesBatch.getWeight(), +// number, +// speciesBatch.getRankOrder()); +// +// CatchExportRow row = currentRow.copy(); +// row.addComment(speciesBatch.getComment()); +// float referenceWeight = TuttiEntities.getValueOrComputedValue( +// speciesBatch.getSampleCategoryWeight(), +// speciesBatch.getSampleCategoryComputedWeight()); +// +// setRaisingFactor(row, referenceWeight, referenceWeight); +// rows.add(row); +// } - prepareBatch(currentRow, - benthosBatch.getSampleCategoryId(), - benthosBatch.getSampleCategoryValue(), - benthosBatch.getSampleCategoryWeight(), - benthosBatch.getSampleCategoryComputedWeight(), - benthosBatch.getWeight(), - number, - benthosBatch.getRankOrder()); +// protected void prepareSortedRows(PersistenceService persistenceService, +// CatchExportRow currentRow, +// List<CatchExportRow> rows, +// BenthosBatch benthosBatch, +// final float totalBatchWeight) { +// +// currentRow.addComment(benthosBatch.getComment()); +// +// Integer number = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getNumber(), +// benthosBatch.getComputedNumber()); +// +// prepareBatch(currentRow, +// benthosBatch.getSampleCategoryId(), +// benthosBatch.getSampleCategoryValue(), +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight(), +// benthosBatch.getWeight(), +// number, +// benthosBatch.getRankOrder()); +// +// if (benthosBatch.isChildBatchsEmpty()) { +// +// // on a leaf, get frequencies +// +// List<BenthosBatchFrequency> benthosBatchFrequency = +// persistenceService.getAllBenthosBatchFrequency(benthosBatch.getId()); +// +// if (CollectionUtils.isEmpty(benthosBatchFrequency)) { +// +// // no frequency +// +// CatchExportRow row = currentRow.copy(); +// +// // Get reference weight +// +// Float referenceWeight = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getWeight(), +// benthosBatch.getComputedWeight()); +// +// if (referenceWeight == null) { +// referenceWeight = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight()); +// } +// +// setRaisingFactor(row, totalBatchWeight, referenceWeight); +// rows.add(row); +// } else { +// +// // there is some frequencies +// +// Float referenceWeight = null; +// +// boolean withNoWeightOnFrequencies = +// benthosBatchFrequency.get(0).getWeight() == null; +// +// if (withNoWeightOnFrequencies) { +// +// // no weight on frequencies use upper reference weight +// +// referenceWeight = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getWeight(), +// benthosBatch.getComputedWeight()); +// +// if (referenceWeight == null) { +// referenceWeight = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight()); +// } +// } +// +// for (BenthosBatchFrequency batchFrequency : benthosBatchFrequency) { +// CatchExportRow row = currentRow.copy(); +// row.setBenthosFrequency(batchFrequency); +// rows.add(row); +// +// if (!withNoWeightOnFrequencies) { +// +// // use concrete frequency weight +// referenceWeight = batchFrequency.getWeight(); +// } +// +// setRaisingFactor(row, totalBatchWeight, referenceWeight); +// } +// } +// +// } else { +// +// for (BenthosBatch childBatch : benthosBatch.getChildBatchs()) { +// prepareSortedRows(persistenceService, +// currentRow, +// rows, +// childBatch, +// totalBatchWeight); +// } +// } +// +// // remove last comment (otherwise next brother will have this one too...) +// currentRow.popLastComment(); +// } +// +// protected void prepareUnsortedRows(CatchExportRow currentRow, +// List<CatchExportRow> rows, +// BenthosBatch benthosBatch) { +// +// Integer number = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getNumber(), +// benthosBatch.getComputedNumber()); +// +// prepareBatch(currentRow, +// benthosBatch.getSampleCategoryId(), +// benthosBatch.getSampleCategoryValue(), +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight(), +// benthosBatch.getWeight(), +// number, +// benthosBatch.getRankOrder()); +// +// CatchExportRow row = currentRow.copy(); +// row.addComment(benthosBatch.getComment()); +// +// Float referenceWeight = TuttiEntities.getValueOrComputedValue( +// benthosBatch.getSampleCategoryWeight(), +// benthosBatch.getSampleCategoryComputedWeight()); +// +// setRaisingFactor(row, referenceWeight, referenceWeight); +// +// rows.add(row); +// } - CatchExportRow row = currentRow.copy(); - row.addComment(benthosBatch.getComment()); - - Float referenceWeight = TuttiEntities.getValueOrComputedValue( - benthosBatch.getSampleCategoryWeight(), - benthosBatch.getSampleCategoryComputedWeight()); - - setRaisingFactor(row, referenceWeight, referenceWeight); - - rows.add(row); - } - protected void setRaisingFactor(CatchExportRow row, float totalBatchWeight, Float referenceWeight) { @@ -463,7 +704,7 @@ currentRow.setBatchNumber(batchNumber); ExportSampleCategory<Serializable> sampleCategory = - new ExportSampleCategory<Serializable>(); + new ExportSampleCategory<>(); SampleCategoryModelEntry categoryById = sampleCategoryModel.getCategoryById(sampleCategoryId); sampleCategory.setCategoryDef(categoryById);