branch develop updated (41ae140 -> 3cbcdc3)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository tutti. See http://git.codelutin.com/tutti.git from 41ae140 move some code new aaeb470 problème d'égalite d'une campagne si le surveyPart est vide ou null new 4550174 suppression des pieces jointes d'une catchBatch a sa suppression new 5f907f3 amélioration de la suppression d'une pièce jointe new 59e93c7 decompresser l'archive d'import des le debut (on ne travaille plus sur les entrées du zip new ee8aa17 refs #6820 modification des imports pour pouvoir importer les pj new 1432b54 refs #6820 ajout de l'import des pj new b53e9a7 fix typo new ded5f75 delete pj before deleting catch batch new 2e3fee3 all pj imports wokrs now new 3cbcdc3 fixes #6820: [IMPORT GENERIQUE] Import des pièces jointes Merge branch 'feature/6820' into develop The 10 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 3cbcdc3f96f32ecd7abc3c19ae33119b622c3d4c Merge: 41ae140 2e3fee3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 18:22:18 2015 +0100 fixes #6820: [IMPORT GENERIQUE] Import des pièces jointes Merge branch 'feature/6820' into develop commit 2e3fee3260ccc887bdbb20c5b120e43486b8ec62 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 18:21:59 2015 +0100 all pj imports wokrs now commit ded5f75bbcbda4cb94469546380151cd44dc0c95 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 18:21:46 2015 +0100 delete pj before deleting catch batch commit b53e9a70035870da94608926a9bd7bfb9063df6d Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:24:58 2015 +0100 fix typo commit 1432b54c76b994b3a887bd4d6bfd6923b10962cd Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:24:44 2015 +0100 refs #6820 ajout de l'import des pj commit ee8aa173479d96a13fc4fad46763298a8e82a5cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:24:11 2015 +0100 refs #6820 modification des imports pour pouvoir importer les pj commit 59e93c7bfb3c13d5aee235cf40c57d02ee5b6db7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:22:49 2015 +0100 decompresser l'archive d'import des le debut (on ne travaille plus sur les entrées du zip commit 5f907f33e5565f424c1cb50d279225839e47913a Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:22:00 2015 +0100 amélioration de la suppression d'une pièce jointe commit 455017422a1c98861d0ce963f9f48f1dc40b9756 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:21:35 2015 +0100 suppression des pieces jointes d'une catchBatch a sa suppression commit aaeb47017c46cfbb0a361704f7fde8014f5891ee Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:20:53 2015 +0100 problème d'égalite d'une campagne si le surveyPart est vide ou null Summary of changes: .../tutti/persistence/entities/data/Cruises.java | 18 ++- .../service/AttachmentPersistenceServiceImpl.java | 26 +++- .../FishingOperationPersistenceServiceImpl.java | 11 +- .../service/util/BatchPersistenceHelper.java | 1 + .../genericformat/GenericFormatArchive.java | 148 +++++++-------------- .../genericformat/GenericFormatContextSupport.java | 33 ++++- .../GenericFormatImportOperationContext.java | 15 +++ .../genericformat/GenericFormatImportService.java | 3 + .../GenericformatImportPersitenceHelper.java | 96 +++++++++++-- .../consumer/CsvConsumerForAccidentalCatch.java | 1 + .../consumer/CsvConsumerForAttachment.java | 29 ++++ .../consumer/CsvConsumerForCatch.java | 12 +- .../CsvConsumerForIndividualObservation.java | 1 + .../service/genericformat/csv/AttachmentRow.java | 12 ++ .../service/genericformat/csv/CatchModel.java | 4 +- .../genericformat/csv/ExportSampleCategory.java | 6 +- .../genericformat/csv/MarineLitterModel.java | 4 +- .../service/genericformat/csv/MarineLitterRow.java | 10 +- .../service/genericformat/csv/OperationModel.java | 8 +- .../service/genericformat/csv/OperationRow.java | 26 ++-- .../service/genericformat/csv/SurveyModel.java | 4 +- .../tutti/service/genericformat/csv/SurveyRow.java | 12 +- .../importactions/ImportOperationAction.java | 8 +- .../importactions/ImportSurveyAction.java | 7 +- .../importactions/LoadAttachmentsAction.java | 80 +++++++++++ .../producer/CsvProducerForSurvey.java | 1 + .../resources/i18n/tutti-service_en_GB.properties | 1 + .../resources/i18n/tutti-service_fr_FR.properties | 1 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 4 +- 29 files changed, 420 insertions(+), 162 deletions(-) create mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAttachment.java create mode 100644 tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/LoadAttachmentsAction.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 aaeb47017c46cfbb0a361704f7fde8014f5891ee Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:20:53 2015 +0100 problème d'égalite d'une campagne si le surveyPart est vide ou null --- .../tutti/persistence/entities/data/Cruises.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/Cruises.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/Cruises.java index cc26c3a..5c3a5d5 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/Cruises.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/data/Cruises.java @@ -51,22 +51,30 @@ public class Cruises extends AbstractCruises { Calendar instance = Calendar.getInstance(); int year1; - if (cruise1.getBeginDate()==null) { - year1=-1; + if (cruise1.getBeginDate() == null) { + year1 = -1; } else { instance.setTime(cruise1.getBeginDate()); year1 = instance.get(Calendar.YEAR); } int year2; - if (cruise1.getBeginDate()==null) { - year2=-2; + if (cruise1.getBeginDate() == null) { + year2 = -2; } else { instance.setTime(cruise2.getBeginDate()); year2 = instance.get(Calendar.YEAR); } equalsBuilder.append(year1, year2); - equalsBuilder.append(cruise1.getSurveyPart(), cruise2.getSurveyPart()); + String surveyPart1 = cruise1.getSurveyPart(); + if (surveyPart1 == null) { + surveyPart1 = ""; + } + String surveyPart2 = cruise2.getSurveyPart(); + if (surveyPart2 == null) { + surveyPart2 = ""; + } + equalsBuilder.append(surveyPart1, surveyPart2); equalsBuilder.append(cruise1.getProgram(), cruise2.getProgram()); boolean equals = equalsBuilder.isEquals(); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 455017422a1c98861d0ce963f9f48f1dc40b9756 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:21:35 2015 +0100 suppression des pieces jointes d'une catchBatch a sa suppression --- .../ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java index 73eb4d9..6f69427 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/util/BatchPersistenceHelper.java @@ -197,6 +197,7 @@ public class BatchPersistenceHelper extends AbstractPersistenceService { List<Integer> ids = catchBatchDao.getAllChildrenIds(catchBatchId); catchBatchDao.remove(catchBatchId); + attachmentPersistenceService.deleteAllAttachment(ObjectTypeCode.CATCH_BATCH, catchBatchId); getCurrentSession().flush(); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 5f907f33e5565f424c1cb50d279225839e47913a Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:22:00 2015 +0100 amélioration de la suppression d'une pièce jointe --- .../service/AttachmentPersistenceServiceImpl.java | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java index a4e28ec..ebd8515 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/AttachmentPersistenceServiceImpl.java @@ -283,7 +283,31 @@ public class AttachmentPersistenceServiceImpl extends AbstractPersistenceService } measurementFileDao.remove(target.getIdAsInt()); - ApplicationIOUtil.deleteFile(file, t("tutti.persistence.attachment.deleteFile.error", file)); + if (file.exists()) { + ApplicationIOUtil.deleteFile(file, t("tutti.persistence.attachment.deleteFile.error", file)); + } else { + if (log.isWarnEnabled()) { + log.warn("COULD NOT FIND Attachement at " + file); + } + } + + File parentFile = file.getParentFile(); + while (!parentFile.equals(dbAttachmentDirectory)) { + + File[] files = parentFile.listFiles(); + if (files != null && files.length == 0) { + + // can delete this directory + if (log.isDebugEnabled()) { + log.debug("Remove empty directory: " + parentFile); + } + ApplicationIOUtil.deleteDirectory(parentFile, "Could not clean directory"); + parentFile = parentFile.getParentFile(); + } else { + break; + } + + } } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 59e93c7bfb3c13d5aee235cf40c57d02ee5b6db7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:22:49 2015 +0100 decompresser l'archive d'import des le debut (on ne travaille plus sur les entrées du zip --- .../genericformat/GenericFormatArchive.java | 148 +++++++-------------- 1 file changed, 48 insertions(+), 100 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 356fd27..d02da4d 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 @@ -24,18 +24,16 @@ package fr.ifremer.tutti.service.genericformat; * #L% */ -import com.google.common.base.Preconditions; import fr.ifremer.tutti.persistence.ProgressionModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.vfs2.FileObject; import org.nuiton.jaxx.application.ApplicationIOUtil; import org.nuiton.jaxx.application.ApplicationTechnicalException; +import org.nuiton.util.ZipUtil; import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.LineNumberReader; import java.io.Serializable; import java.nio.charset.Charset; @@ -45,8 +43,6 @@ import java.util.EnumMap; import java.util.EnumSet; import java.util.LinkedHashSet; import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; import static org.nuiton.i18n.I18n.t; @@ -85,7 +81,7 @@ public class GenericFormatArchive implements Serializable { DATA_MARINE_LITTER(true, "marineLitter.csv"), DATA_ACCIDENTAL_CATCH(true, "accidentalCatch.csv"), DATA_INDIVIDUAL_OBSERVATION(true, "individualObservation.csv"), - DATA_ATTACHMENTS(true, "attachments.csv") ; + DATA_ATTACHMENTS(true, "attachments.csv"); private final boolean mandatory; @@ -112,8 +108,6 @@ public class GenericFormatArchive implements Serializable { private final ArchiveMode archiveMode; - private final String prefixPath; - private final EnumMap<ArchiveFilePath, Integer> countLines; private final EnumSet<ArchiveFilePath> missingPaths; @@ -277,6 +271,10 @@ public class GenericFormatArchive implements Serializable { return countImportLines(ArchiveFilePath.DATA_ACCIDENTAL_CATCH); } + public int getAttachemntsPathLineCount() { + return countImportLines(ArchiveFilePath.DATA_ATTACHMENTS); + } + public int getParameterPathLineCount() { return countImportLines(ArchiveFilePath.DATA_PARAMETER); } @@ -339,10 +337,16 @@ public class GenericFormatArchive implements Serializable { } + public File extractAttachment(String path) { + + Path resolve = getAttachmentDataPath().resolve(path); + return resolve.toFile(); + + } + protected GenericFormatArchive(ArchiveMode archiveMode, File archiveFile, File workingDirectory) { this.archiveFile = archiveFile; - this.workingDirectory = workingDirectory; this.archiveMode = archiveMode; this.countLines = new EnumMap<>(ArchiveFilePath.class); @@ -352,20 +356,34 @@ public class GenericFormatArchive implements Serializable { log.info("Archive mode: " + archiveMode); } if (isImport()) { - this.prefixPath = extractPrefixPath(); - if (log.isInfoEnabled()) { - log.info("Zip entries prefix path: " + prefixPath); - } - missingPaths = computeMissingPaths(); + this.workingDirectory = extractArchive(archiveFile, workingDirectory); + this.missingPaths = computeMissingPaths(); } else { - this.prefixPath = null; + + this.workingDirectory = workingDirectory; this.missingPaths = null; + } } + protected File extractArchive(File archiveFile, File workingDirectory) { + + try { + ZipUtil.uncompress(archiveFile, workingDirectory); + } catch (IOException e) { + throw new ApplicationTechnicalException("Could not explode zipfile " + archiveFile, e); + } + File[] files = workingDirectory.listFiles(); + if (files==null || files.length!=1) { + throw new ApplicationTechnicalException("Archive should contains onyl one directory"); + } + return files[0]; + + } + protected boolean isImport() { return ArchiveMode.IMPORT == archiveMode; } @@ -374,114 +392,44 @@ public class GenericFormatArchive implements Serializable { return ArchiveMode.EXPORT == archiveMode; } - protected String extractPrefixPath() { - - FileObject fileObject = ApplicationIOUtil.resolveFile( - "zip:" + archiveFile.getAbsolutePath(), - t("tutti.service.persistence.getArchive.error", archiveFile)); - - FileObject[] children = ApplicationIOUtil.getChildren( - fileObject, - t("tutti.service.persistence.openArchive.error", fileObject)); - - fileObject = children[0]; - - String prefix = fileObject.getName().getBaseName(); - return prefix; - - } - protected Path getPath(ArchiveFilePath archiveFilePath) { String filename = archiveFilePath.getFilename(); Path file = workingDirectory.toPath().resolve(filename); - if (isImport() && Files.notExists(file) && !missingPaths.contains(archiveFilePath)) { - - // Explode from archive - - try (ZipFile zipFile = new ZipFile(archiveFile)) { - - ZipEntry entry = getZipEntryPath(archiveFilePath, zipFile); - - Preconditions.checkState(!(archiveFilePath.isMandatory() && entry == null), "Must have entry " + filename); - - if (entry != null) { - - if (log.isInfoEnabled()) { - log.info("Explode zip entry to " + file.toFile().getName()); - } - - try (InputStream inputStream = zipFile.getInputStream(entry)) { - Files.copy(inputStream, file); - } - - } - - } catch (IOException e) { - throw new ApplicationTechnicalException("Could not open zip file: " + archiveFile, e); - } - - } - return file; } - protected ZipEntry getZipEntryPath(ArchiveFilePath archiveFilePath, ZipFile zipFile ) { - String path = prefixPath + "/" + archiveFilePath.getFilename(); - ZipEntry entry = zipFile.getEntry(path); - if (entry==null) { - path = prefixPath + "\\" + archiveFilePath.getFilename(); - entry = zipFile.getEntry(path); - } - return entry; - } - - protected String getZipEntryPath(ArchiveFilePath archiveFilePath) { - - String path = prefixPath + archiveFilePath.getFilename(); - return path; - - } - protected EnumSet<ArchiveFilePath> computeMissingPaths() { EnumSet<ArchiveFilePath> result = EnumSet.noneOf(ArchiveFilePath.class); - try (ZipFile zipFile = new ZipFile(archiveFile)) { - - for (ArchiveFilePath archiveFilePath : ArchiveFilePath.values()) { + for (ArchiveFilePath archiveFilePath : ArchiveFilePath.values()) { - ZipEntry zipEntry = getZipEntryPath(archiveFilePath, zipFile); + Path path = getPath(archiveFilePath); - if (log.isDebugEnabled()) { - log.debug("Check if entry " + archiveFilePath + " exists."); - } + if (log.isDebugEnabled()) { + log.debug("Check if entry " + archiveFilePath + " exists."); + } - if (zipEntry == null) { + if (!Files.exists(path)) { - if (log.isInfoEnabled()) { - log.info("Entry " + archiveFilePath + " not found."); - } - - result.add(archiveFilePath); + if (log.isInfoEnabled()) { + log.info("Entry " + archiveFilePath + " not found."); + } - } else { + result.add(archiveFilePath); - if (log.isInfoEnabled()) { - log.info("Entry " + archiveFilePath + " found."); - } + } else { + if (log.isInfoEnabled()) { + log.info("Entry " + archiveFilePath + " found."); } } - } catch (IOException e) { - - throw new ApplicationTechnicalException("Could not open or close zip file: " + archiveFile, e); - } return result; @@ -495,9 +443,9 @@ public class GenericFormatArchive implements Serializable { Path path = getPath(archiveFilePath); - if (path==null) { + if (path == null) { - result=0; + result = 0; countLines.put(archiveFilePath, 0); } else { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 ee8aa173479d96a13fc4fad46763298a8e82a5cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:24:11 2015 +0100 refs #6820 modification des imports pour pouvoir importer les pj --- .../service/genericformat/csv/AttachmentRow.java | 12 ++++++++++ .../genericformat/csv/MarineLitterModel.java | 4 ++-- .../service/genericformat/csv/MarineLitterRow.java | 10 +++------ .../service/genericformat/csv/OperationModel.java | 8 +++---- .../service/genericformat/csv/OperationRow.java | 26 +++++++++++++--------- .../service/genericformat/csv/SurveyModel.java | 4 ++-- .../tutti/service/genericformat/csv/SurveyRow.java | 12 ++++++---- 7 files changed, 47 insertions(+), 29 deletions(-) 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 index 882a366..abc17e7 100644 --- 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 @@ -71,4 +71,16 @@ public class AttachmentRow implements Serializable { public ObjectTypeCode getObjectType() { return attachment.getObjectType(); } + + public Attachment toAttachment(Integer objectId) { + + Attachment result = Attachments.newAttachment(); + result.setObjectId(objectId); + result.setObjectType(getObjectType()); + result.setName(getName()); + result.setComment(getComment()); + result.setPath(getPath()); + return result; + + } } 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 e57e248..62539cc 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,7 +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("Lot_Id", MarineLitterRow.PROPERTY_MARINE_LITTER_ID, TuttiCsvUtil.INTEGER); 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); @@ -105,7 +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("Lot_Id", MarineLitterRow.PROPERTY_MARINE_LITTER_ID, TuttiCsvUtil.INTEGER); 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 05da7fc..b2d5d98 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 @@ -34,10 +34,6 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativ */ public class MarineLitterRow extends RowWithOperationContextSupport { - public static final String PROPERTY_TOTAL_WEIGHT = "totalWeight"; - - public static final String PROPERTY_BATCH = "batch"; - private static final long serialVersionUID = 1L; public static final String PROPERTY_MARINE_LITTER_ID = "marineLitterId"; @@ -75,7 +71,7 @@ public class MarineLitterRow extends RowWithOperationContextSupport { marineLitterBatch.setComment(comment); } - public void setMarineLitterId(String marineLitterId) { + public void setMarineLitterId(Integer marineLitterId) { marineLitterBatch.setId(marineLitterId); } @@ -103,8 +99,8 @@ public class MarineLitterRow extends RowWithOperationContextSupport { return marineLitterBatch.getComment(); } - public String getMarineLitterId() { - return marineLitterBatch.getId(); + public Integer getMarineLitterId() { + return marineLitterBatch.getIdAsInt(); } } 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 f99381d..375ad81 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,8 +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("Fishing_Operation_Id", OperationRow.PROPERTY_FISHING_OPERATION_OBJECT_ID, TuttiCsvUtil.INTEGER); + newColumnForExport("Catch_Lot_Id", OperationRow.PROPERTY_CATCH_OBJECT_ID, TuttiCsvUtil.INTEGER); 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); @@ -253,8 +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("Fishing_Operation_Id", OperationRow.PROPERTY_FISHING_OPERATION_OBJECT_ID, TuttiCsvUtil.INTEGER); + newMandatoryColumn("Catch_Lot_Id", OperationRow.PROPERTY_CATCH_OBJECT_ID, TuttiCsvUtil.INTEGER); 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 9fff7c8..27fe645 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,9 +125,9 @@ public class OperationRow extends RowWithOperationContextSupport { private static final long serialVersionUID = 1L; - public static final String PROPERTY_CATCH_ID = "catchId"; + public static final String PROPERTY_CATCH_OBJECT_ID = "catchObjectId"; - public static final String PROPERTY_FISHING_OPERATION_ID = "fishingOperationId"; + public static final String PROPERTY_FISHING_OPERATION_OBJECT_ID = "fishingOperationObjectId"; protected Short gearRankOrder; @@ -151,6 +151,10 @@ public class OperationRow extends RowWithOperationContextSupport { protected Boolean marineLitterTotalWeightComputed; + protected Integer fishingOperationObjectId; + + protected Integer catchObjectId; + public static OperationRow newEmptyInstance() { OperationRow row = new OperationRow(); @@ -169,6 +173,7 @@ public class OperationRow extends RowWithOperationContextSupport { } this.catchBatch = catchBatch; + setCatchObjectId(catchBatch.getIdAsInt()); } @@ -198,14 +203,15 @@ public class OperationRow extends RowWithOperationContextSupport { if (getGear() != null) { setGearRankOrder(getGear().getRankOrder()); } + setFishingOperationObjectId(fishingOperation.getIdAsInt()); } - public void setCatchId(String catchId) { - getCatchBatch().setId(catchId); + public void setCatchObjectId(Integer catchObjectId) { + this.catchObjectId = catchObjectId; } - public void setFishingOperationId(String fishingOperationId) { - getFishingOperation().setId(fishingOperationId); + public void setFishingOperationObjectId(Integer fishingOperationObjectId) { + this.fishingOperationObjectId = fishingOperationObjectId; } public void setGear(Gear gear) { @@ -328,12 +334,12 @@ public class OperationRow extends RowWithOperationContextSupport { return gearRankOrder; } - public String getCatchId() { - return getCatchBatch().getId(); + public Integer getFishingOperationObjectId() { + return fishingOperationObjectId; } - public String getFishingOperationId() { - return getFishingOperation().getId(); + public Integer getCatchObjectId() { + return catchObjectId; } public Gear 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 428fc84..b885563 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,7 +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("Campagne_Id", SurveyRow.PROPERTY_OBJECT_ID, TuttiCsvUtil.INTEGER); 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); @@ -114,7 +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("Campagne_Id", SurveyRow.PROPERTY_OBJECT_ID, TuttiCsvUtil.INTEGER); 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 fb69d9c..5149c37 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 @@ -44,6 +44,8 @@ public class SurveyRow extends RowWithCruiseContextSupport { public static final String PROPERTY_ID_SISMER = "idSismer"; + public static final String PROPERTY_OBJECT_ID = "objectId"; + public static SurveyRow newEmptyInstance() { SurveyRow row = new SurveyRow(); row.forImport(); @@ -52,12 +54,14 @@ public class SurveyRow extends RowWithCruiseContextSupport { protected TuttiLocation country; + private Integer objectId; + public void setCountry(TuttiLocation country) { this.country = country; } - public void setId(String id) { - getCruise().setId(id); + public void setObjectId(Integer id) { + this.objectId = id; } public void setDepartureLocation(TuttiLocation departureLocation) { @@ -112,8 +116,8 @@ public class SurveyRow extends RowWithCruiseContextSupport { return country; } - public String getId() { - return getCruise().getId(); + public Integer getObjectId() { + return objectId; } public String getName() { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 1432b54c76b994b3a887bd4d6bfd6923b10962cd Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:24:44 2015 +0100 refs #6820 ajout de l'import des pj --- .../genericformat/GenericFormatContextSupport.java | 32 ++++++++- .../genericformat/GenericFormatImportService.java | 3 + .../GenericformatImportPersitenceHelper.java | 78 ++++++++++++++++++--- .../consumer/CsvConsumerForAccidentalCatch.java | 1 + .../consumer/CsvConsumerForAttachment.java | 29 ++++++++ .../CsvConsumerForIndividualObservation.java | 1 + .../importactions/ImportOperationAction.java | 7 +- .../importactions/ImportSurveyAction.java | 6 +- .../importactions/LoadAttachmentsAction.java | 80 ++++++++++++++++++++++ .../producer/CsvProducerForSurvey.java | 1 + .../resources/i18n/tutti-service_en_GB.properties | 1 + .../resources/i18n/tutti-service_fr_FR.properties | 1 + 12 files changed, 229 insertions(+), 11 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 42cb74b..1a3f675 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 @@ -25,7 +25,9 @@ package fr.ifremer.tutti.service.genericformat; */ 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.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; @@ -44,6 +46,7 @@ import fr.ifremer.tutti.service.ValidationService; import fr.ifremer.tutti.service.csv.CaracteristicValueParseException; import fr.ifremer.tutti.service.csv.CaracteristicValueParserFormatter; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForAccidentalCatch; +import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForAttachment; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForCatch; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForGearCaracteristic; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForIndividualObservation; @@ -52,6 +55,7 @@ import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForOperation; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForParameter; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForSampleCategory; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForSurvey; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; import fr.ifremer.tutti.service.genericformat.csv.RowWithCruiseContextSupport; import fr.ifremer.tutti.service.referential.consumer.CsvConsumerForTemporaryGear; import fr.ifremer.tutti.service.referential.consumer.CsvConsumerForTemporaryPerson; @@ -65,6 +69,7 @@ import java.io.File; import java.io.Serializable; import java.nio.file.Path; import java.text.ParseException; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -123,10 +128,14 @@ public abstract class GenericFormatContextSupport implements Closeable { private final GenericFormatCsvFileResult gearCaracteristicFileResult; + private final GenericFormatCsvFileResult attachmentFileResult; + private final Map<String, GenericFormatImportCruiseContext> cruiseContexts; private String protocolOriginalName; + private final Multimap<Integer, AttachmentRow> attachmentRows; + protected abstract void onClose(); public GenericFormatContextSupport(GenericFormatImportRequest importRequest, @@ -167,7 +176,9 @@ public abstract class GenericFormatContextSupport implements Closeable { this.marineLitterFileResult = createFileResult(archive.getMarineLitterPath(), true); this.individualObservationFileResult = createFileResult(archive.getIndividualObservationPath(), true); this.accidentalCatchFileResult = createFileResult(archive.getAccidentalCatchPath(), true); + this.attachmentFileResult = createFileResult(archive.getAttachmentFilePath(), true); + this.attachmentRows = ArrayListMultimap.create(); } @Override @@ -258,6 +269,10 @@ public abstract class GenericFormatContextSupport implements Closeable { return accidentalCatchFileResult; } + public GenericFormatCsvFileResult getAttachmentFileResult() { + return attachmentFileResult; + } + public GenericFormatImportRequest getImportRequest() { return importRequest; } @@ -401,6 +416,13 @@ public abstract class GenericFormatContextSupport implements Closeable { return consumer; } + public CsvConsumerForAttachment loadAttachments(boolean failFast) { + attachmentFileResult.setImported(true); + attachmentFileResult.setLinesCount(importRequest.getArchive().getAttachemntsPathLineCount()); + CsvConsumerForAttachment consumer = new CsvConsumerForAttachment(importRequest.getArchive().getAttachmentFilePath(), importRequest.getCsvSeparator(), importEntityParserFactory, failFast); + return consumer; + } + public CsvConsumerForTemporaryGear loadTemporaryGears(boolean failFast) { referentialTemporaryGearFileResult.setImported(true); referentialTemporaryGearFileResult.setLinesCount(importRequest.getArchive().getTemporaryReferentialGearLineCount()); @@ -534,8 +556,16 @@ public abstract class GenericFormatContextSupport implements Closeable { this.protocolOriginalName = protocolOriginalName; } + public void setAttachmentRows(Multimap<Integer, AttachmentRow> attachmentRows) { + this.attachmentRows.putAll(attachmentRows); + } + + public Collection<AttachmentRow> popAttachmentRows(Integer objectId) { + Collection<AttachmentRow> result = objectId==null?null:attachmentRows.removeAll(objectId); + return result; + } - public static interface CruiseContextAction { + public interface CruiseContextAction { void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java index 9a35d81..72d8712 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportService.java @@ -50,6 +50,7 @@ import fr.ifremer.tutti.service.genericformat.importactions.ImportReferentialPer import fr.ifremer.tutti.service.genericformat.importactions.ImportReferentialSpeciesAction; import fr.ifremer.tutti.service.genericformat.importactions.ImportReferentialVesselAction; import fr.ifremer.tutti.service.genericformat.importactions.ImportSurveyAction; +import fr.ifremer.tutti.service.genericformat.importactions.LoadAttachmentsAction; import fr.ifremer.tutti.service.genericformat.importactions.ValidateAccidentalCatchAction; import fr.ifremer.tutti.service.genericformat.importactions.ValidateCatchAction; import fr.ifremer.tutti.service.genericformat.importactions.ValidateGearCaracteristicAction; @@ -351,6 +352,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { Set<ImportActionSupport> actions = new LinkedHashSet<>(); addTechnicalActions(importContext, actions); + actions.add(new LoadAttachmentsAction(importContext)); actions.add(new ValidateSurveyAction(importContext)); actions.add(new ValidateGearCaracteristicAction(importContext)); actions.add(new ValidateOperationAction(importContext)); @@ -367,6 +369,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { Set<ImportActionSupport> actions = new LinkedHashSet<>(); addTechnicalActions(importContext, actions); + actions.add(new LoadAttachmentsAction(importContext)); actions.add(new ImportSurveyAction(importContext, persitenceHelper)); actions.add(new ImportGearCaracteristicAction(importContext, persitenceHelper)); actions.add(new ImportOperationAction(importContext, persitenceHelper)); 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 8533da0..acecefc 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 @@ -24,10 +24,12 @@ package fr.ifremer.tutti.service.genericformat; * #L% */ +import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.TuttiEntities; 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.BenthosBatchFrequency; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; @@ -39,11 +41,13 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.service.PersistenceService; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; +import java.io.File; import java.util.Collection; import java.util.List; import java.util.Set; @@ -76,7 +80,7 @@ public class GenericformatImportPersitenceHelper { this.fishingOperationDecorator = fishingOperationDecorator; } - public void persistCruise(Cruise cruise) { + public void persistCruise(Cruise cruise, Collection<AttachmentRow> attachmentRows) { String cruiseStr = cruiseDecorator.toString(cruise); @@ -100,6 +104,10 @@ public class GenericformatImportPersitenceHelper { } importContext.increments(t("tutti.service.genericFormat.persist.cruise", cruiseStr)); + + // delete previous attachments + persistenceService.deleteAllAttachment(ObjectTypeCode.SCIENTIFIC_CRUISE, cruise.getIdAsInt()); + savedCruise = persistenceService.saveCruise(cruise, false, false); List<String> fishingOperationIds = persistenceService.getAllFishingOperationIds(savedCruise.getId()); @@ -116,10 +124,26 @@ public class GenericformatImportPersitenceHelper { } + if (CollectionUtils.isNotEmpty(attachmentRows)) { + + persistAttachments(savedCruise.getIdAsInt(), attachmentRows); + } importContext.addImportedCruise(savedCruise, !createCruise); } + protected void persistAttachments(Integer objectId, Collection<AttachmentRow> attachmentRows) { + + for (AttachmentRow attachmentRow : attachmentRows) { + + Attachment attachment = attachmentRow.toAttachment(objectId); + File attachmentFile = importContext.getImportRequest().getArchive().extractAttachment(attachment.getPath()); + persistenceService.createAttachment(attachment, attachmentFile); + + } + + } + public void persistGearCaracteristics() { importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { @@ -151,7 +175,7 @@ public class GenericformatImportPersitenceHelper { } - public void persistFishingOperation(GenericFormatImportCruiseContext cruiseContext, FishingOperation fishingOperation, CatchBatch catchBatch) { + public void persistFishingOperation(GenericFormatImportCruiseContext cruiseContext, FishingOperation fishingOperation, CatchBatch catchBatch, Collection<AttachmentRow> operationAttachmentRows, Collection<AttachmentRow> catchAttachmentRows) { String operationStr = fishingOperationDecorator.toString(fishingOperation); String cruiseStr = cruiseContext.getCruiseLabel(); @@ -164,6 +188,9 @@ public class GenericformatImportPersitenceHelper { CatchBatch createdCatchBatch = persistenceService.createCatchBatch(catchBatch); + persistAttachments(createdFishingOperation.getIdAsInt(), operationAttachmentRows); + persistAttachments(createdCatchBatch.getIdAsInt(), catchAttachmentRows); + importContext.addImportedFishingOperation(createdFishingOperation, createdCatchBatch); } @@ -391,7 +418,16 @@ public class GenericformatImportPersitenceHelper { //FIXME Does not work (all batches are persisted, but the last one only displayed later in application) // persistenceService.createMarineLitterBatches(fishingOperationId, marineLitterBatches); for (MarineLitterBatch marineLitterBatch : marineLitterBatches) { + + Integer objectId = marineLitterBatch.getIdAsInt(); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(objectId); + + // Id was only here to get attachments + marineLitterBatch.setId((String) null); + persistenceService.createMarineLitterBatch(marineLitterBatch); + + persistAttachments(objectId, attachmentRows); } } @@ -419,13 +455,26 @@ public class GenericformatImportPersitenceHelper { if (fishingOperationContext.withIndividualObservationBatches()) { - FishingOperation fishingOperation = fishingOperationContext.getFishingOperation(); - String fishingOperationId = fishingOperation.getId(); +// FishingOperation fishingOperation = fishingOperationContext.getFishingOperation(); +// String fishingOperationId = fishingOperation.getId(); Collection<IndividualObservationBatch> individualObservationBatches = fishingOperationContext.getIndividualObservationBatches(); if (log.isInfoEnabled()) { log.info("Persist " + individualObservationBatches.size() + " individual observation(s) of " + operationStr + " for cruise: " + cruiseStr); } - persistenceService.createIndividualObservationBatches(fishingOperationId, individualObservationBatches); +// persistenceService.createIndividualObservationBatches(fishingOperationId, individualObservationBatches); + + for (IndividualObservationBatch individualObservationBatch : individualObservationBatches) { + + Integer objectId = individualObservationBatch.getIdAsInt(); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(objectId); + + // Id was only here to get attachments + individualObservationBatch.setId((String) null); + + persistenceService.createIndividualObservationBatch(individualObservationBatch); + + persistAttachments(objectId, attachmentRows); + } } @@ -452,13 +501,26 @@ public class GenericformatImportPersitenceHelper { if (fishingOperationContext.withAccidentalBatches()) { - FishingOperation fishingOperation = fishingOperationContext.getFishingOperation(); - String fishingOperationId = fishingOperation.getId(); +// FishingOperation fishingOperation = fishingOperationContext.getFishingOperation(); +// String fishingOperationId = fishingOperation.getId(); Collection<AccidentalBatch> accidentalBatches = fishingOperationContext.getAccidentalBatches(); if (log.isInfoEnabled()) { log.info("Persist " + accidentalBatches.size() + " accidental batch(es) of " + operationStr + " for cruise: " + cruiseStr); } - persistenceService.createAccidentalBatches(fishingOperationId, accidentalBatches); + + for (AccidentalBatch accidentalBatch : accidentalBatches) { + + Integer objectId = accidentalBatch.getIdAsInt(); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(objectId); + + // Id was only here to get attachments + accidentalBatch.setId((String) null); + + persistenceService.createAccidentalBatch(accidentalBatch); + + persistAttachments(objectId, attachmentRows); + + } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAccidentalCatch.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAccidentalCatch.java index 2694a7e..3913e48 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAccidentalCatch.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAccidentalCatch.java @@ -116,6 +116,7 @@ public class CsvConsumerForAccidentalCatch extends CsvComsumer<AccidentalCatchRo batch.setCaracteristics(new CaracteristicMap()); batch.setComment(bean.getComment()); batch.setSpecies(bean.getSpecies()); + batch.setId(bean.getBatchId()); operationContext.addAccidentalBatch(batchId, batch); } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAttachment.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAttachment.java new file mode 100644 index 0000000..c0f16a4 --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForAttachment.java @@ -0,0 +1,29 @@ +package fr.ifremer.tutti.service.genericformat.consumer; + +import fr.ifremer.tutti.service.csv.CsvComsumer; +import fr.ifremer.tutti.service.genericformat.GenericFormatImportEntityParserFactory; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentModel; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; +import org.nuiton.csv.ImportRow; + +import java.nio.file.Path; + +/** + * Created on 3/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class CsvConsumerForAttachment extends CsvComsumer<AttachmentRow, AttachmentModel> { + + public CsvConsumerForAttachment(Path file, char separator, GenericFormatImportEntityParserFactory parserFactory, boolean reportError) { + super(file, AttachmentModel.forImport(separator, parserFactory), reportError); + } + + public void validateRow(ImportRow<AttachmentRow> row) { + + reportError(row); + + } + +} \ No newline at end of file diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForIndividualObservation.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForIndividualObservation.java index b7a7575..33e101b 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForIndividualObservation.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/consumer/CsvConsumerForIndividualObservation.java @@ -116,6 +116,7 @@ public class CsvConsumerForIndividualObservation extends CsvComsumer<IndividualO batch.setCaracteristics(new CaracteristicMap()); batch.setComment(bean.getComment()); batch.setSpecies(bean.getSpecies()); + batch.setId(bean.getBatchId()); operationContext.addIndividualObservationBatch(batchId, batch); } 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 b56bef2..8bfec11 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 @@ -31,6 +31,7 @@ import fr.ifremer.tutti.service.genericformat.GenericFormatImportContext; import fr.ifremer.tutti.service.genericformat.GenericFormatImportCruiseContext; import fr.ifremer.tutti.service.genericformat.GenericformatImportPersitenceHelper; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForOperation; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; import fr.ifremer.tutti.service.genericformat.csv.OperationRow; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,6 +40,7 @@ import org.nuiton.csv.ImportRuntimeException; import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.IOException; +import java.util.Collection; import static org.nuiton.i18n.I18n.t; @@ -81,10 +83,13 @@ public class ImportOperationAction extends ImportActionSupport { OperationRow bean = row.getBean(); + Collection<AttachmentRow> operationAttachmentRows = importContext.popAttachmentRows(bean.getFishingOperationObjectId()); + Collection<AttachmentRow> catchAttachmentRows = importContext.popAttachmentRows(bean.getCatchObjectId()); + FishingOperation fishingOperation = bean.getFishingOperation(); CatchBatch catchBatch = bean.getCatchBatch(); - persitenceHelper.persistFishingOperation(cruiseContext, fishingOperation, catchBatch); + persitenceHelper.persistFishingOperation(cruiseContext, fishingOperation, catchBatch, operationAttachmentRows, catchAttachmentRows); } } catch (IOException e) { 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 a293b1d..84a737b 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 @@ -28,6 +28,7 @@ import fr.ifremer.tutti.service.genericformat.GenericFormatCsvFileResult; import fr.ifremer.tutti.service.genericformat.GenericFormatImportContext; import fr.ifremer.tutti.service.genericformat.GenericformatImportPersitenceHelper; import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForSurvey; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; import fr.ifremer.tutti.service.genericformat.csv.SurveyRow; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,6 +37,7 @@ import org.nuiton.csv.ImportRuntimeException; import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.IOException; +import java.util.Collection; import static org.nuiton.i18n.I18n.t; @@ -79,7 +81,9 @@ public class ImportSurveyAction extends ImportActionSupport { consumer.validateRow(row, importContext); consumer.prepareRowForPersist(row); - persitenceHelper.persistCruise(row.getBean().getCruise()); + SurveyRow bean = row.getBean(); + Collection<AttachmentRow> attachmentRows = importContext.popAttachmentRows(bean.getObjectId()); + persitenceHelper.persistCruise(bean.getCruise(), attachmentRows); } } catch (IOException e) { 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 new file mode 100644 index 0000000..1d81fcc --- /dev/null +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/importactions/LoadAttachmentsAction.java @@ -0,0 +1,80 @@ +package fr.ifremer.tutti.service.genericformat.importactions; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import fr.ifremer.tutti.service.genericformat.GenericFormatContextSupport; +import fr.ifremer.tutti.service.genericformat.GenericFormatCsvFileResult; +import fr.ifremer.tutti.service.genericformat.consumer.CsvConsumerForAttachment; +import fr.ifremer.tutti.service.genericformat.csv.AttachmentRow; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.csv.ImportRow; +import org.nuiton.csv.ImportRuntimeException; +import org.nuiton.jaxx.application.ApplicationTechnicalException; + +import java.io.IOException; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 3/26/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.14.3 + */ +public class LoadAttachmentsAction extends ImportActionSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(LoadAttachmentsAction.class); + + public LoadAttachmentsAction(GenericFormatContextSupport importContext) { + super(importContext); + } + + @Override + protected boolean canExecute() { + return true; + } + + @Override + protected void doExecute() { + + if (log.isInfoEnabled()) { + log.info("Load attachments definitions."); + } + + importContext.increments(t("tutti.service.genericFormat.load.attachments")); + + GenericFormatCsvFileResult importFileResult = importContext.getAttachmentFileResult(); + try (CsvConsumerForAttachment consumer = importContext.loadAttachments(false)) { + + Multimap<Integer, AttachmentRow> attachmentRowsByObjectId = ArrayListMultimap.create(); + + for (ImportRow<AttachmentRow> row : consumer) { + + consumer.validateRow(row); + + if (row.isValid()) { + + AttachmentRow bean = row.getBean(); + attachmentRowsByObjectId.put(bean.getObjectId(), bean); + + } + + } + + importFileResult.flushErrors(consumer); + + importContext.setAttachmentRows(attachmentRowsByObjectId); + + } catch (IOException e) { + throw new ApplicationTechnicalException("Could not close sampleCategory.csv file", e); + } catch (ImportRuntimeException e) { + + importFileResult.addGlobalError(e.getMessage()); + + } + + } + +} \ No newline at end of file diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSurvey.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSurvey.java index 8c47b55..910ec4d 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSurvey.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/producer/CsvProducerForSurvey.java @@ -48,6 +48,7 @@ public class CsvProducerForSurvey extends CsvProducer<SurveyRow, SurveyModel> { SurveyRow row = new SurveyRow(); row.setCruise(cruise); + row.setObjectId(cruise.getIdAsInt()); row.setCountry(country); return row; diff --git a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties index f44c1fe..cf00e44 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties @@ -208,6 +208,7 @@ tutti.service.genericFormat.importError.archiveNotSane= tutti.service.genericFormat.importError.missArchiveFile= tutti.service.genericFormat.invalid.cruise= tutti.service.genericFormat.invalid.fishingOperation= +tutti.service.genericFormat.load.attachments= tutti.service.genericFormat.load.protocol= tutti.service.genericFormat.persist.cruise= tutti.service.genericFormat.persist.gearCaracteristics= diff --git a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties index cdf4a1b..81aea77 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties @@ -167,6 +167,7 @@ tutti.service.genericFormat.importError.archiveNotSane=L'archive ne respecte pas tutti.service.genericFormat.importError.missArchiveFile=Il manque le fichier %s dans l'archive tutti.service.genericFormat.invalid.cruise=Erreur d'élévation de poids sur les traits de la campagne %s \:<ul>%s</ul> tutti.service.genericFormat.invalid.fishingOperation=<li>L'élévation des poids ne peut pas être réalisée sur le trait %s, pour la raison suivante \:<ul><li>%s</li></ul></li> +tutti.service.genericFormat.load.attachments= tutti.service.genericFormat.load.protocol=Import du protocol tutti.service.genericFormat.persist.cruise=Sauvegarde de la campagne <strong>%s</strong> tutti.service.genericFormat.persist.gearCaracteristics=Sauvegarde des caractéristiques des engins de la campagne <strong>%s</strong> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 b53e9a70035870da94608926a9bd7bfb9063df6d Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 16:24:58 2015 +0100 fix typo --- .../src/main/resources/i18n/tutti-ui-swing_fr_FR.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties index f68ad71..cde4cf8 100644 --- a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties +++ b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties @@ -92,7 +92,7 @@ tutti.common.file.tuttiCatch=Fichier d'import/export des poids de capture tutti.common.file.tuttiIndividualObservation=Fichier d'import/export des lots d'observations individuelles tutti.common.file.tuttiMarineLitter=Fichier d'import/export des lots de déchets tutti.common.file.tuttiSpecies=Fichier d'import/export des lots d'espèces -tutti.common.file.zip= +tutti.common.file.zip=Fichier zip tutti.common.referential.gear=Engin tutti.common.referential.person=utilisateur tutti.common.referential.species=Espèce @@ -149,7 +149,7 @@ tutti.config.option.ui.config.file.shortLabel=Chemin du fichier de confirmation tutti.config.option.ui.coordinateEditorType.shortLabel=Formateur de coordonnées tutti.config.option.ui.dateFormat.shortLabel=Format des dates tutti.config.option.ui.fullBluetoothScan.shortLabel=Recherche complète des périphériques bluetooth -tutti.config.option.ui.genericFormat.import.skipBackup.shortLabel=Ne pas faire de sauvegarde avant un import au format génriqugénérique +tutti.config.option.ui.genericFormat.import.skipBackup.shortLabel=Ne pas faire de sauvegarde avant un import au format générique tutti.config.option.ui.individualObservationRowsToCreate.shortLabel=Nombre max de données individuelles tutti.config.option.ui.showBatchLog.shortLabel=Voir la structure des lots dans les logs tutti.config.option.update.application.url.shortLabel=URL de mise à jour des applicatifs -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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 ded5f75bbcbda4cb94469546380151cd44dc0c95 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 18:21:46 2015 +0100 delete pj before deleting catch batch --- .../service/FishingOperationPersistenceServiceImpl.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java index 7d8fcc2..0b556f3 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/FishingOperationPersistenceServiceImpl.java @@ -521,6 +521,11 @@ public class FishingOperationPersistenceServiceImpl extends AbstractPersistenceS throw new DataRetrievalFailureException("Could not retrieve fishing operation with id=" + fishingOperationId); } + attachmentPersistenceService.deleteAllAttachment( + ObjectTypeCode.OPERATION, + fishingOperationId); + getCurrentSession().flush(); + // delete catch batch catchBatchService.deleteCatchBatch(id); getCurrentSession().flush(); @@ -619,9 +624,9 @@ public class FishingOperationPersistenceServiceImpl extends AbstractPersistenceS getCurrentSession().flush(); - attachmentPersistenceService.deleteAllAttachment( - ObjectTypeCode.OPERATION, - fishingOperationId); +// attachmentPersistenceService.deleteAllAttachment( +// ObjectTypeCode.OPERATION, +// fishingOperationId); } //------------------------------------------------------------------------// -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
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>.
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 3cbcdc3f96f32ecd7abc3c19ae33119b622c3d4c Merge: 41ae140 2e3fee3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Mar 27 18:22:18 2015 +0100 fixes #6820: [IMPORT GENERIQUE] Import des pièces jointes Merge branch 'feature/6820' into develop .../tutti/persistence/entities/data/Cruises.java | 18 ++- .../service/AttachmentPersistenceServiceImpl.java | 26 +++- .../FishingOperationPersistenceServiceImpl.java | 11 +- .../service/util/BatchPersistenceHelper.java | 1 + .../genericformat/GenericFormatArchive.java | 148 +++++++-------------- .../genericformat/GenericFormatContextSupport.java | 33 ++++- .../GenericFormatImportOperationContext.java | 15 +++ .../genericformat/GenericFormatImportService.java | 3 + .../GenericformatImportPersitenceHelper.java | 96 +++++++++++-- .../consumer/CsvConsumerForAccidentalCatch.java | 1 + .../consumer/CsvConsumerForAttachment.java | 29 ++++ .../consumer/CsvConsumerForCatch.java | 12 +- .../CsvConsumerForIndividualObservation.java | 1 + .../service/genericformat/csv/AttachmentRow.java | 12 ++ .../service/genericformat/csv/CatchModel.java | 4 +- .../genericformat/csv/ExportSampleCategory.java | 6 +- .../genericformat/csv/MarineLitterModel.java | 4 +- .../service/genericformat/csv/MarineLitterRow.java | 10 +- .../service/genericformat/csv/OperationModel.java | 8 +- .../service/genericformat/csv/OperationRow.java | 26 ++-- .../service/genericformat/csv/SurveyModel.java | 4 +- .../tutti/service/genericformat/csv/SurveyRow.java | 12 +- .../importactions/ImportOperationAction.java | 8 +- .../importactions/ImportSurveyAction.java | 7 +- .../importactions/LoadAttachmentsAction.java | 80 +++++++++++ .../producer/CsvProducerForSurvey.java | 1 + .../resources/i18n/tutti-service_en_GB.properties | 1 + .../resources/i18n/tutti-service_fr_FR.properties | 1 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 4 +- 29 files changed, 420 insertions(+), 162 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm