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 dc0722c74082427d6ff2bea837e7ae62d97a4bf4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 26 19:15:06 2015 +0100 refs #6819: ajout des pièces jointes dans l'export --- .../genericformat/GenericFormatArchive.java | 11 +- .../genericformat/GenericFormatExportContext.java | 77 +++++++++++- .../GenericFormatExportOperationContext.java | 11 ++ .../genericformat/GenericFormatExportService.java | 37 +++--- .../service/genericformat/csv/AttachmentModel.java | 65 ++++++++++ .../service/genericformat/csv/AttachmentRow.java | 74 +++++++++++ .../service/genericformat/csv/CatchModel.java | 3 +- .../genericformat/csv/ExportSampleCategory.java | 12 ++ .../genericformat/csv/MarineLitterModel.java | 2 + .../service/genericformat/csv/MarineLitterRow.java | 10 ++ .../service/genericformat/csv/OperationModel.java | 4 + .../service/genericformat/csv/OperationRow.java | 20 +++ .../service/genericformat/csv/SurveyModel.java | 2 + .../tutti/service/genericformat/csv/SurveyRow.java | 8 ++ .../producer/CsvProducerForAttachment.java | 139 +++++++++++++++++++++ .../producer/CsvProducerForCatch.java | 7 +- 16 files changed, 458 insertions(+), 24 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java index ec64277..356fd27 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatArchive.java @@ -84,7 +84,8 @@ public class GenericFormatArchive implements Serializable { DATA_SPECIES(false, "species.csv"), DATA_MARINE_LITTER(true, "marineLitter.csv"), DATA_ACCIDENTAL_CATCH(true, "accidentalCatch.csv"), - DATA_INDIVIDUAL_OBSERVATION(true, "individualObservation.csv"); + DATA_INDIVIDUAL_OBSERVATION(true, "individualObservation.csv"), + DATA_ATTACHMENTS(true, "attachments.csv") ; private final boolean mandatory; @@ -160,6 +161,14 @@ public class GenericFormatArchive implements Serializable { return getPath(ArchiveFilePath.SAMPLE_CATEGORY); } + public Path getAttachmentFilePath() { + return getPath(ArchiveFilePath.DATA_ATTACHMENTS); + } + + public Path getAttachmentDataPath() { + return workingDirectory.toPath().resolve("meas_files"); + } + public boolean isProtocolExists() { return Files.exists(getProtocolPath()); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java index 2c2510a..25461b3 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportContext.java @@ -26,16 +26,25 @@ package fr.ifremer.tutti.service.genericformat; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; +import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.ProgressionModel; +import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; +import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Speciess; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.service.genericformat.csv.AccidentalCatchModel; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentModel; import fr.ifremer.tutti.service.genericformat.csv.CatchModel; import fr.ifremer.tutti.service.genericformat.csv.GearCaracteristicModel; import fr.ifremer.tutti.service.genericformat.csv.IndividualObservationModel; @@ -45,6 +54,7 @@ import fr.ifremer.tutti.service.genericformat.csv.ParameterModel; import fr.ifremer.tutti.service.genericformat.csv.SpeciesExportModel; import fr.ifremer.tutti.service.genericformat.csv.SurveyModel; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForAccidentalCatch; +import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForAttachment; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForCatch; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForGearCaracteristics; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForIndividualObservation; @@ -65,6 +75,7 @@ import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.Closeable; import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -126,6 +137,8 @@ public class GenericFormatExportContext implements Closeable { private final CsvProducerForSampleCategory producerForSampleCategory; + private final CsvProducerForAttachment producerForAttachment; + protected final ProgressionModel progressionModel; protected String checkError; @@ -140,7 +153,8 @@ public class GenericFormatExportContext implements Closeable { PersistenceService persistenceService, WeightComputingService weightComputingService, Decorator<FishingOperation> fishingOperationDecorator, - SampleCategoryModel sampleCategoryModel) { + SampleCategoryModel sampleCategoryModel, + Path attachmentSourcePath) { Preconditions.checkNotNull(progressionModel); this.progressionModel = progressionModel; @@ -171,6 +185,7 @@ public class GenericFormatExportContext implements Closeable { this.producerForParameter = new CsvProducerForParameter(archive.getParameterPath(), ParameterModel.forExport(csvSeparator)); this.producerForMarineLitter = new CsvProducerForMarineLitter(archive.getMarineLitterPath(), MarineLitterModel.forExport(csvSeparator)); this.producerForSampleCategory = new CsvProducerForSampleCategory(archive.getSampleCategoryModelPath(), fr.ifremer.tutti.service.genericformat.csv.SampleCategoryModel.forExport(csvSeparator)); + this.producerForAttachment = new CsvProducerForAttachment(archive.getAttachmentFilePath(), AttachmentModel.forExport(csvSeparator), attachmentSourcePath, archive.getAttachmentDataPath()); this.producerForTemporaryGear = new CsvProducerForTemporaryGear(archive.getTemporaryReferentialGearsPath(), csvSeparator); this.producerForTemporaryPerson = new CsvProducerForTemporaryPerson(archive.getTemporaryReferentialPersonsPath(), csvSeparator); @@ -245,6 +260,7 @@ public class GenericFormatExportContext implements Closeable { producerForIndividualObservation.writeEmpty(); producerForCatch.writeEmpty(); producerForMarineLitter.writeEmpty(); + producerForAttachment.writeEmpty(); } catch (Exception e) { throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.operations.error"), e); @@ -267,6 +283,7 @@ public class GenericFormatExportContext implements Closeable { IOUtils.closeQuietly(producerForTemporarySpecies); IOUtils.closeQuietly(producerForTemporaryVessel); IOUtils.closeQuietly(producerForSampleCategory); + IOUtils.closeQuietly(producerForAttachment); } @@ -336,6 +353,10 @@ public class GenericFormatExportContext implements Closeable { return producerForSampleCategory; } + public CsvProducerForAttachment getProducerForAttachment() { + return producerForAttachment; + } + public File getProtocolFile() { return archive.getProtocolPath().toFile(); } @@ -363,4 +384,58 @@ public class GenericFormatExportContext implements Closeable { public boolean isOperationExported() { return operationExported; } + + public List<Attachment> getAttachements(Cruise cruise) { + return persistenceService.getAllAttachments(ObjectTypeCode.SCIENTIFIC_CRUISE, cruise.getIdAsInt()); + } + + public List<Attachment> getAttachements(FishingOperation fishingOperation) { + return persistenceService.getAllAttachments(ObjectTypeCode.OPERATION, fishingOperation.getIdAsInt()); + } + + public List<Attachment> getAttachements(CatchBatch catchBatch) { + return persistenceService.getAllAttachments(ObjectTypeCode.CATCH_BATCH, catchBatch.getIdAsInt()); + } + + public List<Attachment> getAttachements(MarineLitterBatch marineLitterBatch) { + return persistenceService.getAllAttachments(ObjectTypeCode.BATCH, marineLitterBatch.getIdAsInt()); + } + + public List<Attachment> getAttachements(SpeciesBatch speciesBatch) { + return persistenceService.getAllAttachments(ObjectTypeCode.BATCH, speciesBatch.getIdAsInt()); + } + + public List<Attachment> getAttachements(BenthosBatch benthosBatch) { + return persistenceService.getAllAttachments(ObjectTypeCode.BATCH, benthosBatch.getIdAsInt()); + } + + public List<Attachment> getAttachements(IndividualObservationBatch individualObservations) { + return persistenceService.getAllAttachments(ObjectTypeCode.SAMPLE, individualObservations.getIdAsInt()); + } + + public List<Attachment> getAttachements(AccidentalBatch accidentalBatch) { + return persistenceService.getAllAttachments(ObjectTypeCode.SAMPLE, accidentalBatch.getIdAsInt()); + } + + public void write(GenericFormatExportOperationContext operationContext) { + + try { + + getProducerForOperation().write(operationContext.getOperationRow()); + getProducerForParameter().write(operationContext.getParameterRows()); + getProducerForMarineLitter().write(operationContext.getMarineLitterRows()); + getProducerForIndividualObservation().write(operationContext.getIndividualObservationRows()); + getProducerForAccidentalCatch().write(operationContext.getAccidentalCatchRows()); + getProducerForCatch().write(operationContext.getCatchRows()); + getProducerForAttachment().write(operationContext.getAttachmentRows()); + + + } catch (Exception e) { + + throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.operation.error", operationContext.getOperationLabel(), operationContext.getCruise().getName()), e); + + } + + + } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java index df8a1b6..97b74bd 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportOperationContext.java @@ -41,6 +41,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.service.genericformat.csv.AccidentalCatchRow; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; import fr.ifremer.tutti.service.genericformat.csv.CatchRow; import fr.ifremer.tutti.service.genericformat.csv.IndividualObservationRow; import fr.ifremer.tutti.service.genericformat.csv.MarineLitterRow; @@ -106,6 +107,8 @@ public class GenericFormatExportOperationContext { private List<CatchRow> catchRows; + private List<AttachmentRow> attachmentRows; + public GenericFormatExportOperationContext(Cruise cruise, FishingOperation operation, String operationLabel, @@ -301,4 +304,12 @@ public class GenericFormatExportOperationContext { public List<CatchRow> getCatchRows() { return catchRows; } + + public List<AttachmentRow> getAttachmentRows() { + return attachmentRows; + } + + public void setAttachmentRows(List<AttachmentRow> attachmentRows) { + this.attachmentRows = attachmentRows; + } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java index 59b9b63..bb0b0de 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatExportService.java @@ -44,6 +44,7 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.service.genericformat.csv.AccidentalCatchRow; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; import fr.ifremer.tutti.service.genericformat.csv.CatchRow; import fr.ifremer.tutti.service.genericformat.csv.GearCaracteristicRow; import fr.ifremer.tutti.service.genericformat.csv.IndividualObservationRow; @@ -53,6 +54,7 @@ import fr.ifremer.tutti.service.genericformat.csv.ParameterRow; import fr.ifremer.tutti.service.genericformat.csv.SampleCategoryRow; import fr.ifremer.tutti.service.genericformat.csv.SpeciesExportRow; import fr.ifremer.tutti.service.genericformat.csv.SurveyRow; +import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForAttachment; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForCatch; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForGearCaracteristics; import fr.ifremer.tutti.service.genericformat.producer.CsvProducerForSampleCategory; @@ -75,6 +77,7 @@ import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collection; @@ -315,13 +318,16 @@ public class GenericFormatExportService extends GenericFormatServiceSupport { protected GenericFormatExportContext createExportContext(ProgressionModel progressionModel, GenericFormatArchive genericFormatArchive) { + Path attachmentsSourcePath = context.getConfig().getDbAttachmentDirectory().toPath(); + return new GenericFormatExportContext(progressionModel, genericFormatArchive, ';', persistenceService, weightComputingService, fishingOperationDecorator, - context.getSampleCategoryModel()); + context.getSampleCategoryModel(), + attachmentsSourcePath); } @@ -487,7 +493,7 @@ public class GenericFormatExportService extends GenericFormatServiceSupport { } protected void exportCruise(GenericFormatExportContext exportContext, Cruise cruise, List<FishingOperation> operations) { - + exportContext.setCruiseExported(true); exportSurvey(exportContext, cruise); @@ -519,6 +525,10 @@ public class GenericFormatExportService extends GenericFormatServiceSupport { SurveyRow surveyRow = producerForSurvey.getDataToExport(cruise, country); producerForSurvey.write(surveyRow); + CsvProducerForAttachment producerForAttachment = exportContext.getProducerForAttachment(); + List<AttachmentRow> attachmentRows = producerForAttachment.getDataToExport(exportContext, cruise); + producerForAttachment.write(attachmentRows); + } catch (Exception e) { throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.survey.error"), e); } @@ -561,13 +571,15 @@ public class GenericFormatExportService extends GenericFormatServiceSupport { CatchBatch catchBatch = operationContext.getCatchBatch(); - // FIXME cela va poser des problème si le catch n'existe pas ? OperationRow operationRow = exportContext.getProducerForOperation().getDataToExport(cruise, operation, catchBatch); operationContext.setOperationRow(operationRow); List<ParameterRow> parameterRows = exportContext.getProducerForParameter().getDataToExport(cruise, operation); operationContext.setParameterRows(parameterRows); + List<AttachmentRow> attachmentRows = exportContext.getProducerForAttachment().getDataToExport(exportContext, operationContext); + operationContext.setAttachmentRows(attachmentRows); + boolean withCatchBatch = operationContext.isWithCatchBatch(); if (withCatchBatch) { @@ -588,20 +600,7 @@ public class GenericFormatExportService extends GenericFormatServiceSupport { } - try { - - exportContext.getProducerForOperation().write(operationContext.getOperationRow()); - exportContext.getProducerForParameter().write(operationContext.getParameterRows()); - exportContext.getProducerForMarineLitter().write(operationContext.getMarineLitterRows()); - exportContext.getProducerForIndividualObservation().write(operationContext.getIndividualObservationRows()); - exportContext.getProducerForAccidentalCatch().write(operationContext.getAccidentalCatchRows()); - exportContext.getProducerForCatch().write(operationContext.getCatchRows()); - - } catch (Exception e) { - - throw new ApplicationTechnicalException(t("tutti.service.genericFormat.export.operation.error", operationContext.getOperationLabel(), operationContext.getCruise().getName()), e); - - } + exportContext.write(operationContext); } @@ -644,8 +643,8 @@ public class GenericFormatExportService extends GenericFormatServiceSupport { Float catchRaisingFactor = totalWeight == null || totalUnsortedWeight == null || totalSortedWeight == null ? 1 : (totalWeight - totalUnsortedWeight) / totalSortedWeight; - Float speciesCatchRaisingFactor = totalSampleSortedSpeciesWeight == null || totalSortedSpeciesWeight == null || totalSampleSortedSpeciesWeight == null ? 1 : (totalSampleSortedSpeciesWeight == 0 ? 0 : (totalSortedSpeciesWeight / totalSampleSortedSpeciesWeight) * catchRaisingFactor); - Float benthosCatchRaisingFactor = totalSampleSortedBenthosWeight == null || totalSortedBenthosWeight == null || totalSampleSortedBenthosWeight == null ? 1 : (totalSampleSortedBenthosWeight == 0 ? 0 : (totalSortedBenthosWeight / totalSampleSortedBenthosWeight) * catchRaisingFactor); + Float speciesCatchRaisingFactor = totalSampleSortedSpeciesWeight == null || totalSortedSpeciesWeight == null ? 1 : (totalSampleSortedSpeciesWeight == 0 ? 0 : (totalSortedSpeciesWeight / totalSampleSortedSpeciesWeight) * catchRaisingFactor); + Float benthosCatchRaisingFactor = totalSampleSortedBenthosWeight == null || totalSortedBenthosWeight == null ? 1 : (totalSampleSortedBenthosWeight == 0 ? 0 : (totalSortedBenthosWeight / totalSampleSortedBenthosWeight) * catchRaisingFactor); if (log.isDebugEnabled()) { String message = "\ncatchTotalWeight : " + totalWeight + diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/AttachmentModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/AttachmentModel.java new file mode 100644 index 0000000..11c4845 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/AttachmentModel.java @@ -0,0 +1,65 @@ +package fr.ifremer.tutti.service.genericformat.csv; + +import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.service.csv.AbstractTuttiImportExportModel; +import fr.ifremer.tutti.service.csv.TuttiCsvUtil; +import fr.ifremer.tutti.service.genericformat.GenericFormatImportEntityParserFactory; + +/** + * Created on 3/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class AttachmentModel extends AbstractTuttiImportExportModel<AttachmentRow> { + + public static AttachmentModel forExport(char separator) { + + AttachmentModel exportModel = new AttachmentModel(separator); + exportModel.forExport(); + return exportModel; + + } + + public static AttachmentModel forImport(char separator, GenericFormatImportEntityParserFactory parserFactory) { + + AttachmentModel importModel = new AttachmentModel(separator); + importModel.forImport(parserFactory); + return importModel; + + } + + @Override + public AttachmentRow newEmptyInstance() { + + AttachmentRow row = AttachmentRow.newEmptyInstance(); + return row; + + } + + protected AttachmentModel(char separator) { + super(separator); + } + + protected void forExport() { + + newColumnForExport("Object_Id", Attachment.PROPERTY_OBJECT_ID, TuttiCsvUtil.PRIMITIVE_INTEGER); + newColumnForExport("Object_Type", Attachment.PROPERTY_OBJECT_TYPE, TuttiCsvUtil.newEnumByNameParserFormatter(ObjectTypeCode.class)); + newColumnForExport("Name", Attachment.PROPERTY_NAME); + newColumnForExport("Comment", Attachment.PROPERTY_COMMENT); + newColumnForExport("Path", Attachment.PROPERTY_PATH); + + } + + protected void forImport(GenericFormatImportEntityParserFactory parserFactory) { + + newMandatoryColumn("Object_Id", Attachment.PROPERTY_OBJECT_ID, TuttiCsvUtil.PRIMITIVE_INTEGER); + newMandatoryColumn("Object_Type", Attachment.PROPERTY_OBJECT_TYPE, TuttiCsvUtil.newEnumByNameParserFormatter(ObjectTypeCode.class)); + newMandatoryColumn("Name", Attachment.PROPERTY_NAME); + newMandatoryColumn("Comment", Attachment.PROPERTY_COMMENT); + newMandatoryColumn("Path", Attachment.PROPERTY_PATH); + + } + +} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/AttachmentRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/AttachmentRow.java new file mode 100644 index 0000000..882a366 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/AttachmentRow.java @@ -0,0 +1,74 @@ +package fr.ifremer.tutti.service.genericformat.csv; + +import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.Attachments; + +import java.io.Serializable; + +/** + * Created on 3/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class AttachmentRow implements Serializable { + + private static final long serialVersionUID = 1L; + + public static AttachmentRow newEmptyInstance() { + AttachmentRow row = new AttachmentRow(); + row.forImport(); + return row; + } + + private Attachment attachment; + + public void forImport() { + setAttachment(Attachments.newAttachment()); + } + + public void setAttachment(Attachment attachment) { + this.attachment = attachment; + } + + public void setName(String name) { + attachment.setName(name); + } + + public void setObjectId(Integer objectId) { + attachment.setObjectId(objectId); + } + + public void setPath(String path) { + attachment.setPath(path); + } + + public void setComment(String comment) { + attachment.setComment(comment); + } + + public void setObjectType(ObjectTypeCode objectType) { + attachment.setObjectType(objectType); + } + + public String getName() { + return attachment.getName(); + } + + public Integer getObjectId() { + return attachment.getObjectId(); + } + + public String getPath() { + return attachment.getPath(); + } + + public String getComment() { + return attachment.getComment(); + } + + public ObjectTypeCode getObjectType() { + return attachment.getObjectType(); + } +} 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 1a046ee..ba3e88e 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,6 +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); } @@ -187,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)); } } 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 189e09f..f84d0b8 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 @@ -52,6 +52,10 @@ public class ExportSampleCategory<S extends Serializable> extends SampleCategory public static final String PROPERTY_SAMPLE_WEIGHT = "sampleWeight"; + public static final java.lang.String PROPERTY_BATCH_ID = "batchId"; + + private String batchId; + private Integer rankOrder; private String weightOrVolType; @@ -64,6 +68,14 @@ public class ExportSampleCategory<S extends Serializable> extends SampleCategory return weightOrVolType; } + public String getBatchId() { + return batchId; + } + + public void setBatchId(String batchId) { + this.batchId = batchId; + } + public void setWeightOrVolType(String weightOrVolType) { this.weightOrVolType = weightOrVolType; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterModel.java index 21aff13..e57e248 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterModel.java @@ -82,6 +82,7 @@ public class MarineLitterModel extends AbstractTuttiImportExportModel<MarineLitt newColumnForExport("Commentaire", MarineLitterBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER); + newColumnForExport("Lot_Id", MarineLitterRow.PROPERTY_MARINE_LITTER_ID); newColumnForExport("Categorie_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_CATEGORY, TuttiCsvUtil.CARACTERISTIC_VALUE_TECHNICAL_FORMATTER); newColumnForExport("Categorie_Taille_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_SIZE_CATEGORY, TuttiCsvUtil.CARACTERISTIC_VALUE_TECHNICAL_FORMATTER); @@ -104,6 +105,7 @@ public class MarineLitterModel extends AbstractTuttiImportExportModel<MarineLitt newMandatoryColumn("Commentaire", MarineLitterBatch.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser()); + newMandatoryColumn("Lot_Id", MarineLitterRow.PROPERTY_MARINE_LITTER_ID); newMandatoryColumn("Categorie_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_CATEGORY, parserFactory.getMarineLitterCategoryValueParser()); newMandatoryColumn("Categorie_Taille_Id", MarineLitterBatch.PROPERTY_MARINE_LITTER_SIZE_CATEGORY, parserFactory.getMarineLitterSizeCategoryValueParser()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterRow.java index ea63b19..05da7fc 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/MarineLitterRow.java @@ -40,6 +40,8 @@ public class MarineLitterRow extends RowWithOperationContextSupport { private static final long serialVersionUID = 1L; + public static final String PROPERTY_MARINE_LITTER_ID = "marineLitterId"; + protected MarineLitterBatch marineLitterBatch; public static MarineLitterRow newEmptyInstance() { @@ -73,6 +75,10 @@ public class MarineLitterRow extends RowWithOperationContextSupport { marineLitterBatch.setComment(comment); } + public void setMarineLitterId(String marineLitterId) { + marineLitterBatch.setId(marineLitterId); + } + public MarineLitterBatch getMarineLitterBatch() { return marineLitterBatch; } @@ -97,4 +103,8 @@ public class MarineLitterRow extends RowWithOperationContextSupport { return marineLitterBatch.getComment(); } + public String getMarineLitterId() { + return marineLitterBatch.getId(); + } + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java index 1556ebd..f99381d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationModel.java @@ -153,6 +153,8 @@ public class OperationModel extends AbstractTuttiImportExportModel<OperationRow> newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER); newColumnForExport("Engin_Id", FishingOperation.PROPERTY_GEAR, TuttiCsvUtil.GEAR_TECHNICAL_FORMATTER); + newColumnForExport("Fishing_Operation_Id", OperationRow.PROPERTY_FISHING_OPERATION_ID); + newColumnForExport("Catch_Lot_Id", OperationRow.PROPERTY_CATCH_ID); newColumnForExport("Navire_Id", FishingOperation.PROPERTY_VESSEL, TuttiCsvUtil.VESSEL_TECHNICAL_FORMATTER); newColumnForExport("Strate_Id", FishingOperation.PROPERTY_STRATA, TuttiCsvUtil.FISHING_OPERATION_STRATA_TECHNICAL_FORMATTER); newColumnForExport("Sous_Strate_Id", FishingOperation.PROPERTY_SUB_STRATA, TuttiCsvUtil.FISHING_OPERATION_SUB_STRATA_TECHNICAL_FORMATTER); @@ -251,6 +253,8 @@ public class OperationModel extends AbstractTuttiImportExportModel<OperationRow> newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser()); newMandatoryColumn("Engin_Id", FishingOperation.PROPERTY_GEAR, parserFactory.getGearParser()); + newMandatoryColumn("Fishing_Operation_Id", OperationRow.PROPERTY_FISHING_OPERATION_ID); + newMandatoryColumn("Catch_Lot_Id", OperationRow.PROPERTY_CATCH_ID); newMandatoryColumn("Navire_Id", FishingOperation.PROPERTY_VESSEL, parserFactory.getVesselParser()); newMandatoryColumn("Strate_Id", FishingOperation.PROPERTY_STRATA, parserFactory.getFishingOperationStrataParser()); newMandatoryColumn("Sous_Strate_Id", FishingOperation.PROPERTY_SUB_STRATA, parserFactory.getFishingOperationSubStrataParser()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java index 3989b76..9fff7c8 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/OperationRow.java @@ -125,6 +125,10 @@ public class OperationRow extends RowWithOperationContextSupport { private static final long serialVersionUID = 1L; + public static final String PROPERTY_CATCH_ID = "catchId"; + + public static final String PROPERTY_FISHING_OPERATION_ID = "fishingOperationId"; + protected Short gearRankOrder; protected CatchBatch catchBatch; @@ -196,6 +200,14 @@ public class OperationRow extends RowWithOperationContextSupport { } } + public void setCatchId(String catchId) { + getCatchBatch().setId(catchId); + } + + public void setFishingOperationId(String fishingOperationId) { + getFishingOperation().setId(fishingOperationId); + } + public void setGear(Gear gear) { getFishingOperation().setGear(gear); } @@ -316,6 +328,14 @@ public class OperationRow extends RowWithOperationContextSupport { return gearRankOrder; } + public String getCatchId() { + return getCatchBatch().getId(); + } + + public String getFishingOperationId() { + return getFishingOperation().getId(); + } + public Gear getGear() { return getFishingOperation().getGear(); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java index 897433f..428fc84 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyModel.java @@ -84,6 +84,7 @@ public class SurveyModel extends AbstractTuttiImportExportModel<SurveyRow> { newColumnForExport("Commentaire", Cruise.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); newColumnForExport("Serie_Id", Cruise.PROPERTY_PROGRAM, TuttiCsvUtil.PROGRAM_TECHNICAL_FORMATTER); + newColumnForExport("Campagne_Id", Cruise.PROPERTY_ID); newColumnForExport("Navire_Id", Cruise.PROPERTY_VESSEL, TuttiCsvUtil.VESSEL_TECHNICAL_FORMATTER); newColumnForExport("Engin_Id", Cruise.PROPERTY_GEAR, TuttiCsvUtil.GEAR_LIST_TECHNICAL_FORMATTER); newColumnForExport("Port_Deb_Campagne_Id", Cruise.PROPERTY_DEPARTURE_LOCATION, TuttiCsvUtil.HARBOUR_TECHNICAL_FORMATTER); @@ -113,6 +114,7 @@ public class SurveyModel extends AbstractTuttiImportExportModel<SurveyRow> { newMandatoryColumn("Commentaire", Cruise.PROPERTY_COMMENT, TuttiCsvUtil.COMMENT_PARSER_FORMATTER); newMandatoryColumn("Serie_Id", Cruise.PROPERTY_PROGRAM, parserFactory.getProgramParser()); + newMandatoryColumn("Campagne_Id", Cruise.PROPERTY_ID); newMandatoryColumn("Navire_Id", Cruise.PROPERTY_VESSEL, parserFactory.getVesselParser()); newMandatoryColumn("Engin_Id", Cruise.PROPERTY_GEAR, parserFactory.getGearListParser()); newMandatoryColumn("Port_Deb_Campagne_Id", Cruise.PROPERTY_DEPARTURE_LOCATION, parserFactory.getHarbourParser()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyRow.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyRow.java index c48923a..fb69d9c 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyRow.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/csv/SurveyRow.java @@ -56,6 +56,10 @@ public class SurveyRow extends RowWithCruiseContextSupport { this.country = country; } + public void setId(String id) { + getCruise().setId(id); + } + public void setDepartureLocation(TuttiLocation departureLocation) { getCruise().setDepartureLocation(departureLocation); } @@ -108,6 +112,10 @@ public class SurveyRow extends RowWithCruiseContextSupport { return country; } + public String getId() { + return getCruise().getId(); + } + public String getName() { return getCruise().getName(); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForAttachment.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForAttachment.java new file mode 100644 index 0000000..da6f72f --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForAttachment.java @@ -0,0 +1,139 @@ +package fr.ifremer.tutti.service.genericformat.producer; + +import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; +import fr.ifremer.tutti.persistence.entities.data.Attachment; +import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; +import fr.ifremer.tutti.persistence.entities.data.Cruise; +import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; +import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; +import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.service.csv.CsvProducer; +import fr.ifremer.tutti.service.genericformat.GenericFormatExportContext; +import fr.ifremer.tutti.service.genericformat.GenericFormatExportOperationContext; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentModel; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +/** + * Created on 3/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class CsvProducerForAttachment extends CsvProducer<AttachmentRow, AttachmentModel> { + + private final Path sourcePath; + + private final Path targetPath; + + public CsvProducerForAttachment(Path file, AttachmentModel model, + Path sourcePath, + Path targetPath) { + super(file, model); + this.sourcePath = sourcePath; + this.targetPath = targetPath; + } + + public List<AttachmentRow> getDataToExport(GenericFormatExportContext exportContext, Cruise cruise) { + + List<AttachmentRow> rows = new ArrayList<>(); + + List<Attachment> attachments = exportContext.getAttachements(cruise); + addAttachments(attachments, rows); + + return rows; + + } + + public List<AttachmentRow> getDataToExport(GenericFormatExportContext exportContext, GenericFormatExportOperationContext operationContext) { + + List<AttachmentRow> rows = new ArrayList<>(); + + { + List<Attachment> attachments = exportContext.getAttachements(operationContext.getOperation()); + addAttachments(attachments, rows); + } + + if (operationContext.isWithCatchBatch()) { + + { + List<Attachment> attachments = exportContext.getAttachements(operationContext.getCatchBatch()); + addAttachments(attachments, rows); + } + + { + for (IndividualObservationBatch individualObservationBatch : operationContext.getIndividualObservations()) { + List<Attachment> attachments = exportContext.getAttachements(individualObservationBatch); + addAttachments(attachments, rows); + } + } + + { + for (AccidentalBatch accidentalBatch : operationContext.getAccidentalBatches()) { + List<Attachment> attachments = exportContext.getAttachements(accidentalBatch); + addAttachments(attachments, rows); + } + } + + { + for (BenthosBatch benthosBatch : operationContext.getRootBenthosBatch().getChildren()) { + List<Attachment> attachments = exportContext.getAttachements(benthosBatch); + addAttachments(attachments, rows); + } + + } + + { + for (SpeciesBatch speciesBatch : operationContext.getRootSpeciesBatch().getChildren()) { + List<Attachment> attachments = exportContext.getAttachements(speciesBatch); + addAttachments(attachments, rows); + } + } + + { + for (MarineLitterBatch marineLitterBatch : operationContext.getRootMarineLitterBatch().getChildren()) { + List<Attachment> attachments = exportContext.getAttachements(marineLitterBatch); + addAttachments(attachments, rows); + } + } + + } + + return rows; + + } + + + @Override + public void write(List<AttachmentRow> rows) throws Exception { + super.write(rows); + for (AttachmentRow row : rows) { + + String path = row.getPath(); + + Path source = sourcePath.resolve(path); + Path target = targetPath.resolve(path); + Files.createDirectories(target.getParent()); + Files.copy(source, target); + + } + } + + protected void addAttachments(List<Attachment> attachments, List<AttachmentRow> rows) { + + for (Attachment attachment : attachments) { + + AttachmentRow row = new AttachmentRow(); + row.setAttachment(attachment); + rows.add(row); + + } + + } + +} + 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 1479bbb..5d8be44 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 @@ -189,6 +189,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { addBatchSampleCategory(operationExportContext.getSampleCategoryModel(), currentRow, + speciesBatch.getId(), speciesBatch.getSampleCategoryId(), speciesBatch.getSampleCategoryValue(), speciesBatch.getSampleCategoryWeight(), @@ -314,6 +315,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { addBatchSampleCategory(operationExportContext.getSampleCategoryModel(), currentRow, + benthosBatch.getId(), benthosBatch.getSampleCategoryId(), benthosBatch.getSampleCategoryValue(), benthosBatch.getSampleCategoryWeight(), @@ -464,6 +466,7 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { protected void addBatchSampleCategory(SampleCategoryModel sampleCategoryModel, CatchRow currentRow, + String batchId, Integer sampleCategoryId, Serializable sampleCategoryValue, Float sampleCategoryWeight, @@ -475,8 +478,8 @@ public class CsvProducerForCatch extends CsvProducer<CatchRow, CatchModel> { currentRow.setBatchNumber(batchNumber); currentRow.setBatchNumberComputed(batchNumberComputed); - ExportSampleCategory<Serializable> sampleCategory = - new ExportSampleCategory<>(); + ExportSampleCategory<Serializable> sampleCategory = new ExportSampleCategory<>(); + sampleCategory.setBatchId(batchId); SampleCategoryModelEntry categoryById = sampleCategoryModel.getCategoryById(sampleCategoryId); sampleCategory.setCategoryDef(categoryById); sampleCategory.setCategoryValue(sampleCategoryValue); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.