r1682 - trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic
Author: tchemit Date: 2014-04-09 10:08:54 +0200 (Wed, 09 Apr 2014) New Revision: 1682 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1682 Log: fixes #4904 [EXPORT GENERIQUE] Les cat?\195?\169gorisations ne sont pas bien export?\195?\169es (table catch) 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/CatchExportRow.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-31 08:18:54 UTC (rev 1681) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportModel.java 2014-04-09 08:08:54 UTC (rev 1682) @@ -77,7 +77,16 @@ newColumnForExport("Commentaire", SpeciesBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_FORMATTER); for (SampleCategoryModelEntry entry : sampleCategoryModel.getCategory()) { - addSampleCategory(entry.getCanonicalLabel(), entry.getOrder()); + + String headerPrefix = entry.getCanonicalLabel(); + int categoryOrder = entry.getOrder(); + String categoryName = CatchExportRow.SAMPLE_CATEGORY; + newIndexNullableColumnForExport(headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_CATEGORY_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_FORMATTER); + newIndexNullableColumnForExport("Num_Ordre_" + headerPrefix + "_H2", categoryName, categoryOrder, ExportSampleCategory.PROPERTY_RANK_ORDER, TuttiCsvUtil.INTEGER); + newIndexNullableColumnForExport("Tot_" + headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_CATEGORY_WEIGHT, TuttiCsvUtil.FLOAT); + newIndexNullableColumnForExport("Ech_" + headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_SAMPLE_WEIGHT, TuttiCsvUtil.FLOAT); + newIndexNullableColumnForExport("Type_Volume_Poids_" + headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_WEIGHT_OR_VOL_TYPE); + newNullableColumnForExport("Unite_Volume_Poids_" + headerPrefix, CatchExportRow.BATCH_WEIGHT_UNIT); } // mensuration @@ -128,33 +137,13 @@ float totalBatchWeight = batchWeight == null ? 0 : speciesCatchRaisingFactor * batchWeight; - 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); -// } - + addSpeciesBatch(persistenceService, + row, + rows, + speciesBatch, + totalBatchWeight); } + for (BenthosBatch benthosBatch : rootBenthosBatch.getChildren()) { CatchExportRow row = new CatchExportRow(); row.setCruise(cruise); @@ -175,31 +164,11 @@ float totalBatchWeight = batchWeight == null ? 0 : benthosCatchRaisingFactor * batchWeight; - 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); -// } + addBenthosBatch(persistenceService, + row, + rows, + benthosBatch, + totalBatchWeight); } // compute final raising factor @@ -226,24 +195,24 @@ } } - protected void prepareRows(PersistenceService persistenceService, - CatchExportRow currentRow, - List<CatchExportRow> rows, - SpeciesBatch speciesBatch, - float totalBatchWeight) { + protected void addSpeciesBatch(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()); + addBatchSampleCategory(currentRow, + speciesBatch.getSampleCategoryId(), + speciesBatch.getSampleCategoryValue(), + speciesBatch.getSampleCategoryWeight(), + speciesBatch.getSampleCategoryComputedWeight(), + speciesBatch.getWeight(), + number, + speciesBatch.getRankOrder()); if (speciesBatch.isChildBatchsEmpty()) { @@ -314,24 +283,23 @@ } else { for (SpeciesBatch childBatch : speciesBatch.getChildBatchs()) { - prepareRows(persistenceService, - currentRow, - rows, - childBatch, - totalBatchWeight + // always use a copy, otherwise sample categories can be shared by brothers + CatchExportRow childRow = currentRow.copy(); + addSpeciesBatch(persistenceService, + childRow, + rows, + childBatch, + totalBatchWeight ); } } - - // remove last comment (otherwise next brother will have this one too...) - currentRow.popLastComment(); } - protected void prepareRows(PersistenceService persistenceService, - CatchExportRow currentRow, - List<CatchExportRow> rows, - BenthosBatch benthosBatch, - final float totalBatchWeight) { + protected void addBenthosBatch(PersistenceService persistenceService, + CatchExportRow currentRow, + List<CatchExportRow> rows, + BenthosBatch benthosBatch, + final float totalBatchWeight) { currentRow.addComment(benthosBatch.getComment()); @@ -339,14 +307,14 @@ benthosBatch.getNumber(), benthosBatch.getComputedNumber()); - prepareBatch(currentRow, - benthosBatch.getSampleCategoryId(), - benthosBatch.getSampleCategoryValue(), - benthosBatch.getSampleCategoryWeight(), - benthosBatch.getSampleCategoryComputedWeight(), - benthosBatch.getWeight(), - number, - benthosBatch.getRankOrder()); + addBatchSampleCategory(currentRow, + benthosBatch.getSampleCategoryId(), + benthosBatch.getSampleCategoryValue(), + benthosBatch.getSampleCategoryWeight(), + benthosBatch.getSampleCategoryComputedWeight(), + benthosBatch.getWeight(), + number, + benthosBatch.getRankOrder()); if (benthosBatch.isChildBatchsEmpty()) { @@ -417,275 +385,17 @@ } else { for (BenthosBatch childBatch : benthosBatch.getChildBatchs()) { - prepareRows(persistenceService, - currentRow, - rows, - childBatch, - totalBatchWeight); + // always use a copy, otherwise sample categories can be shared by brothers + CatchExportRow childRow = currentRow.copy(); + addBenthosBatch(persistenceService, + childRow, + rows, + childBatch, + totalBatchWeight); } } - - // remove last comment (otherwise next brother will have this one too...) - currentRow.popLastComment(); } -// 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(); -// } - -// 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); -// } - -// 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); -// } - protected void setRaisingFactor(CatchExportRow row, float totalBatchWeight, Float referenceWeight) { @@ -693,14 +403,14 @@ row.setRaisingFactor(referenceWeight == null ? 1.0f : (totalBatchWeight / referenceWeight)); } - protected void prepareBatch(CatchExportRow currentRow, - Integer sampleCategoryId, - Serializable sampleCategoryValue, - Float sampleCategoryWeight, - Float sampleCategoryComputedWeight, - Float batchWeight, - Integer batchNumber, - Integer batchRankOrder) { + protected void addBatchSampleCategory(CatchExportRow currentRow, + Integer sampleCategoryId, + Serializable sampleCategoryValue, + Float sampleCategoryWeight, + Float sampleCategoryComputedWeight, + Float batchWeight, + Integer batchNumber, + Integer batchRankOrder) { currentRow.setBatchNumber(batchNumber); ExportSampleCategory<Serializable> sampleCategory = @@ -718,16 +428,4 @@ currentRow.addSampleCategory(sampleCategory); } - - protected void addSampleCategory(String headerPrefix, int categoryOrder) { - - String categoryName = CatchExportRow.SAMPLE_CATEGORY; - newIndexNullableColumnForExport(headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_CATEGORY_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_FORMATTER); - newIndexNullableColumnForExport("Num_Ordre_" + headerPrefix + "_H2", categoryName, categoryOrder, ExportSampleCategory.PROPERTY_RANK_ORDER, TuttiCsvUtil.INTEGER); - newIndexNullableColumnForExport("Tot_" + headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_CATEGORY_WEIGHT, TuttiCsvUtil.FLOAT); - newIndexNullableColumnForExport("Ech_" + headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_SAMPLE_WEIGHT, TuttiCsvUtil.FLOAT); - newIndexNullableColumnForExport("Type_Volume_Poids_" + headerPrefix, categoryName, categoryOrder, ExportSampleCategory.PROPERTY_WEIGHT_OR_VOL_TYPE); - newNullableColumnForExport("Unite_Volume_Poids_" + headerPrefix, CatchExportRow.BATCH_WEIGHT_UNIT); - } - } \ No newline at end of file Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportRow.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportRow.java 2014-03-31 08:18:54 UTC (rev 1681) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/export/generic/CatchExportRow.java 2014-04-09 08:08:54 UTC (rev 1682) @@ -26,7 +26,6 @@ import com.google.common.base.Joiner; import com.google.common.base.Preconditions; -import com.google.common.collect.Lists; import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; @@ -40,6 +39,7 @@ import org.apache.commons.logging.LogFactory; import java.io.Serializable; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -82,7 +82,7 @@ protected FishingOperation fishingOperation; - protected final List<ExportSampleCategory> sampleCategory = Lists.newLinkedList(); + protected final List<ExportSampleCategory> sampleCategory = new ArrayList<>(); protected SpeciesBatchFrequency speciesFrequency; @@ -100,7 +100,7 @@ protected String batchWeightUnit; - protected final List<String> comment = Lists.newArrayList(); + protected final List<String> comment = new ArrayList<>(); public void setCruise(Cruise cruise) { this.cruise = cruise; @@ -249,12 +249,6 @@ this.comment.add(safeComment); } - public void popLastComment() { - if (!comment.isEmpty()) { - this.comment.remove(this.comment.size() - 1); - } - } - public String getComment() { String result; if (comment.isEmpty()) {
participants (1)
-
tchemit@users.forge.codelutin.com