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 bf3128ec0c789a547ba14f4392657ccc9727cffd Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Feb 17 16:50:58 2015 +0100 utilisation TaxonCache dans les services --- .../ifremer/tutti/service/PersistenceService.java | 174 +-------------------- .../fr/ifremer/tutti/service/TuttiDataContext.java | 12 +- .../export/pdf/CatchesPdfExportService.java | 163 +++++++------------ .../sumatra/CatchesSumatraExportService.java | 96 +++++++++--- .../toconfirmreport/ToConfirmReportService.java | 18 ++- .../service/psionimport/PsionImportService.java | 10 +- .../service/pupitri/PupitriImportService.java | 73 +++------ 7 files changed, 179 insertions(+), 367 deletions(-) diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java index 2f4c512..67c3413 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java @@ -26,7 +26,6 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import fr.ifremer.adagio.core.dao.referential.ObjectTypeCode; import fr.ifremer.tutti.TuttiConfiguration; @@ -53,6 +52,7 @@ import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocols; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Gears; @@ -69,7 +69,6 @@ import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator; import fr.ifremer.tutti.persistence.service.UpdateSchemaContextSupport; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.AllFileSelector; @@ -89,11 +88,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.concurrent.Callable; import static org.nuiton.i18n.I18n.t; @@ -529,96 +526,6 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer return result; } - public List<Species> getReferentSpeciesWithSurveyCode(List<Species> referentSpecies) { - - List<Species> result; - TuttiProtocol protocol = getProtocol(); - - if (protocol != null) { - // fill available species from protocol - result = Lists.newArrayList(); - if (!protocol.isSpeciesEmpty()) { - - // split by taxonId - Map<String, Species> map = Speciess.splitReferenceSpeciesByReferenceTaxonId(referentSpecies); - - for (SpeciesProtocol protocolSpecy : protocol.getSpecies()) { - String taxonId = String.valueOf(protocolSpecy.getSpeciesReferenceTaxonId()); - Species species = map.get(taxonId); - species.setSurveyCode(protocolSpecy.getSpeciesSurveyCode()); - result.add(species); - } - } - - } else { - - // no protocol, use default values - result = Lists.newArrayList(referentSpecies); - } - - result = Collections.unmodifiableList(result); - - return result; - } - - public List<Species> getReferentBenthosWithSurveyCode(List<Species> referentSpecies) { - List<Species> result; - - TuttiProtocol protocol = getProtocol(); - - if (protocol != null) { - - // fill available species from protocol - - result = Lists.newArrayList(); - if (!protocol.isBenthosEmpty()) { - - // split by taxonId - Map<String, Species> map = Speciess.splitReferenceSpeciesByReferenceTaxonId(referentSpecies); - - for (SpeciesProtocol protocolSpecy : protocol.getBenthos()) { - String taxonId = String.valueOf(protocolSpecy.getSpeciesReferenceTaxonId()); - Species species = map.get(taxonId); - species.setSurveyCode(protocolSpecy.getSpeciesSurveyCode()); - result.add(species); - } - } - - } else { - - // no protocol, use default values - result = Lists.newArrayList(referentSpecies); - } - - result = Collections.unmodifiableList(result); - - return result; - } - - public Map<Integer, SpeciesProtocol> toSpeciesProtocolMap() { - TuttiProtocol protocol = getProtocol(); - Preconditions.checkNotNull(protocol, - "Could not find protocol in ui context"); - - final Map<Integer, SpeciesProtocol> result = Maps.newHashMap(); - for (SpeciesProtocol sp : protocol.getSpecies()) { - result.put(sp.getSpeciesReferenceTaxonId(), sp); - } - return result; - } - - public Map<Integer, SpeciesProtocol> toBenthosProtocolMap() { - TuttiProtocol protocol = getProtocol(); - Preconditions.checkNotNull(protocol, - "Could not find protocol in ui context"); - - final Map<Integer, SpeciesProtocol> result = Maps.newHashMap(); - for (SpeciesProtocol sp : protocol.getBenthos()) { - result.put(sp.getSpeciesReferenceTaxonId(), sp); - } - return result; - } - /** * Return the speciesProtocol corresponding to the species of the given protocol. * @@ -627,7 +534,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer * @since 2.6 */ public SpeciesProtocol getSpeciesProtocol(Species species) { - return getSpeciesProtocol(species, getProtocol().getSpecies()); + return TuttiProtocols.getSpeciesProtocol(species, getProtocol().getSpecies()); } /** @@ -638,82 +545,7 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer * @since 2.6 */ public SpeciesProtocol getBenthosProtocol(Species species) { - return getSpeciesProtocol(species, getProtocol().getBenthos()); - } - - /** - * Return all the speciesprotocol corresponding to the species of the batch - * - * @param species species to test - * @param speciesProtocols list of species protocol to filter - * @return all the speciesprotocol corresponding to the species of the batch - * @since 2.6 - */ - public SpeciesProtocol getSpeciesProtocol(Species species, - List<SpeciesProtocol> speciesProtocols) { - for (SpeciesProtocol speciesProtocol : speciesProtocols) { - if (species.getReferenceTaxonId().equals( - speciesProtocol.getSpeciesReferenceTaxonId())) { - return speciesProtocol; - } - } - return null; - } - - public Set<String> fillSpeciesSurveyCode(Collection<Species> speciesList) { - - TuttiProtocol protocol = getProtocol(); - - Set<String> badSpecies = new LinkedHashSet<>(); - - if (protocol != null) { - // fill available species from protocol - if (!protocol.isSpeciesEmpty()) { - - Map<Integer, SpeciesProtocol> protocolMap = toSpeciesProtocolMap(); - - for (Species species : speciesList) { - SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); - if (speciesProtocol == null || - StringUtils.isEmpty(speciesProtocol.getSpeciesSurveyCode())) { - badSpecies.add(species.getName()); - continue; - } - species.setSurveyCode(speciesProtocol.getSpeciesSurveyCode()); - } - } - } - - return badSpecies; - } - - public Set<String> fillBenthosSurveyCode(Collection<Species> benthosList) { - - TuttiProtocol protocol = getProtocol(); - - Set<String> badSpecies = new LinkedHashSet<>(); - - if (protocol != null) { - - - // fill available benthos from protocol - if (!protocol.isBenthosEmpty()) { - - Map<Integer, SpeciesProtocol> protocolMap = toBenthosProtocolMap(); - - for (Species species : benthosList) { - SpeciesProtocol speciesProtocol = protocolMap.get(species.getReferenceTaxonId()); - if (speciesProtocol == null || - StringUtils.isEmpty(speciesProtocol.getSpeciesSurveyCode())) { - badSpecies.add(species.getName()); - continue; - } - species.setSurveyCode(speciesProtocol.getSpeciesSurveyCode()); - } - } - } - - return badSpecies; + return TuttiProtocols.getSpeciesProtocol(species, getProtocol().getBenthos()); } public static final TimeLog TIME_LOG = new TimeLog(PersistenceService.class); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java index 9a3a1bc..98d416f 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/TuttiDataContext.java @@ -37,6 +37,8 @@ import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativ import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.util.Weights; import org.apache.commons.lang3.StringUtils; @@ -48,6 +50,7 @@ import org.nuiton.util.DateUtil; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Closeable; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -716,7 +719,9 @@ public class TuttiDataContext extends AbstractBean implements Closeable { log.info("Loading referentSpecies"); } - referentSpeciesWithSurveyCode = service.getReferentSpeciesWithSurveyCode(getReferentSpecies()); + TaxonCache taxonCache = TaxonCaches.createSpeciesCacheWithoutVernacularCode(service, getProtocol()); + referentSpeciesWithSurveyCode = new ArrayList<>(getReferentSpecies()); + taxonCache.load(referentSpeciesWithSurveyCode); } return referentSpeciesWithSurveyCode; } @@ -728,8 +733,9 @@ public class TuttiDataContext extends AbstractBean implements Closeable { if (log.isInfoEnabled()) { log.info("Loading referentBenthos"); } - - referentBenthosWithSurveyCode = service.getReferentBenthosWithSurveyCode(getReferentSpecies()); + TaxonCache taxonCache = TaxonCaches.createBenthosCacheWithoutVernacularCode(service, getProtocol()); + referentBenthosWithSurveyCode = new ArrayList<>(getReferentSpecies()); + taxonCache.load(referentBenthosWithSurveyCode); } return referentBenthosWithSurveyCode; } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java index ce31737..89955da 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/pdf/CatchesPdfExportService.java @@ -26,8 +26,10 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.Speciess; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PdfGeneratorService; import fr.ifremer.tutti.service.PersistenceService; @@ -35,10 +37,8 @@ import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.service.export.ExportBatchEntry; import fr.ifremer.tutti.service.export.ExportCatchContext; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.ApplicationBusinessException; import java.io.File; import java.util.List; @@ -118,8 +118,7 @@ public class CatchesPdfExportService extends AbstractTuttiService { generatePdf(targetFile, locale, operations); } - protected void prepareOperation(String fishingOperationId, - List<Map<String, Object>> operations) { + protected void prepareOperation(String fishingOperationId, List<Map<String, Object>> operations) { // get operation and catch data boolean withCatchBatch = @@ -153,84 +152,15 @@ public class CatchesPdfExportService extends AbstractTuttiService { // Species if (exportContext.withSpeciesBatches()) { - List<ExportBatchEntry> speciesBatchEntries = - exportContext.getSpeciesBatchEntry(false); + prepareOperationSpecies(exportContext, totalWeight, catchList); - - boolean protocolFilled = context.getDataContext().isProtocolFilled(); - - Map<Integer, SpeciesProtocol> speciesProtocolMap = null; - - if (protocolFilled) { - - speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); - - } - - for (ExportBatchEntry entry : speciesBatchEntries) { - - SpeciesAbleBatch batch = entry.getBatch(); - Species species = batch.getSpecies(); - - Species speciesWithVerncularCode = - persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); - - String code; - - - // if the protocol is set and the species is in the protocol - if (protocolFilled && speciesProtocolMap.containsKey(species.getReferenceTaxonId())) { - - // use surveyCode from protocol - SpeciesProtocol speciesProtocol = speciesProtocolMap.get(species.getReferenceTaxonId()); - - code = speciesProtocol.getSpeciesSurveyCode(); - - } else { - - // use refTaxCode - code = species.getRefTaxCode(); - - } - - if (StringUtils.isEmpty(code)) { - - - throw new ApplicationBusinessException(t("tutti.pdf.export.missing.species.code", species.getReferenceTaxonId(), species.getName())); - } - - PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry(code, - species.getName(), - speciesWithVerncularCode.getVernacularCode(), - entry.getSortedWeight(), - entry.getTotalWeight(), - totalWeight); - catchList.add(pdfEntry); - } } // Benthos if (exportContext.withBenthosBatches()) { - List<ExportBatchEntry> benthosBatchEntries = - exportContext.getBenthosBatchEntry(false); - - float sortedWeight = 0f; - float benthosTotalWeight = 0f; + prepareOperationBenthos(exportContext, totalWeight, catchList); - for (ExportBatchEntry entry : benthosBatchEntries) { - sortedWeight += entry.getSortedWeight(); - benthosTotalWeight += entry.getTotalWeight(); - } - - PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry( - t("tutti.service.operations.exportCatchesReport.specialRows.benthos.code"), - "", - t("tutti.service.operations.exportCatchesReport.specialRows.benthos.name"), - sortedWeight, - benthosTotalWeight, - totalWeight); - catchList.add(pdfEntry); } // Inert and living not itemized @@ -266,6 +196,54 @@ public class CatchesPdfExportService extends AbstractTuttiService { operations.add(op); } + protected void prepareOperationSpecies(ExportCatchContext exportContext, float totalWeight, List<PdfExportBatchEntry> catchList) { + + List<ExportBatchEntry> speciesBatchEntries = exportContext.getSpeciesBatchEntry(false); + + TaxonCache taxonCache = TaxonCaches.createSpeciesCache(persistenceService, context.getDataContext().getProtocol()); + + for (ExportBatchEntry entry : speciesBatchEntries) { + + SpeciesAbleBatch batch = entry.getBatch(); + Species species = batch.getSpecies(); + + taxonCache.load(species); + + String code = Speciess.getSurveyCodeOrRefTaxCode(species); + + PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry(code, + species.getName(), + species.getVernacularCode(), + entry.getSortedWeight(), + entry.getTotalWeight(), + totalWeight); + catchList.add(pdfEntry); + } + } + + protected void prepareOperationBenthos(ExportCatchContext exportContext, float totalWeight, List<PdfExportBatchEntry> catchList) { + + List<ExportBatchEntry> benthosBatchEntries = exportContext.getBenthosBatchEntry(false); + + float sortedWeight = 0f; + float benthosTotalWeight = 0f; + + for (ExportBatchEntry entry : benthosBatchEntries) { + sortedWeight += entry.getSortedWeight(); + benthosTotalWeight += entry.getTotalWeight(); + } + + PdfExportBatchEntry pdfEntry = new PdfExportBatchEntry( + t("tutti.service.operations.exportCatchesReport.specialRows.benthos.code"), + "", + t("tutti.service.operations.exportCatchesReport.specialRows.benthos.name"), + sortedWeight, + benthosTotalWeight, + totalWeight); + catchList.add(pdfEntry); + + } + protected void generatePdf(File targetFile, Locale locale, List<Map<String, Object>> operations) { Map<String, Object> data = Maps.newHashMap(); @@ -275,39 +253,6 @@ public class CatchesPdfExportService extends AbstractTuttiService { } - - // protected void generatePdf(File targetFile, Locale locale, List<Map<String, Object>> operations) { -// -// Map<String, Object> data = Maps.newHashMap(); -// data.put("operations", operations); -// // generate the report -// OutputStream os = null; -// try { -// -// // render freemarker template -// Template mapTemplate = freemarkerConfiguration.getTemplate("catchesReport.ftl", locale); -// -// Writer out = new StringWriter(); -// mapTemplate.process(data, out); -// out.flush(); -// -// // render template output as pdf -// os = new FileOutputStream(targetFile); -// -// ITextRenderer renderer = new ITextRenderer(); -// renderer.setDocumentFromString(out.toString()); -// renderer.layout(); -// renderer.createPDF(os); -// -// os.close(); -// -// } catch (Exception ex) { -// throw new ApplicationTechnicalException(t("tutti.service.operations.exportCatchesReport.error"), ex); -// } finally { -// IOUtils.closeQuietly(os); -// } -// } -// protected Map<String, Object> createOperation(FishingOperation fishingOperation) { Map<String, Object> op = Maps.newHashMap(); op.put("number", fishingOperation.getFishingOperationNumber()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java index 34cd9d1..7116322 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/sumatra/CatchesSumatraExportService.java @@ -29,7 +29,10 @@ import com.google.common.io.Files; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -37,6 +40,7 @@ import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.service.export.ExportBatchEntry; import fr.ifremer.tutti.service.export.ExportCatchContext; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Export; @@ -160,6 +164,12 @@ public class CatchesSumatraExportService extends AbstractTuttiService { new CatchRowModel(context.getConfig().getCsvSeparator()); if (operations != null) { + + TuttiProtocol protocol = context.getDataContext().getProtocol(); + + TaxonCache speciesCache = TaxonCaches.createSpeciesCacheWithoutVernacularCode(persistenceService, protocol); + TaxonCache benthosCache = TaxonCaches.createBenthosCacheWithoutVernacularCode(persistenceService, protocol); + for (String operationId : operations) { progressionModel.increments(t("tutti.service.sumatra.export.step.load.fishingOperation", operationId)); @@ -171,7 +181,8 @@ public class CatchesSumatraExportService extends AbstractTuttiService { break; } - prepareFishingOperation(csvModel, rows, operationId, result); + prepareFishingOperation(speciesCache, benthosCache, csvModel, rows, operationId, result); + } } @@ -191,7 +202,9 @@ public class CatchesSumatraExportService extends AbstractTuttiService { } } - protected void prepareFishingOperation(CatchRowModel csvModel, + protected void prepareFishingOperation(TaxonCache speciesCache, + TaxonCache benthosCache, + CatchRowModel csvModel, List<CatchRow> rows, String operationId, SumatraExportResult result) { @@ -207,46 +220,77 @@ public class CatchesSumatraExportService extends AbstractTuttiService { // Species if (exportContext.withSpeciesBatches()) { - Set<Species> allspecies = new HashSet<>(); + List<ExportBatchEntry> entries = exportContext.getSpeciesBatchEntry(true); + Set<String> badSpecies = prepareFishingOperationSpecies(speciesCache, entries, csvModel, rows, operation); + result.setBadSpecies(badSpecies); + + } + + // Benthos + if (exportContext.withBenthosBatches()) { + + List<ExportBatchEntry> entries = exportContext.getBenthosBatchEntry(true); + Set<String> badBenthos = prepareFishingOperationBenthos(benthosCache, entries, csvModel, rows, operation); + result.setBadBenthos(badBenthos); + + } + } - List<ExportBatchEntry> entries = - exportContext.getSpeciesBatchEntry(true); + protected Set<String> prepareFishingOperationSpecies(TaxonCache taxonCache, + List<ExportBatchEntry> entries, + CatchRowModel csvModel, + List<CatchRow> rows, + FishingOperation operation) { - for (ExportBatchEntry entry : entries) { + Set<String> badSpecies = new HashSet<>(); - // get species campaign code from protocol + for (ExportBatchEntry entry : entries) { - allspecies.add(entry.getBatch().getSpecies()); + Species species = entry.getBatch().getSpecies(); - CatchRow row = csvModel.newRow(operation, entry); - row.getSpecies(); - rows.add(row); + // load species codes + taxonCache.load(species); + + if (StringUtils.isBlank(species.getSurveyCode())) { + badSpecies.add(species.getName()); } - // fill survey code in species - Set<String> badSpecies = persistenceService.fillSpeciesSurveyCode(allspecies); - result.setBadSpecies(badSpecies); + CatchRow row = csvModel.newRow(operation, entry); + + rows.add(row); } - // Benthos - if (exportContext.withBenthosBatches()) { + return badSpecies; + + } - Set<Species> allspecies = new HashSet<>(); + protected Set<String> prepareFishingOperationBenthos(TaxonCache taxonCache, + List<ExportBatchEntry> entries, + CatchRowModel csvModel, + List<CatchRow> rows, + FishingOperation operation) { - List<ExportBatchEntry> entries = - exportContext.getBenthosBatchEntry(true); + Set<String> badBenthos = new HashSet<>(); - for (ExportBatchEntry entry : entries) { + for (ExportBatchEntry entry : entries) { - CatchRow row = csvModel.newRow(operation, entry); - allspecies.add(entry.getBatch().getSpecies()); - rows.add(row); + Species species = entry.getBatch().getSpecies(); + + // load species codes + taxonCache.load(species); + if (StringUtils.isBlank(species.getSurveyCode())) { + badBenthos.add(species.getName()); } - // fill survey code in benthos - Set<String> badBenthos = persistenceService.fillBenthosSurveyCode(allspecies); - result.setBadBenthos(badBenthos); + CatchRow row = csvModel.newRow(operation, entry); + rows.add(row); + } + + return badBenthos; + } + + } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java index 58117b9..02dc8e1 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/export/toconfirmreport/ToConfirmReportService.java @@ -29,12 +29,14 @@ import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; +import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PdfGeneratorService; import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.service.SpeciesMap; import fr.ifremer.tutti.service.TuttiServiceContext; import fr.ifremer.tutti.service.catches.WeightComputingService; import fr.ifremer.tutti.type.WeightUnit; @@ -100,7 +102,10 @@ public class ToConfirmReportService extends AbstractTuttiService { progressionModel.increments(t("tutti.toconfirmReport.loading.protocol")); - SpeciesMap speciesMap = SpeciesMap.create(context.getDataContext(), persistenceService); + TuttiProtocol protocol = context.getDataContext().getProtocol(); + + TaxonCache speciesCache = TaxonCaches.createSpeciesCache(persistenceService, protocol); + TaxonCache benthosCache = TaxonCaches.createBenthosCache(persistenceService, protocol); List<String> allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); @@ -118,7 +123,7 @@ public class ToConfirmReportService extends AbstractTuttiService { if (fishingOperationData != null) { - ToConfirmReportFishingOperationBean operationBean = createOperationBean(fishingOperationData, speciesMap); + ToConfirmReportFishingOperationBean operationBean = createOperationBean(fishingOperationData, speciesCache, benthosCache); reportBean.addOperation(operationBean); } @@ -131,7 +136,8 @@ public class ToConfirmReportService extends AbstractTuttiService { } protected ToConfirmReportFishingOperationBean createOperationBean(ToConfirmReportFishingOperationData fishingOperationData, - SpeciesMap speciesMap) { + TaxonCache speciesCache, + TaxonCache benthosCache) { // Species @@ -140,7 +146,7 @@ public class ToConfirmReportService extends AbstractTuttiService { if (fishingOperationData.isWithSpeciesBatchToConfirm()) { List<SpeciesBatch> speciesBatchEntries = fishingOperationData.getSpeciesBatchToConfirm(); - speciesMap.loadSpecies(speciesBatchEntries); + speciesCache.loadInBatches(speciesBatchEntries); speciesCatchList = createBatchBeans(speciesWeightUnit, speciesBatchEntries); } else { @@ -155,7 +161,7 @@ public class ToConfirmReportService extends AbstractTuttiService { if (fishingOperationData.isWithBenthosBatchToConfirm()) { List<BenthosBatch> benthosBatchEntries = fishingOperationData.getBenthosBatchToConfirm(); - speciesMap.loadBenthos(benthosBatchEntries); + benthosCache.loadInBatches(benthosBatchEntries); benthosCatchList = createBatchBeans(benthosWeightUnit, benthosBatchEntries); } else { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java index a786fa5..de78272 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/psionimport/PsionImportService.java @@ -50,6 +50,8 @@ import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues; import fr.ifremer.tutti.persistence.entities.referential.Species; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -71,6 +73,7 @@ import java.io.Serializable; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; @@ -209,9 +212,10 @@ public class PsionImportService extends AbstractTuttiService { throw new ApplicationBusinessException(t("tutti.service.psionimport.error.no.protocol")); } - List<Species> allReferentSpecies = persistenceService.getAllReferentSpecies(); - List<Species> allSpeciesWithSurveyCode = persistenceService.getReferentSpeciesWithSurveyCode( - allReferentSpecies); + List<Species> allSpeciesWithSurveyCode = new ArrayList<>(persistenceService.getAllReferentSpecies()); + + TaxonCache speciesMap = TaxonCaches.createSpeciesCacheWithoutVernacularCode(persistenceService, protocol); + speciesMap.load(allSpeciesWithSurveyCode); Map<String, Species> speciesBySurveyCode = Maps.newTreeMap(); for (Species species : allSpeciesWithSurveyCode) { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java index 4979838..a5de739 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/PupitriImportService.java @@ -35,12 +35,13 @@ import fr.ifremer.tutti.persistence.entities.data.CatchBatch; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchs; -import fr.ifremer.tutti.persistence.entities.protocol.SpeciesProtocol; import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues; import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Speciess; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCache; +import fr.ifremer.tutti.persistence.entities.referential.TaxonCaches; import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.DecoratorService; import fr.ifremer.tutti.service.PdfGeneratorService; @@ -62,7 +63,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Import; import org.nuiton.decorator.Decorator; -import org.nuiton.jaxx.application.ApplicationBusinessException; import org.nuiton.jaxx.application.ApplicationIOUtil; import org.nuiton.jaxx.application.ApplicationTechnicalException; @@ -193,74 +193,49 @@ public class PupitriImportService extends AbstractTuttiService { //FIXME Check how to deal with Melag meta species and species involed in melag protected File generatePupitriReport(FishingOperation operation, PupitriImportResult result) { - boolean protocolFilled = context.getDataContext().isProtocolFilled(); - - Map<Integer, SpeciesProtocol> speciesProtocolMap = null; - - if (protocolFilled) { - - speciesProtocolMap = persistenceService.toSpeciesProtocolMap(); - - } + TaxonCache taxonCache = TaxonCaches.createSpeciesCache(persistenceService, context.getDataContext().getProtocol()); PupitriImportReportModel reportModel = new PupitriImportReportModel(operation, result); for (PupitriSpeciesContext aCatch : result.getCatches()) { - Species species = aCatch.getSpecies(); - - Species speciesWithVerncularCode = - persistenceService.getSpeciesByReferenceTaxonIdWithVernacularCode(species.getReferenceTaxonId()); - - String code; + addCatchEntry(taxonCache, aCatch, reportModel); - // if the protocol is set and the species is in the protocol - if (protocolFilled && speciesProtocolMap.containsKey(species.getReferenceTaxonId())) { + } - // use surveyCode from protocol - SpeciesProtocol speciesProtocol = speciesProtocolMap.get(species.getReferenceTaxonId()); + reportModel.sortRows(); - code = speciesProtocol.getSpeciesSurveyCode(); + File reportFile = context.getConfig().newTempFile("puputri-report", ".pdf"); + Locale locale = context.getConfig().getI18nLocale(); - } else { + pdfGeneratorService.generatePdf(reportFile, locale, "pupitriReport.ftl", reportModel); - // use refTaxCode - code = species.getRefTaxCode(); + return reportFile; - } + } - String name = species.getName(); - if (StringUtils.isEmpty(code)) { + protected void addCatchEntry(TaxonCache taxonCache, PupitriSpeciesContext aCatch, PupitriImportReportModel reportModel) { - throw new ApplicationBusinessException(t("tutti.pdf.export.missing.species.code", species.getReferenceTaxonId(), name)); + Species species = aCatch.getSpecies(); + taxonCache.load(species); - } + String code = Speciess.getSurveyCodeOrRefTaxCode(species); - String vernacularCode = speciesWithVerncularCode.getVernacularCode(); + String name = species.getName(); - for (Signs signs : aCatch.getSigns()) { + String vernacularCode = species.getVernacularCode(); - PupitriImportReportRow reportCatch = PupitriImportReportRow.newRow(code, - name, - vernacularCode, - aCatch.isSorted(), - aCatch.getSignContext(signs)); + for (Signs signs : aCatch.getSigns()) { - reportModel.addRow(reportCatch); + PupitriImportReportRow reportCatch = PupitriImportReportRow.newRow(code, + name, + vernacularCode, + aCatch.isSorted(), + aCatch.getSignContext(signs)); - } + reportModel.addRow(reportCatch); } - - reportModel.sortRows(); - - File reportFile = context.getConfig().newTempFile("puputri-report", ".pdf"); - Locale locale = context.getConfig().getI18nLocale(); - - pdfGeneratorService.generatePdf(reportFile, locale, "pupitriReport.ftl", reportModel); - - return reportFile; - } protected String addFileAsAttachment(File f, CatchBatch catchBatch) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.