This is an automated email from the git hooks/post-receive script. New commit to branch feature/6688 in repository tutti. See http://git.codelutin.com/tutti.git commit 0a5891a8342ca13bf8a4c2300d31df90166b1f2c Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Feb 23 09:01:05 2015 +0100 - amélioration du calcul du nombre d'étapes - mise en place de la progression - amélioration de l'API de requete et resultat --- .../genericformat/GenericFormatArchive.java | 44 ++++ .../GenericFormatImportCruiseContext.java | 16 +- .../GenericFormatImportCruiseResult.java | 3 +- .../genericformat/GenericFormatImportRequest.java | 17 +- .../genericformat/GenericFormatImportResult.java | 9 +- .../genericformat/GenericFormatImportService.java | 71 +++--- .../GenericformatImportPersitenceHelper.java | 270 +++++++++++---------- .../resources/i18n/tutti-service_en_GB.properties | 12 + .../resources/i18n/tutti-service_fr_FR.properties | 16 +- 9 files changed, 272 insertions(+), 186 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 9498c46..30c465a 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 @@ -10,9 +10,12 @@ import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.jaxx.application.ApplicationIOUtil; import org.nuiton.jaxx.application.ApplicationTechnicalException; +import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.LineNumberReader; +import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -203,6 +206,47 @@ public class GenericFormatArchive { return getPath(ArchiveFilePath.DATA_MARINE_LITTER); } + public int getNbCruisesFromFile() { + + Path path = getSurveyPath(); + try (BufferedReader bufferedReader = Files.newBufferedReader(path, Charset.forName("UTF-8"))) { + + try (LineNumberReader lineNumberReader = new LineNumberReader(bufferedReader)) { + lineNumberReader.skip(Long.MAX_VALUE); + int result = lineNumberReader.getLineNumber() - 1; + if (result == -1) { + result = 0; + } + return result; + } + + } catch (IOException e) { + throw new ApplicationTechnicalException("Could not read survey.csv file from archive " + archiveFile, e); + } + + } + + public int getNbOperationsFromFile() { + + Path path = getOperationPath(); + + try (BufferedReader bufferedReader = Files.newBufferedReader(path, Charset.forName("UTF-8"))) { + + try (LineNumberReader lineNumberReader = new LineNumberReader(bufferedReader)) { + lineNumberReader.skip(Long.MAX_VALUE); + int result = lineNumberReader.getLineNumber() - 1; + if (result == -1) { + result = 0; + } + return result; + } + + } catch (IOException e) { + throw new ApplicationTechnicalException("Could not read operation.csv file from archive " + archiveFile, e); + } + + } + public void createZip(ProgressionModel progressionModel) { if (progressionModel != null) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseContext.java index 5a1e971..f8d48af 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseContext.java @@ -1,6 +1,6 @@ package fr.ifremer.tutti.service.genericformat; -import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.CatchBatch; @@ -13,6 +13,7 @@ import fr.ifremer.tutti.service.genericformat.csv.RowWithOperationContextSupport import java.io.Closeable; import java.io.Serializable; +import java.util.Collection; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -114,17 +115,8 @@ public class GenericFormatImportCruiseContext implements Closeable { } - - public Iterable<GenericFormatImportOperationContext> getFishingOperationContexts(Predicate<GenericFormatImportOperationContext> predicate) { - - Iterable<GenericFormatImportOperationContext> result; - if (predicate == null) { - result = fishingOperationContexts.values(); - } else { - result = Iterables.filter(fishingOperationContexts.values(), predicate); - } - return result; - + public Collection<GenericFormatImportOperationContext> getFishingOperationContexts() { + return ImmutableList.copyOf(fishingOperationContexts.values()); } public Iterable<FishingOperation> getFishingOperations() { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseResult.java index 51c0d82..886ade5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportCruiseResult.java @@ -35,8 +35,7 @@ public class GenericFormatImportCruiseResult { this.cruise = cruiseContext.getCruise(); this.fishingOperationResults = new HashMap<>(); - Iterable<GenericFormatImportOperationContext> operationContexts = cruiseContext.getFishingOperationContexts(null); - for (GenericFormatImportOperationContext operationContext : operationContexts) { + for (GenericFormatImportOperationContext operationContext : cruiseContext.getFishingOperationContexts()) { GenericFormatImportOperationResult operationResult = new GenericFormatImportOperationResult(operationContext); fishingOperationResults.put(operationContext.getFishingOperation().getId(), operationResult); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportRequest.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportRequest.java index 13af96d..92f06f5 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportRequest.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportRequest.java @@ -1,14 +1,11 @@ package fr.ifremer.tutti.service.genericformat; -import com.google.common.collect.ImmutableSet; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.Cruises; import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; -import fr.ifremer.tutti.service.PersistenceService; -import java.util.List; import java.util.Set; /** @@ -31,19 +28,19 @@ public class GenericFormatImportRequest { private final Program program; - public GenericFormatImportRequest(PersistenceService persistenceService, - GenericFormatArchive archive, + public GenericFormatImportRequest(GenericFormatArchive archive, char csvSeparator, Program program, - SampleCategoryModel sampleCategoryModel) { + SampleCategoryModel sampleCategoryModel, + Set<Cruise> cruises, + TuttiProtocol oldProtocol + ) { this.archive = archive; this.csvSeparator = csvSeparator; this.sampleCategoryModel = sampleCategoryModel; this.program = program; - - List<Cruise> allCruise = persistenceService.getAllCruise(program.getId()); - this.existingCruises = ImmutableSet.copyOf(allCruise); - this.oldProtocol = persistenceService.getProtocol(); + this.existingCruises = cruises; + this.oldProtocol = oldProtocol; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportResult.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportResult.java index 251d58d..2a87b5e 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportResult.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/genericformat/GenericFormatImportResult.java @@ -39,10 +39,11 @@ public class GenericFormatImportResult { private final GenericFormatReferentialImportResult<Vessel, String> importedVessels; - private final GenericFormatImportRequest importRequest; + private final GenericFormatArchive archive; public GenericFormatImportResult(GenericFormatImportContext importContext) { - this.importRequest = importContext.getImportRequest(); + + this.archive = importContext.getImportRequest().getArchive(); this.cruiseResults = new LinkedHashMap<>(); this.errors = new LinkedHashSet<>(); this.protocol = importContext.getImportedProtocol(); @@ -53,8 +54,8 @@ public class GenericFormatImportResult { } - public GenericFormatImportRequest getImportRequest() { - return importRequest; + public GenericFormatArchive getArchive() { + return archive; } public Set<Cruise> getImportedCruises() { 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 ba129f5..51fd6c8 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 @@ -1,8 +1,10 @@ package fr.ifremer.tutti.service.genericformat; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; import fr.ifremer.tutti.persistence.ProgressionModel; 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.Program; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; @@ -50,10 +52,6 @@ import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.File; import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; import java.util.Map; import java.util.Set; @@ -83,27 +81,38 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { public int getImportProgramNbSteps(File importFile) { - // nbCruise * (check cruise / export cruise / gear caracteristics / operation / parameter / catches / individual observation / accidental catches / marine litters) + - // (species + sampleCategoryModel + protocol + temporary gear + temporary person + temporar species + temporary vessel + zip) - GenericFormatArchive archive = GenericFormatArchive.forImport(importFile, context.getConfig().getTmpDirectory()); - Path surveyPath = archive.getSurveyPath(); - try { + int nbCruises = archive.getNbCruisesFromFile(); + if (log.isInfoEnabled()) { + log.info("Count " + nbCruises + " cruises to import."); + } + int nbOperations = archive.getNbOperationsFromFile(); + if (log.isInfoEnabled()) { + log.info("Count " + nbOperations + " operations to import."); + } + int result = 6 // check sampleCategoryModel + import ( gear + person + species + vessel + protocol ) + + 1 + nbCruises // load cruises + nbCruise * persist cruise + + 1 + nbCruises // load gear caracteristics + nbCruise * persist gear caracteristics + + 1 + nbOperations // load operations + nbOperations * persist operation + + 1 + nbOperations // load parameters + nbOperations * persist parameters + + 1 + nbOperations * 2 // load catches + nbOperations * persist (species batches + benthos batches) + + 1 + nbOperations // load marine litters + nbOperations * persist marine litters + + 1 + nbOperations // load individualObservations + nbOperations * persist individualObservations + + 1 + nbOperations // load accidental catches + nbOperations * persist accidental catches + + nbOperations // nbOperations * cleanWeights + + nbOperations // nbOperations * checkWeights + + 1; // compute report - List<String> allCruise = Files.readAllLines(surveyPath, Charset.forName("UTF-8")); - int result = 9 * allCruise.size() - 1 + 8; - return result; + return result; - } catch (IOException e) { - throw new ApplicationTechnicalException("Could not read survey.csv file from archive " + importFile, e); - } } public GenericFormatImportResult importProgram(String programId, File importFile, ProgressionModel progressionModel) { Preconditions.checkNotNull(programId); Preconditions.checkNotNull(importFile); + Preconditions.checkNotNull(progressionModel); Program program = persistenceService.getProgram(programId); Preconditions.checkNotNull(program); @@ -116,7 +125,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { GenericFormatImportResult result = doImport(archive, program, progressionModel); - computeReport(result); + computeReport(result, progressionModel); return result; @@ -124,11 +133,14 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { protected GenericFormatImportResult doImport(GenericFormatArchive archive, Program program, ProgressionModel progressionModel) { - GenericFormatImportRequest request = new GenericFormatImportRequest(persistenceService, - archive, + Set<Cruise> cruises = ImmutableSet.copyOf(persistenceService.getAllCruise(program.getId())); + TuttiProtocol protocol = persistenceService.getProtocol(); + GenericFormatImportRequest request = new GenericFormatImportRequest(archive, ';', program, - context.getSampleCategoryModel()); + context.getSampleCategoryModel(), + cruises, + protocol); try (GenericFormatImportContext importContext = new GenericFormatImportContext(request, progressionModel, persistenceService, cruiseDecorator, fishingOperationDecorator)) { @@ -151,7 +163,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { importAccidentalCatches(importContext, persitenceHelper); doCleanWeights(importContext); - doCheckCruises(importContext); + doCheckWeights(importContext); GenericFormatImportResult result = new GenericFormatImportResult(importContext); return result; @@ -160,9 +172,10 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } - protected void computeReport(GenericFormatImportResult result) { + protected void computeReport(GenericFormatImportResult result, ProgressionModel progressionModel) { //TODO Compute report + progressionModel.increments(t("tutti.service.genericFormat.import.computeReport")); } @@ -368,7 +381,6 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { protected void importProtocol(GenericFormatImportContext importContext) { - importContext.increments(t("tutti.service.genericFormat.load.protocol")); GenericFormatArchive archive = importContext.getImportRequest().getArchive(); if (archive.isProtocolExists()) { @@ -397,6 +409,8 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { log.info("Skip import protocol (no file found)."); } + importContext.increments(t("tutti.service.genericFormat.skip.import.protocol")); + } } @@ -462,7 +476,7 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { FishingOperation fishingOperation = bean.getFishingOperation(); CatchBatch catchBatch = bean.getCatchBatch(); - persitenceHelper.persistFishingOperation(fishingOperation, catchBatch); + persitenceHelper.persistFishingOperation(cruiseContext, fishingOperation, catchBatch); } } catch (IOException e) { @@ -527,7 +541,6 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { for (ImportRow<MarineLitterRow> row : consumer) { GenericFormatImportOperationContext operationContext = consumer.validateRow(row, importContext); - consumer.prepareRowForPersist(operationContext, row); } @@ -590,9 +603,9 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { @Override public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - for (GenericFormatImportOperationContext operationContext : cruiseContext.getFishingOperationContexts(null)) { + for (GenericFormatImportOperationContext operationContext : cruiseContext.getFishingOperationContexts()) { - progressionModel.increments(t("tutti.service.genericFormat.cleanWeights.fishingOperation", operationContext.getFishingOperationLabel())); + progressionModel.increments(t("tutti.service.genericFormat.cleanWeights.fishingOperation", cruiseContext.getCruiseLabel(), operationContext.getFishingOperationLabel())); weightCleaningService.cleanFishingOperation(operationContext.getFishingOperation().getId()); @@ -603,16 +616,16 @@ public class GenericFormatImportService extends GenericFormatServiceSupport { } - protected void doCheckCruises(GenericFormatImportContext importContext) { + protected void doCheckWeights(GenericFormatImportContext importContext) { importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { @Override public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - for (GenericFormatImportOperationContext operationContext : cruiseContext.getFishingOperationContexts(null)) { + for (GenericFormatImportOperationContext operationContext : cruiseContext.getFishingOperationContexts()) { - progressionModel.increments(t("tutti.service.genericFormat.checkWeights.fishingOperation", operationContext.getFishingOperationLabel())); + progressionModel.increments(t("tutti.service.genericFormat.checkWeights.fishingOperation", cruiseContext.getCruiseLabel(), operationContext.getFishingOperationLabel())); Set<String> errors = checkFishingOperation(operationContext.getFishingOperation().getId()); operationContext.addCheckErrors(errors); 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 fd96423..34019fd 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 @@ -1,6 +1,5 @@ package fr.ifremer.tutti.service.genericformat; -import com.google.common.base.Predicate; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.CaracteristicMap; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; @@ -24,6 +23,8 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import static org.nuiton.i18n.I18n.t; + /** * Created on 2/19/15. * @@ -52,9 +53,11 @@ public class GenericformatImportPersitenceHelper { public void persistCruise(Cruise cruise) { + String cruiseStr = cruiseDecorator.toString(cruise); if (log.isInfoEnabled()) { - log.info("Persist cruise: " + cruiseDecorator.toString(cruise)); + log.info("Persist cruise: " + cruiseStr); } + importContext.increments(t("tutti.service.genericFormat.persist.cruise", cruiseStr)); Cruise savedCruise = persistenceService.createCruise(cruise); importContext.addImportedCruise(savedCruise); @@ -67,6 +70,8 @@ public class GenericformatImportPersitenceHelper { @Override public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { + importContext.increments(t("tutti.service.genericFormat.persist.gearCaracteristics", cruiseContext.getCruiseLabel())); + if (cruiseContext.withGearCaracteristics()) { Set<Gear> gears = cruiseContext.getGearsWithcaracteristics(); @@ -89,12 +94,14 @@ public class GenericformatImportPersitenceHelper { } - public void persistFishingOperation(FishingOperation fishingOperation, CatchBatch catchBatch) { + public void persistFishingOperation(GenericFormatImportCruiseContext cruiseContext, FishingOperation fishingOperation, CatchBatch catchBatch) { + String operationStr = fishingOperationDecorator.toString(fishingOperation); + String cruiseStr = cruiseContext.getCruiseLabel(); if (log.isInfoEnabled()) { - log.info("Persist fishing Operation: " + fishingOperationDecorator.toString(fishingOperation) + " for cruise: " + cruiseDecorator.toString(fishingOperation.getCruise())); + log.info("Persist fishing Operation: " + operationStr + " for cruise: " + cruiseStr); } - + importContext.increments(t("tutti.service.genericFormat.persist.operation", cruiseStr, operationStr)); FishingOperation createdFishingOperation = persistenceService.createFishingOperation(fishingOperation); catchBatch.setFishingOperation(createdFishingOperation); @@ -111,14 +118,14 @@ public class GenericformatImportPersitenceHelper { @Override public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - Iterable<GenericFormatImportOperationContext> fishingOperationContexts = cruiseContext.getFishingOperationContexts(new Predicate<GenericFormatImportOperationContext>() { - @Override - public boolean apply(GenericFormatImportOperationContext input) { - return input.withGearFeatures() || input.withVesselFeatures(); - } - }); + for (GenericFormatImportOperationContext fishingOperationContext : cruiseContext.getFishingOperationContexts()) { + + String cruiseStr = cruiseContext.getCruiseLabel(); + String operationStr = fishingOperationContext.getFishingOperationLabel(); - for (GenericFormatImportOperationContext fishingOperationContext : fishingOperationContexts) { + importContext.increments(t("tutti.service.genericFormat.persist.operation.parameters", cruiseStr, operationStr)); + + boolean persist = false; FishingOperation fishingOperation = fishingOperationContext.getFishingOperation(); @@ -127,9 +134,11 @@ public class GenericformatImportPersitenceHelper { CaracteristicMap gearUseFeatures = fishingOperationContext.getGearUseFeatures(); fishingOperation.setGearUseFeatures(gearUseFeatures); if (log.isInfoEnabled()) { - log.info("Persist " + gearUseFeatures.size() + " gear use features of " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); + log.info("Persist " + gearUseFeatures.size() + " gear use features of " + operationStr + " for cruise: " + cruiseStr); } + persist = true; + } if (fishingOperationContext.withVesselFeatures()) { @@ -137,112 +146,20 @@ public class GenericformatImportPersitenceHelper { CaracteristicMap vesselUseFeatures = fishingOperationContext.getVesselUseFeatures(); fishingOperation.setVesselUseFeatures(vesselUseFeatures); if (log.isInfoEnabled()) { - log.info("Persist " + vesselUseFeatures.size() + " vessel use features of " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); + log.info("Persist " + vesselUseFeatures.size() + " vessel use features of " + operationStr + " for cruise: " + cruiseStr); } - } - - persistenceService.saveFishingOperation(fishingOperation); - - } - } - }); - - } - - public void persistMarineLitterBatches() { - - importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { + persist = true; - @Override - public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - - Iterable<GenericFormatImportOperationContext> fishingOperationContexts = cruiseContext.getFishingOperationContexts(new Predicate<GenericFormatImportOperationContext>() { - @Override - public boolean apply(GenericFormatImportOperationContext input) { - return input.withMarineLitterBatches(); - } - }); - - for (GenericFormatImportOperationContext fishingOperationContext : fishingOperationContexts) { - -// FishingOperation fishingOperation = fishingOperationContext.getFishingOperation(); -// String fishingOperationId = fishingOperation.getId(); - Collection<MarineLitterBatch> marineLitterBatches = fishingOperationContext.getMarineLitterBatches(); - if (log.isInfoEnabled()) { - log.info("Persist " + marineLitterBatches.size() + " marine litter(s) of " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); - } - //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) { - persistenceService.createMarineLitterBatch(marineLitterBatch); } - } + if (persist) { - } - }); + persistenceService.saveFishingOperation(fishingOperation); - } - - public void persistAccidentalBatches() { - - importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { - - @Override - public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - - Iterable<GenericFormatImportOperationContext> fishingOperationContexts = cruiseContext.getFishingOperationContexts(new Predicate<GenericFormatImportOperationContext>() { - @Override - public boolean apply(GenericFormatImportOperationContext input) { - return input.withAccidentalBatches(); } - }); - - for (GenericFormatImportOperationContext fishingOperationContext : fishingOperationContexts) { - - 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 " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); - } - persistenceService.createAccidentalBatches(fishingOperationId, accidentalBatches); } - - } - }); - - - } - - public void persistIndividualObservationBatches() { - - importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { - - @Override - public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - - Iterable<GenericFormatImportOperationContext> fishingOperationContexts = cruiseContext.getFishingOperationContexts(new Predicate<GenericFormatImportOperationContext>() { - @Override - public boolean apply(GenericFormatImportOperationContext input) { - return input.withIndividualObservationBatches(); - } - }); - - for (GenericFormatImportOperationContext fishingOperationContext : fishingOperationContexts) { - - 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 " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); - } - persistenceService.createIndividualObservationBatches(fishingOperationId, individualObservationBatches); - - } - } }); @@ -255,20 +172,18 @@ public class GenericformatImportPersitenceHelper { @Override public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - Iterable<GenericFormatImportOperationContext> fishingOperationContexts = cruiseContext.getFishingOperationContexts(new Predicate<GenericFormatImportOperationContext>() { - @Override - public boolean apply(GenericFormatImportOperationContext input) { - return input.withSpeciesBatches(true) || input.withSpeciesBatches(false); - } - }); + for (GenericFormatImportOperationContext fishingOperationContext : cruiseContext.getFishingOperationContexts()) { - for (GenericFormatImportOperationContext fishingOperationContext : fishingOperationContexts) { + String cruiseStr = cruiseContext.getCruiseLabel(); + String operationStr = fishingOperationContext.getFishingOperationLabel(); + + importContext.increments(t("tutti.service.genericFormat.persist.operation.speciesBatches", cruiseStr, operationStr)); if (fishingOperationContext.withSpeciesBatches(true)) { Collection<SpeciesBatch> batches = fishingOperationContext.getSpeciesBatches(true); if (log.isInfoEnabled()) { - log.info("Persist " + batches.size() + " VRAC root species batch(es) of " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); + log.info("Persist " + batches.size() + " VRAC root species batch(es) of " + operationStr + " for cruise: " + cruiseStr); } persistSpeciesBatches(fishingOperationContext, batches, null); @@ -278,7 +193,7 @@ public class GenericformatImportPersitenceHelper { Collection<SpeciesBatch> batches = fishingOperationContext.getSpeciesBatches(false); if (log.isInfoEnabled()) { - log.info("Persist " + batches.size() + " HORS VRAC root species batch(es) of " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); + log.info("Persist " + batches.size() + " HORS VRAC root species batch(es) of " + operationStr + " for cruise: " + cruiseStr); } persistSpeciesBatches(fishingOperationContext, batches, null); @@ -330,20 +245,18 @@ public class GenericformatImportPersitenceHelper { @Override public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { - Iterable<GenericFormatImportOperationContext> fishingOperationContexts = cruiseContext.getFishingOperationContexts(new Predicate<GenericFormatImportOperationContext>() { - @Override - public boolean apply(GenericFormatImportOperationContext input) { - return input.withBenthosBatches(true) || input.withBenthosBatches(false); - } - }); + for (GenericFormatImportOperationContext fishingOperationContext : cruiseContext.getFishingOperationContexts()) { - for (GenericFormatImportOperationContext fishingOperationContext : fishingOperationContexts) { + String cruiseStr = cruiseContext.getCruiseLabel(); + String operationStr = fishingOperationContext.getFishingOperationLabel(); + + importContext.increments(t("tutti.service.genericFormat.persist.operation.benthosBatches", cruiseStr, operationStr)); if (fishingOperationContext.withBenthosBatches(true)) { Collection<BenthosBatch> batches = fishingOperationContext.getBenthosBatches(true); if (log.isInfoEnabled()) { - log.info("Persist " + batches.size() + " VRAC benthos batch(es) of " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); + log.info("Persist " + batches.size() + " VRAC benthos batch(es) of " + operationStr + " for cruise: " + cruiseStr); } persistBenthosBatches(fishingOperationContext, batches, null); @@ -353,7 +266,7 @@ public class GenericformatImportPersitenceHelper { Collection<BenthosBatch> batches = fishingOperationContext.getBenthosBatches(false); if (log.isInfoEnabled()) { - log.info("Persist " + batches.size() + " HORS VRAC benthos batch(es) of " + fishingOperationContext.getFishingOperationLabel() + " for cruise: " + cruiseContext.getCruiseLabel()); + log.info("Persist " + batches.size() + " HORS VRAC benthos batch(es) of " + operationStr + " for cruise: " + cruiseContext.getCruiseLabel()); } persistBenthosBatches(fishingOperationContext, batches, null); @@ -396,4 +309,107 @@ public class GenericformatImportPersitenceHelper { } + public void persistMarineLitterBatches() { + + importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { + + @Override + public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { + + for (GenericFormatImportOperationContext fishingOperationContext : cruiseContext.getFishingOperationContexts()) { + + String cruiseStr = cruiseContext.getCruiseLabel(); + String operationStr = fishingOperationContext.getFishingOperationLabel(); + + importContext.increments(t("tutti.service.genericFormat.persist.operation.marineLitters", cruiseStr, operationStr)); + + if (fishingOperationContext.withMarineLitterBatches()) { + +// FishingOperation fishingOperation = fishingOperationContext.getFishingOperation(); +// String fishingOperationId = fishingOperation.getId(); + Collection<MarineLitterBatch> marineLitterBatches = fishingOperationContext.getMarineLitterBatches(); + if (log.isInfoEnabled()) { + log.info("Persist " + marineLitterBatches.size() + " marine litter(s) of " + operationStr + " for cruise: " + cruiseStr); + } + //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) { + persistenceService.createMarineLitterBatch(marineLitterBatch); + } + + } + + } + + } + }); + + } + + public void persistIndividualObservationBatches() { + + importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { + + @Override + public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { + + for (GenericFormatImportOperationContext fishingOperationContext : cruiseContext.getFishingOperationContexts()) { + + String cruiseStr = cruiseContext.getCruiseLabel(); + String operationStr = fishingOperationContext.getFishingOperationLabel(); + + importContext.increments(t("tutti.service.genericFormat.persist.operation.individualObservations", cruiseStr, operationStr)); + + if (fishingOperationContext.withIndividualObservationBatches()) { + + 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); + + } + + } + + } + }); + + } + + public void persistAccidentalBatches() { + + importContext.doActionOnCruiseContexts(new GenericFormatImportContext.CruiseContextAction() { + + @Override + public void onCruise(GenericFormatImportCruiseContext cruiseContext, ProgressionModel progressionModel) { + + for (GenericFormatImportOperationContext fishingOperationContext : cruiseContext.getFishingOperationContexts()) { + + String cruiseStr = cruiseContext.getCruiseLabel(); + String operationStr = fishingOperationContext.getFishingOperationLabel(); + + importContext.increments(t("tutti.service.genericFormat.persist.operation.accidentalBatches", cruiseStr, operationStr)); + + if (fishingOperationContext.withAccidentalBatches()) { + + 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); + + } + + } + + } + }); + + } + } 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 7e0d908..58da369 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 @@ -121,6 +121,7 @@ tutti.service.exportSumatraV2.header.totalWeight=TotalWeight tutti.service.exportSumatraV2.header.year=Year tutti.service.genericFormat.checkCruise= tutti.service.genericFormat.checkCruiseFishingOperation= +tutti.service.genericFormat.checkWeights.fishingOperation= tutti.service.genericFormat.cleanWeights.fishingOperation= tutti.service.genericFormat.export.accidentalCatch.error= tutti.service.genericFormat.export.buildZip= @@ -169,6 +170,7 @@ tutti.service.genericFormat.exportCruise.exportSpecies= tutti.service.genericFormat.exportCruise.exportSurvey= tutti.service.genericFormat.import.accidentalCatches= tutti.service.genericFormat.import.catches= +tutti.service.genericFormat.import.computeReport= tutti.service.genericFormat.import.cruises= tutti.service.genericFormat.import.error.cruiseAlreadyExist= tutti.service.genericFormat.import.error.cruiseAlreadyImported= @@ -200,7 +202,17 @@ tutti.service.genericFormat.importError.missArchiveFile= tutti.service.genericFormat.invalid.cruise= tutti.service.genericFormat.invalid.fishingOperation= tutti.service.genericFormat.load.protocol= +tutti.service.genericFormat.persist.cruise= +tutti.service.genericFormat.persist.gearCaracteristics= +tutti.service.genericFormat.persist.operation= +tutti.service.genericFormat.persist.operation.accidentalBatches= +tutti.service.genericFormat.persist.operation.benthosBatches= +tutti.service.genericFormat.persist.operation.individualObservations= +tutti.service.genericFormat.persist.operation.marineLitters= +tutti.service.genericFormat.persist.operation.parameters= +tutti.service.genericFormat.persist.operation.speciesBatches= tutti.service.genericFormat.reuse.protocol= +tutti.service.genericFormat.skip.import.protocol= tutti.service.multipost.attachment.copy.error= tutti.service.multipost.attachment.mkdir.error= tutti.service.multipost.export.attachments.error= 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 110431d..860aeb9 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 @@ -97,7 +97,8 @@ tutti.service.exportSumatra.header.weight=total tutti.service.exportSumatra.header.year=annee tutti.service.genericFormat.checkCruise=Vérification de la campagne %s tutti.service.genericFormat.checkCruiseFishingOperation=Vérification de la campagne <strong>%s</strong> ( trait <strong>%s</strong> ) -tutti.service.genericFormat.cleanWeights.fishingOperation=Suppression des poids en double pour l'opération %s +tutti.service.genericFormat.checkWeights.fishingOperation=Vérification des poids du trait <strong>%s</strong> - <strong>%s</strong> +tutti.service.genericFormat.cleanWeights.fishingOperation=Suppression des poids en double du trait <strong>%s</strong> - <strong>%s</strong> tutti.service.genericFormat.export.accidentalCatch.error=Erreur lors de l'export des captures accidentelles tutti.service.genericFormat.export.buildZip=Création de l'archive de l'export (fichier %s) tutti.service.genericFormat.export.catches.error=Erreur lors de l'export des captures @@ -132,11 +133,12 @@ tutti.service.genericFormat.exportCruise.exportSpecies=<html>Export de la campag tutti.service.genericFormat.exportCruise.exportSurvey=<html>Export de la campagne <strong>%s</strong></html> tutti.service.genericFormat.import.accidentalCatches=Import des captures accidentelles tutti.service.genericFormat.import.catches=Import des captures +tutti.service.genericFormat.import.computeReport=Génération du rapport d'import tutti.service.genericFormat.import.cruises=Import des campagnes tutti.service.genericFormat.import.error.cruiseAlreadyExist=Il existe déjà une campagne avec ce nom %s tutti.service.genericFormat.import.error.cruiseAlreadyImported=La campagne avec ce nom %s a déjà été importée tutti.service.genericFormat.import.error.cruiseNotFound=La campagne (année\: %s, série\: %s, série partielle %s) n'existe pas -tutti.service.genericFormat.import.error.cruiseNotValid= +tutti.service.genericFormat.import.error.cruiseNotValid=La campagne n'est pas valide \: %s tutti.service.genericFormat.import.error.fishingOperationAlreadyImported=Un trait %s - %s - %s -%s a déjà été importé dans la campagne %s tutti.service.genericFormat.import.error.fishingOperationNotFoundInCruise=Le trait %s - %s - %s -%s n'existe pas dans la campagne %s tutti.service.genericFormat.import.error.fishingOperationNotValid=Le trait n'est pas valide \:\n%s @@ -163,7 +165,17 @@ tutti.service.genericFormat.importError.missArchiveFile=Il manque le fichier %s 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.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> +tutti.service.genericFormat.persist.operation=Sauvegarde du trait <strong>%s</strong> - <strong>%s</strong> +tutti.service.genericFormat.persist.operation.accidentalBatches=Sauvegarde des captures accidentelles du trait <strong>%s</strong> - <strong>%s</strong> +tutti.service.genericFormat.persist.operation.benthosBatches=Sauvegarde des lots benthos du trait <strong>%s</strong> - <strong>%s</strong> +tutti.service.genericFormat.persist.operation.individualObservations=Sauvegarde des observations individuelles du trait <strong>%s</strong> - <strong>%s</strong> +tutti.service.genericFormat.persist.operation.marineLitters=Sauvegarde des macro-déchets du trait <strong>%s</strong> - <strong>%s</strong> +tutti.service.genericFormat.persist.operation.parameters=Sauvegarde des caractéristiques du trait <strong>%s</strong> - <strong>%s</strong> +tutti.service.genericFormat.persist.operation.speciesBatches=Sauvegarde des lots espèces du trait <strong>%s</strong> - <strong>%s</strong> tutti.service.genericFormat.reuse.protocol=Réutilisation du protocol existant %s +tutti.service.genericFormat.skip.import.protocol=Pas de protocole à importer tutti.service.multipost.attachment.copy.error=Erreur lors de l'export de la pièce-jointe %s tutti.service.multipost.attachment.mkdir.error=Impossible de créer le répertoire %s tutti.service.multipost.export.attachments.error=Erreur lors de l'export des pièces-jointes -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.