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 2e3fee3260ccc887bdbb20c5b120e43486b8ec62 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 18:21:59 2015 +0100 all pj imports wokrs now --- .../genericformat/GenericFormatContextSupport.java | 9 ++--- .../GenericFormatImportOperationContext.java | 15 +++++++++ .../GenericformatImportPersitenceHelper.java | 38 +++++++++++++++------- .../consumer/CsvConsumerForCatch.java | 12 ++++--- .../service/genericformat/csv/CatchModel.java | 4 +-- .../genericformat/csv/ExportSampleCategory.java | 6 ++-- .../importactions/ImportOperationAction.java | 5 +-- .../importactions/ImportSurveyAction.java | 3 +- .../importactions/LoadAttachmentsAction.java | 4 +-- 9 files changed, 66 insertions(+), 30 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java index 1a3f675..761e4c3 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatContextSupport.java @@ -28,6 +28,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; +import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; @@ -134,7 +135,7 @@ public abstract class GenericFormatContextSupport implements Closeable { private String protocolOriginalName; - private final Multimap<Integer, AttachmentRow> attachmentRows; + private final Multimap<String, AttachmentRow> attachmentRows; protected abstract void onClose(); @@ -556,12 +557,12 @@ public abstract class GenericFormatContextSupport implements Closeable { this.protocolOriginalName = protocolOriginalName; } - public void setAttachmentRows(Multimap<Integer, AttachmentRow> attachmentRows) { + public void setAttachmentRows(Multimap<String, AttachmentRow> attachmentRows) { this.attachmentRows.putAll(attachmentRows); } - public Collection<AttachmentRow> popAttachmentRows(Integer objectId) { - Collection<AttachmentRow> result = objectId==null?null:attachmentRows.removeAll(objectId); + public Collection<AttachmentRow> popAttachmentRows(ObjectTypeCode objectTypeCode, Integer objectId) { + Collection<AttachmentRow> result = objectId == null ? null : attachmentRows.removeAll(objectTypeCode + "_" + objectId); return result; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java index 2bc3a79..fad1a64 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportOperationContext.java @@ -88,6 +88,8 @@ public class GenericFormatImportOperationContext implements Closeable { private final Map<Integer, BenthosBatch> horsVracBenthosBatches; + private final Map<Integer, Integer> batchesObjectIds; + private final ArrayListMultimap<Integer, BenthosBatchFrequency> benthosFrequencies; private final CaracteristicMap gearUseFeatures; @@ -115,6 +117,7 @@ public class GenericFormatImportOperationContext implements Closeable { this.gearUseFeatures = new CaracteristicMap(); this.vesselUseFeatures = new CaracteristicMap(); this.checkErrors = new LinkedHashSet<>(); + this.batchesObjectIds = new TreeMap<>(); } public FishingOperation getFishingOperation() { @@ -277,5 +280,17 @@ public class GenericFormatImportOperationContext implements Closeable { horsVracSpeciesBatches.clear(); } + + public void registerBatchObjectId(Integer batchId, Integer objectId) { + if (objectId != null) { + batchesObjectIds.put(batchId, objectId); + } + } + + public Integer getBatchObjectId(Integer batchId) { + return batchesObjectIds.get(batchId); + } + + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersitenceHelper.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersitenceHelper.java index acecefc..f33606a 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersitenceHelper.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericformatImportPersitenceHelper.java @@ -125,7 +125,6 @@ public class GenericformatImportPersitenceHelper { } if (CollectionUtils.isNotEmpty(attachmentRows)) { - persistAttachments(savedCruise.getIdAsInt(), attachmentRows); } importContext.addImportedCruise(savedCruise, !createCruise); @@ -291,12 +290,21 @@ public class GenericformatImportPersitenceHelper { for (SpeciesBatch batch : batches) { + Integer batchObjectId = fishingOperationContext.getBatchObjectId(batch.getIdAsInt()); + List<SpeciesBatchFrequency> frequencies = fishingOperationContext.getSpeciesFrequencies(batch); // reset temporary id to persist batch batch.setId((Integer) null); SpeciesBatch createdBatch = persistenceService.createSpeciesBatch(batch, parentId); + if (batchObjectId != null) { + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(ObjectTypeCode.BATCH, batchObjectId); + if (CollectionUtils.isNotEmpty(attachmentRows)) { + persistAttachments(createdBatch.getIdAsInt(), attachmentRows); + } + } + if (CollectionUtils.isNotEmpty(frequencies)) { String batchId = batch.getId(); @@ -363,6 +371,8 @@ public class GenericformatImportPersitenceHelper { for (BenthosBatch batch : batches) { + Integer batchObjectId = fishingOperationContext.getBatchObjectId(batch.getIdAsInt()); + List<BenthosBatchFrequency> frequencies = fishingOperationContext.getBenthosFrequencies(batch); // reset temporary id to persist batch @@ -370,6 +380,13 @@ public class GenericformatImportPersitenceHelper { BenthosBatch createdBatch = persistenceService.createBenthosBatch(batch, parentId); + if (batchObjectId != null) { + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(ObjectTypeCode.BATCH, batchObjectId); + if (CollectionUtils.isNotEmpty(attachmentRows)) { + persistAttachments(createdBatch.getIdAsInt(), attachmentRows); + } + } + if (CollectionUtils.isNotEmpty(frequencies)) { String batchId = batch.getId(); @@ -420,14 +437,14 @@ public class GenericformatImportPersitenceHelper { for (MarineLitterBatch marineLitterBatch : marineLitterBatches) { Integer objectId = marineLitterBatch.getIdAsInt(); - Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(objectId); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(ObjectTypeCode.BATCH, objectId); // Id was only here to get attachments marineLitterBatch.setId((String) null); - persistenceService.createMarineLitterBatch(marineLitterBatch); + MarineLitterBatch createdMarineLitterBatch = persistenceService.createMarineLitterBatch(marineLitterBatch); + persistAttachments(createdMarineLitterBatch.getIdAsInt(), attachmentRows); - persistAttachments(objectId, attachmentRows); } } @@ -466,14 +483,14 @@ public class GenericformatImportPersitenceHelper { for (IndividualObservationBatch individualObservationBatch : individualObservationBatches) { Integer objectId = individualObservationBatch.getIdAsInt(); - Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(objectId); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(ObjectTypeCode.SAMPLE,objectId); // Id was only here to get attachments individualObservationBatch.setId((String) null); - persistenceService.createIndividualObservationBatch(individualObservationBatch); + IndividualObservationBatch createdIndividualObservationBatch = persistenceService.createIndividualObservationBatch(individualObservationBatch); + persistAttachments(createdIndividualObservationBatch.getIdAsInt(), attachmentRows); - persistAttachments(objectId, attachmentRows); } } @@ -511,14 +528,13 @@ public class GenericformatImportPersitenceHelper { for (AccidentalBatch accidentalBatch : accidentalBatches) { Integer objectId = accidentalBatch.getIdAsInt(); - Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(objectId); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(ObjectTypeCode.SAMPLE, objectId); // Id was only here to get attachments accidentalBatch.setId((String) null); - persistenceService.createAccidentalBatch(accidentalBatch); - - persistAttachments(objectId, attachmentRows); + AccidentalBatch createdAccidentalBatch = persistenceService.createAccidentalBatch(accidentalBatch); + persistAttachments(createdAccidentalBatch.getIdAsInt(), attachmentRows); } 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 2ffdb69..6390ed4 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 @@ -166,7 +166,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } - batch = fillBatchCategories(batch, bean); + batch = fillBatchCategories(operationContext, batch, bean); if (withFrequency) { @@ -214,7 +214,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } - batch = fillBatchCategories(batch, bean); + batch = fillBatchCategories(operationContext, batch, bean); if (withFrequency) { @@ -239,17 +239,17 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { } - protected <A extends SpeciesAbleBatch> A fillBatchCategories(A batch, CatchRow bean) { + protected <A extends SpeciesAbleBatch> A fillBatchCategories(GenericFormatImportOperationContext operationContext,A batch, CatchRow bean) { for (ExportSampleCategory exportSampleCategory : bean.getFilledSampleCategories()) { - batch = fillBatchCategories(batch, exportSampleCategory); + batch = fillBatchCategories(operationContext, batch, exportSampleCategory); } return batch; } - protected <A extends SpeciesAbleBatch> A fillBatchCategories(A batch, ExportSampleCategory sampleCategory) { + protected <A extends SpeciesAbleBatch> A fillBatchCategories(GenericFormatImportOperationContext operationContext,A batch, ExportSampleCategory sampleCategory) { A result = null; @@ -260,6 +260,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { batch.setSampleCategoryValue(sampleCategory.getCategoryValue()); batch.setSampleCategoryWeight(sampleCategory.getCategoryWeight()); result = batch; + operationContext.registerBatchObjectId(batch.getIdAsInt(), sampleCategory.getBatchId()); } else { @@ -292,6 +293,7 @@ public class CsvConsumerForCatch extends CsvComsumer<CatchRow, CatchModel> { result.setSampleCategoryId(sampleCategory.getCategoryId()); result.setSampleCategoryValue(sampleCategory.getCategoryValue()); result.setSampleCategoryWeight(sampleCategory.getCategoryWeight()); + operationContext.registerBatchObjectId(batch.getIdAsInt(), sampleCategory.getBatchId()); 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/CatchModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/CatchModel.java index ba3e88e..e97c7ff 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 @@ -131,7 +131,7 @@ public class CatchModel extends AbstractTuttiImportExportModel<CatchRow> { String collectionName = CatchRow.SAMPLE_CATEGORY; newIndexNullableColumnForExport(headerPrefix + "_Id", collectionName, categoryOrder, ExportSampleCategory.PROPERTY_CATEGORY_VALUE, TuttiCsvUtil.CARACTERISTIC_VALUE_TECHNICAL_FORMATTER); - newIndexNullableColumnForExport(headerPrefix + "_Lot_Id", collectionName, categoryOrder, ExportSampleCategory.PROPERTY_BATCH_ID); + newIndexNullableColumnForExport(headerPrefix + "_Lot_Id", collectionName, categoryOrder, ExportSampleCategory.PROPERTY_BATCH_ID, TuttiCsvUtil.INTEGER); } @@ -188,7 +188,7 @@ public class CatchModel extends AbstractTuttiImportExportModel<CatchRow> { String headerPrefix = entry.getCode(); newMandatoryColumn(headerPrefix + "_Id", CaracteristicValueParserFormatter.newParser(entry.getCaracteristic()), new SampleCategoryValueSetter<Serializable>(entry, ExportSampleCategory.PROPERTY_CATEGORY_VALUE)); - newMandatoryColumn(headerPrefix + "_Lot_Id", new SampleCategoryValueSetter<String>(entry, ExportSampleCategory.PROPERTY_BATCH_ID)); + newMandatoryColumn(headerPrefix + "_Lot_Id", TuttiCsvUtil.INTEGER, new SampleCategoryValueSetter<Integer>(entry, ExportSampleCategory.PROPERTY_BATCH_ID)); } } 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 f84d0b8..d2040d8 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 @@ -54,7 +54,7 @@ public class ExportSampleCategory<S extends Serializable> extends SampleCategory public static final java.lang.String PROPERTY_BATCH_ID = "batchId"; - private String batchId; + private Integer batchId; private Integer rankOrder; @@ -68,11 +68,11 @@ public class ExportSampleCategory<S extends Serializable> extends SampleCategory return weightOrVolType; } - public String getBatchId() { + public Integer getBatchId() { return batchId; } - public void setBatchId(String batchId) { + public void setBatchId(Integer batchId) { this.batchId = batchId; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportOperationAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportOperationAction.java index 8bfec11..d36008a 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportOperationAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportOperationAction.java @@ -24,6 +24,7 @@ package fr.ifremer.tutti.service.genericformat.importactions; * #L% */ +import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.service.genericformat.GenericFormatCsvFileResult; @@ -83,8 +84,8 @@ public class ImportOperationAction extends ImportActionSupport { OperationRow bean = row.getBean(); - Collection<AttachmentRow> operationAttachmentRows = importContext.popAttachmentRows(bean.getFishingOperationObjectId()); - Collection<AttachmentRow> catchAttachmentRows = importContext.popAttachmentRows(bean.getCatchObjectId()); + Collection<AttachmentRow> operationAttachmentRows = importContext.popAttachmentRows(ObjectTypeCode.OPERATION, bean.getFishingOperationObjectId()); + Collection<AttachmentRow> catchAttachmentRows = importContext.popAttachmentRows(ObjectTypeCode.CATCH_BATCH, bean.getCatchObjectId()); FishingOperation fishingOperation = bean.getFishingOperation(); CatchBatch catchBatch = bean.getCatchBatch(); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportSurveyAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportSurveyAction.java index 84a737b..8739887 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportSurveyAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/ImportSurveyAction.java @@ -24,6 +24,7 @@ package fr.ifremer.tutti.service.genericformat.importactions; * #L% */ +import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.service.genericformat.GenericFormatCsvFileResult; import fr.ifremer.tutti.service.genericformat.GenericFormatImportContext; import fr.ifremer.tutti.service.genericformat.GenericformatImportPersitenceHelper; @@ -82,7 +83,7 @@ public class ImportSurveyAction extends ImportActionSupport { consumer.prepareRowForPersist(row); SurveyRow bean = row.getBean(); - Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(bean.getObjectId()); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(ObjectTypeCode.SCIENTIFIC_CRUISE, bean.getObjectId()); persitenceHelper.persistCruise(bean.getCruise(), attachmentRows); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/LoadAttachmentsAction.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/LoadAttachmentsAction.java index 1d81fcc..3640688 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/LoadAttachmentsAction.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/LoadAttachmentsAction.java @@ -48,7 +48,7 @@ public class LoadAttachmentsAction extends ImportActionSupport { GenericFormatCsvFileResult importFileResult = importContext.getAttachmentFileResult(); try (CsvConsumerForAttachment consumer = importContext.loadAttachments(false)) { - Multimap<Integer, AttachmentRow> attachmentRowsByObjectId = ArrayListMultimap.create(); + Multimap<String, AttachmentRow> attachmentRowsByObjectId = ArrayListMultimap.create(); for (ImportRow<AttachmentRow> row : consumer) { @@ -57,7 +57,7 @@ public class LoadAttachmentsAction extends ImportActionSupport { if (row.isValid()) { AttachmentRow bean = row.getBean(); - attachmentRowsByObjectId.put(bean.getObjectId(), bean); + attachmentRowsByObjectId.put(bean.getObjectType() + "_" + bean.getObjectId(), bean); } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.