Author: tchemit Date: 2013-07-31 20:19:34 +0200 (Wed, 31 Jul 2013) New Revision: 1162 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1162 Log: fixes #3004: [IMPORT-EXPORT MULTIPOSTE] Probl?\195?\168me de transaction lors d'une erreur Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportService.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportServiceTest.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2013-07-30 17:22:49 UTC (rev 1161) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2013-07-31 18:19:34 UTC (rev 1162) @@ -53,6 +53,7 @@ import java.io.File; import java.util.List; +import java.util.concurrent.Callable; /** * Contract for a persistence driver used by Tutti. @@ -78,6 +79,20 @@ TuttiEnumerationFile getEnumerationFile(); + /** + * To invoke the given call code. + * <p/> + * <strong>Note:</strong> this is mainly to execute a code in a single + * transaction. + * + * @param call call to invoke + * @param <V> return type + * @return the return of the call + * @since 2.5 + */ + @Transactional(readOnly = false) + <V> V invoke(Callable<V> call); + //------------------------------------------------------------------------// //-- Referential methods --// //------------------------------------------------------------------------// @@ -221,7 +236,6 @@ List<Caracteristic> getAllCaracteristicWithProtected(); /** - * * @return all caracteristics of the system useable for {@link SampleCategoryModel}. * @since 2.5 */ @@ -360,7 +374,6 @@ @Transactional(readOnly = false) Attachment createAttachment(Attachment attachment, File file); - /** * Saves the given attachment. * @@ -370,7 +383,6 @@ @Transactional(readOnly = false) Attachment saveAttachment(Attachment attachment); - /** * Deletes the given attachment given his id. * @@ -474,7 +486,7 @@ /** * @param operationId id of the fishing operation * @return {@code true} if there is a catchBatch for the given fishing - * operation, {@code false} otherwise. + * operation, {@code false} otherwise. * @since 2.2 */ boolean isFishingOperationWithCatchBatch(String operationId); @@ -520,7 +532,7 @@ * <p/> * <strong>Note:</strong> All childs of the batch should be loaded here. * - * @param fishingOperationId if of the fishing operation to seek + * @param fishingOperationId if of the fishing operation to seek * @param sampleCategoryModel [optional] sample category model to check * @return the list of root {@link SpeciesBatch} * @throws InvalidBatchModelException if batch does not respect the sample category model @@ -578,7 +590,7 @@ * <p/> * <strong>Note:</strong> All childs of the batch should be loaded here. * - * @param fishingOperationId if of the fishing operation to seek + * @param fishingOperationId if of the fishing operation to seek * @param sampleCategoryModel [optional] sample category model to check * @return the list of root {@link BenthosBatch} * @throws InvalidBatchModelException if batch does not respect the sample category model Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-07-30 17:22:49 UTC (rev 1161) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-07-31 18:19:34 UTC (rev 1162) @@ -27,6 +27,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Maps; import fr.ifremer.adagio.core.service.technical.CacheService; +import fr.ifremer.tutti.TuttiTechnicalException; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.AccidentalBatch; import fr.ifremer.tutti.persistence.entities.data.AttachementObjectTypeEnum; @@ -76,6 +77,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; /** * @author tchemit <chemit@codelutin.com> @@ -146,6 +148,21 @@ } @Override + public <V> V invoke(Callable<V> call) { + + try { + V result = call.call(); + return result; + } catch (TuttiTechnicalException e) { + throw e; + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new TuttiTechnicalException(e); + } + } + + @Override public void init() { if (log.isInfoEnabled()) { log.info("Open persistence driver " + getImplementationName()); @@ -495,7 +512,6 @@ attachmentService.deleteAttachment(attachmentId); } - //------------------------------------------------------------------------// //-- Program methods --// //------------------------------------------------------------------------// Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-07-30 17:22:49 UTC (rev 1161) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-07-31 18:19:34 UTC (rev 1162) @@ -53,6 +53,7 @@ import java.io.File; import java.io.IOException; import java.util.List; +import java.util.concurrent.Callable; /** * Mock implementation With no persistence at all behind. @@ -73,6 +74,11 @@ } @Override + public <V> V invoke(Callable<V> call) { + throw notImplemented(); + } + + @Override public boolean isVracSpeciesBatch(SpeciesBatch speciesBatch) { throw notImplemented(); } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-07-30 17:22:49 UTC (rev 1161) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-07-31 18:19:34 UTC (rev 1162) @@ -70,6 +70,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.List; +import java.util.concurrent.Callable; import static org.nuiton.i18n.I18n._; @@ -112,6 +113,11 @@ return driver.getEnumerationFile(); } + @Override + public <V> V invoke(Callable<V> call) { + return driver.invoke(call); + } + public static final DateFormat EXPORT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); public static final String EXPORT_DIRECTORY_FORMAT = "tutti-%s-%s"; Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportService.java 2013-07-30 17:22:49 UTC (rev 1161) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportService.java 2013-07-31 18:19:34 UTC (rev 1162) @@ -58,7 +58,6 @@ import java.io.Writer; import java.util.List; import java.util.Map; -import java.util.UUID; import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; @@ -128,7 +127,6 @@ } } } - } /** @@ -526,7 +524,7 @@ List<AttachmentRow> attachmentRows) { CatchRow row = new CatchRow(); - String id = context.generateId(CatchRow.class);; + String id = context.generateId(CatchRow.class); row.setId(id); row.setParentId(parentId); row.setSpecies(batch.getSpecies()); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportService.java 2013-07-30 17:22:49 UTC (rev 1161) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportService.java 2013-07-31 18:19:34 UTC (rev 1162) @@ -70,12 +70,14 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; /** - * Service to export batches from a satellite post or import batches into a master post. + * Service to export batches from a satellite post or import batches + * into a master post. * * @author kmorin <kmorin@codelutin.com> * @since 2.2 @@ -151,69 +153,75 @@ * @param operation the operation in which to add the batches * @return the list of the species which have not been imported, because there were concurrent batches */ - public Map<String, Object> importSpecies(File file, FishingOperation operation) { + public Map<String, Object> importSpecies(final File file, + final FishingOperation operation) { - File tempDir = TuttiIOUtil.explodeZip( - context.getConfig().getTmpDirectory(), - file, - n_("tutti.service.multipost.uncompress.error")); + Callable<Map<String, Object>> call = new Callable<Map<String, Object>>() { - //check operation - CatchWeightsRowModel weightsModel = new CatchWeightsRowModel(csvSeparator); - checkSameOperation(tempDir, weightsModel, operation); + @Override + public Map<String, Object> call() throws Exception { - Map<String, Object> notImportedData = Maps.newHashMap(); - final Map<String, SpeciesBatch> notImportedBatches = Maps.newLinkedHashMap(); + File tempDir = TuttiIOUtil.explodeZip( + context.getConfig().getTmpDirectory(), + file, + n_("tutti.service.multipost.uncompress.error")); - BatchContainer<SpeciesBatch> speciesBatches = - persistenceService.getRootSpeciesBatch(operation.getId(), null); + //check operation + CatchWeightsRowModel weightsModel = new CatchWeightsRowModel(csvSeparator); + checkSameOperation(tempDir, weightsModel, operation); - TuttiDataContext dataContext = context.getDataContext(); - List<Species> speciesList = dataContext.getReferentSpecies(); + final Map<String, Object> notImportedData = Maps.newHashMap(); - // Import batches - // map containing the batches by their persistence id + final Map<String, SpeciesBatch> notImportedBatches = Maps.newLinkedHashMap(); - final Map<String, SpeciesBatch> batches = importSpeciesBatches( - tempDir, - operation, - speciesBatches, - notImportedBatches, - speciesList); + BatchContainer<SpeciesBatch> speciesBatches = + persistenceService.getRootSpeciesBatch(operation.getId(), null); - List<Caracteristic> caracteristics = dataContext.getCaracteristics(); + TuttiDataContext dataContext = context.getDataContext(); + List<Species> speciesList = dataContext.getReferentSpecies(); - // Import frequencies + // Import batches + // map containing the batches by their persistence id - ListMultimap<String, SpeciesBatchFrequency> frequencyMap = importSpeciesFrequencies( - file, - batches, - notImportedBatches, - caracteristics); + final Map<String, SpeciesBatch> batches = importSpeciesBatches( + tempDir, + operation, + speciesBatches, + notImportedBatches, + speciesList); - // Persist frequencies + List<Caracteristic> caracteristics = dataContext.getCaracteristics(); - for (String batchId : frequencyMap.keySet()) { - List<SpeciesBatchFrequency> frequencies = frequencyMap.get(batchId); - persistenceService.saveSpeciesBatchFrequency(batchId, frequencies); - } + // Import frequencies - // Import attachments + importSpeciesFrequencies( + tempDir, + batches, + notImportedBatches, + caracteristics); - importAttachments(tempDir, - batches, - notImportedBatches, - AttachementObjectTypeEnum.BATCH); + // Import attachments - // Import weights + importAttachments(tempDir, + batches, + notImportedBatches, + AttachementObjectTypeEnum.BATCH); - importSpeciesWeights(tempDir, - operation, - weightsModel, - notImportedData); + // Import weights - notImportedData.put(BATCHES_KEY, notImportedBatches.values()); - return notImportedData; + importSpeciesWeights(tempDir, + operation, + weightsModel, + notImportedData); + + notImportedData.put(BATCHES_KEY, notImportedBatches.values()); + + return notImportedData; + } + }; + + Map<String, Object> result = persistenceService.invoke(call); + return result; } protected Map<String, SpeciesBatch> importSpeciesBatches(File file, @@ -304,7 +312,7 @@ return batches; } - protected ListMultimap<String, SpeciesBatchFrequency> importSpeciesFrequencies( + protected void importSpeciesFrequencies( File file, Map<String, SpeciesBatch> batches, Map<String, SpeciesBatch> notImportedBatches, @@ -323,7 +331,6 @@ Import<CatchFrequencyRow> importer = Import.newImport(frequencyModel, reader); - try { for (CatchFrequencyRow frequencyRow : importer) { if (notImportedBatches.get(frequencyRow.getBatchId()) == null) { @@ -347,7 +354,11 @@ } finally { IOUtils.closeQuietly(reader); } - return frequencyMap; + + for (String batchId : frequencyMap.keySet()) { + List<SpeciesBatchFrequency> frequencies = frequencyMap.get(batchId); + persistenceService.saveSpeciesBatchFrequency(batchId, frequencies); + } } protected void importSpeciesWeights(File file, @@ -412,60 +423,70 @@ * @param operation the operation in which to add the batches * @return the list of the benthos which have not been imported, because there were concurrent batches */ - public Map<String, Object> importBenthos(File file, FishingOperation operation) { + public Map<String, Object> importBenthos(final File file, + final FishingOperation operation) { - File tempDir = TuttiIOUtil.explodeZip( - context.getConfig().getTmpDirectory(), - file, - n_("tutti.service.multipost.uncompress.error")); + Callable<Map<String, Object>> call = new Callable<Map<String, Object>>() { - //check operation - CatchWeightsRowModel weightsModel = new CatchWeightsRowModel(csvSeparator); - checkSameOperation(tempDir, weightsModel, operation); + @Override + public Map<String, Object> call() throws Exception { - Map<String, Object> notImportedData = Maps.newHashMap(); - final Map<String, BenthosBatch> notImportedBatches = Maps.newLinkedHashMap(); + File tempDir = TuttiIOUtil.explodeZip( + context.getConfig().getTmpDirectory(), + file, + n_("tutti.service.multipost.uncompress.error")); - BatchContainer<BenthosBatch> benthosBatches = - persistenceService.getRootBenthosBatch(operation.getId(), null); + //check operation + CatchWeightsRowModel weightsModel = new CatchWeightsRowModel(csvSeparator); + checkSameOperation(tempDir, weightsModel, operation); - TuttiDataContext dataContext = context.getDataContext(); - List<Species> speciesList = dataContext.getReferentSpecies(); + Map<String, Object> notImportedData = Maps.newHashMap(); + final Map<String, BenthosBatch> notImportedBatches = Maps.newLinkedHashMap(); - // Import batches - // map containing the batches by their persistence id - final Map<String, BenthosBatch> batches = importBenthosBatches( - tempDir, - operation, - benthosBatches, - notImportedBatches, - speciesList); + BatchContainer<BenthosBatch> benthosBatches = + persistenceService.getRootBenthosBatch(operation.getId(), null); - // Import frequencies + TuttiDataContext dataContext = context.getDataContext(); + List<Species> speciesList = dataContext.getReferentSpecies(); - ListMultimap<String, BenthosBatchFrequency> frequencyMap = importBenthosFrequencies( - tempDir, - batches, - notImportedBatches, - dataContext.getCaracteristics()); + // Import batches + // map containing the batches by their persistence id + final Map<String, BenthosBatch> batches = importBenthosBatches( + tempDir, + operation, + benthosBatches, + notImportedBatches, + speciesList); - // Persist frequencies + // Import frequencies - for (String batchId : frequencyMap.keySet()) { - List<BenthosBatchFrequency> frequencies = frequencyMap.get(batchId); - persistenceService.saveBenthosBatchFrequency(batchId, frequencies); - } + importBenthosFrequencies( + tempDir, + batches, + notImportedBatches, + dataContext.getCaracteristics()); - // Import attachments + // Import attachments - importAttachments(tempDir, batches, notImportedBatches, AttachementObjectTypeEnum.BATCH); + importAttachments(tempDir, + batches, + notImportedBatches, + AttachementObjectTypeEnum.BATCH); - // Import weights + // Import weights - importBenthosWeights(tempDir, operation, weightsModel, notImportedData); + importBenthosWeights(tempDir, + operation, + weightsModel, + notImportedData); - notImportedData.put(BATCHES_KEY, notImportedBatches.values()); - return notImportedData; + notImportedData.put(BATCHES_KEY, notImportedBatches.values()); + return notImportedData; + } + }; + + Map<String, Object> result = persistenceService.invoke(call); + return result; } protected Map<String, BenthosBatch> importBenthosBatches(File file, @@ -556,10 +577,10 @@ return batches; } - protected ListMultimap<String, BenthosBatchFrequency> importBenthosFrequencies(File file, - Map<String, BenthosBatch> batches, - Map<String, BenthosBatch> notImportedBatches, - List<Caracteristic> caracteristics) { + protected void importBenthosFrequencies(File file, + Map<String, BenthosBatch> batches, + Map<String, BenthosBatch> notImportedBatches, + List<Caracteristic> caracteristics) { ListMultimap<String, BenthosBatchFrequency> frequencyMap = ArrayListMultimap.create(); @@ -596,7 +617,11 @@ } finally { IOUtils.closeQuietly(reader); } - return frequencyMap; + + for (String batchId : frequencyMap.keySet()) { + List<BenthosBatchFrequency> frequencies = frequencyMap.get(batchId); + persistenceService.saveBenthosBatchFrequency(batchId, frequencies); + } } protected void importBenthosWeights(File file, @@ -662,55 +687,65 @@ * @param operation the operation in which to add the batches * @return the list of the marine litter which have not been imported, because there were concurrent batches */ - public Map<String, Object> importMarineLitter(File file, FishingOperation operation) { + public Map<String, Object> importMarineLitter(final File file, + final FishingOperation operation) { - File tempDir = TuttiIOUtil.explodeZip( - context.getConfig().getTmpDirectory(), - file, - n_("tutti.service.multipost.uncompress.error")); + Callable<Map<String, Object>> call = new Callable<Map<String, Object>>() { - //check operation - MarineLitterWeightRowModel weightModel = new MarineLitterWeightRowModel(csvSeparator); - checkSameOperation(tempDir, weightModel, operation); + @Override + public Map<String, Object> call() throws Exception { + File tempDir = TuttiIOUtil.explodeZip( + context.getConfig().getTmpDirectory(), + file, + n_("tutti.service.multipost.uncompress.error")); - String operationId = operation.getId(); + //check operation + MarineLitterWeightRowModel weightModel = new MarineLitterWeightRowModel(csvSeparator); + checkSameOperation(tempDir, weightModel, operation); - Map<String, Object> notImportedData = Maps.newHashMap(); - final Map<String, MarineLitterBatch> notImportedBatches = Maps.newLinkedHashMap(); + String operationId = operation.getId(); - BatchContainer<MarineLitterBatch> marineLitterBatches = - persistenceService.getRootMarineLitterBatch(operationId); - List<CaracteristicQualitativeValue> categoryValues = - persistenceService.getMarineLitterCategoryCaracteristic().getQualitativeValue(); - List<CaracteristicQualitativeValue> sizeCategoryValues = - persistenceService.getMarineLitterSizeCategoryCaracteristic().getQualitativeValue(); + Map<String, Object> notImportedData = Maps.newHashMap(); + final Map<String, MarineLitterBatch> notImportedBatches = Maps.newLinkedHashMap(); - // Import batches - // map containing the batches by their persistence id - final Map<String, MarineLitterBatch> batches = importMarineLitterBatches( - tempDir, - operation, - categoryValues, - sizeCategoryValues, - marineLitterBatches, - notImportedBatches); + BatchContainer<MarineLitterBatch> marineLitterBatches = + persistenceService.getRootMarineLitterBatch(operationId); + List<CaracteristicQualitativeValue> categoryValues = + persistenceService.getMarineLitterCategoryCaracteristic().getQualitativeValue(); + List<CaracteristicQualitativeValue> sizeCategoryValues = + persistenceService.getMarineLitterSizeCategoryCaracteristic().getQualitativeValue(); - // Import attachments + // Import batches + // map containing the batches by their persistence id + final Map<String, MarineLitterBatch> batches = importMarineLitterBatches( + tempDir, + operation, + categoryValues, + sizeCategoryValues, + marineLitterBatches, + notImportedBatches); - importAttachments(tempDir, - batches, - notImportedBatches, - AttachementObjectTypeEnum.BATCH); + // Import attachments - // Import weights + importAttachments(tempDir, + batches, + notImportedBatches, + AttachementObjectTypeEnum.BATCH); - importMarineLitterCatchWeights(tempDir, - operation, - weightModel, - notImportedData); + // Import weights - notImportedData.put(BATCHES_KEY, notImportedBatches.values()); - return notImportedData; + importMarineLitterCatchWeights(tempDir, + operation, + weightModel, + notImportedData); + + notImportedData.put(BATCHES_KEY, notImportedBatches.values()); + return notImportedData; + + } + }; + Map<String, Object> result = persistenceService.invoke(call); + return result; } protected Map<String, MarineLitterBatch> importMarineLitterBatches(File file, FishingOperation operation, @@ -820,43 +855,52 @@ * @param file the file to import the batches from * @param operation the operation in which to add the batches */ - public void importIndividualObservation(File file, FishingOperation operation) { + public void importIndividualObservation(final File file, + final FishingOperation operation) { - File tempDir = TuttiIOUtil.explodeZip( - context.getConfig().getTmpDirectory(), - file, - n_("tutti.service.multipost.uncompress.error")); + Callable<Void> call = new Callable<Void>() { - //check operation - FishingOperationRowModel operationModel = - new FishingOperationRowModel(csvSeparator); - checkSameOperation(tempDir, operationModel, operation); + @Override + public Void call() throws Exception { + File tempDir = TuttiIOUtil.explodeZip( + context.getConfig().getTmpDirectory(), + file, + n_("tutti.service.multipost.uncompress.error")); - TuttiDataContext dataContext = context.getDataContext(); - List<Species> speciesList = dataContext.getReferentSpecies(); - List<Caracteristic> caracteristics = dataContext.getCaracteristicWithProtected(); + //check operation + FishingOperationRowModel operationModel = + new FishingOperationRowModel(csvSeparator); + checkSameOperation(tempDir, operationModel, operation); - // Import batches - // map containing the batches by their persistence id - final Map<String, IndividualObservationBatch> batches = importIndividualObservationBatches( - tempDir, - operation, - speciesList, - caracteristics); + TuttiDataContext dataContext = context.getDataContext(); + List<Species> speciesList = dataContext.getReferentSpecies(); + List<Caracteristic> caracteristics = dataContext.getCaracteristicWithProtected(); - // Import caracteristics + // Import batches + // map containing the batches by their persistence id + final Map<String, IndividualObservationBatch> batches = importIndividualObservationBatches( + tempDir, + operation, + speciesList, + caracteristics); - importIndividualObservationCaracteristics(file, batches, caracteristics); + // Import caracteristics - // Persist batches + importIndividualObservationCaracteristics(file, batches, caracteristics); - for (IndividualObservationBatch batch : batches.values()) { - persistenceService.createIndividualObservationBatch(batch); - } + // Persist batches - // Import attachments + for (IndividualObservationBatch batch : batches.values()) { + persistenceService.createIndividualObservationBatch(batch); + } - importAttachments(tempDir, batches, AttachementObjectTypeEnum.SAMPLE); + // Import attachments + + importAttachments(tempDir, batches, AttachementObjectTypeEnum.SAMPLE); + return null; + } + }; + persistenceService.invoke(call); } protected Map<String, IndividualObservationBatch> importIndividualObservationBatches(File file, FishingOperation operation, @@ -964,48 +1008,56 @@ * @param file the file to import the batches from * @param operation the operation in which to add the batches */ - public void importAccidentalCatches(File file, FishingOperation operation) { + public void importAccidentalCatches(final File file, final FishingOperation operation) { - File tempDir = TuttiIOUtil.explodeZip( - context.getConfig().getTmpDirectory(), - file, - n_("tutti.service.multipost.uncompress.error")); + Callable<Void> call = new Callable<Void>() { - //check operation - FishingOperationRowModel operationModel = - new FishingOperationRowModel(csvSeparator); - checkSameOperation(tempDir, operationModel, operation); + @Override + public Void call() throws Exception { + File tempDir = TuttiIOUtil.explodeZip( + context.getConfig().getTmpDirectory(), + file, + n_("tutti.service.multipost.uncompress.error")); - TuttiDataContext dataContext = context.getDataContext(); - List<Species> speciesList = dataContext.getReferentSpecies(); - List<CaracteristicQualitativeValue> genderValues = dataContext.getGenderValues(); - List<Caracteristic> caracteristics = dataContext.getCaracteristicWithProtected(); - List<CaracteristicQualitativeValue> dedOrAliveValues = dataContext.getDeadOrAliveValues(); + //check operation + FishingOperationRowModel operationModel = + new FishingOperationRowModel(csvSeparator); + checkSameOperation(tempDir, operationModel, operation); - // Import batches - // map containing the batches by their persistence id - final Map<String, AccidentalBatch> batches = importAccidentalCatchesBatches( - tempDir, - operation, - speciesList, - genderValues, - caracteristics, - dedOrAliveValues - ); + TuttiDataContext dataContext = context.getDataContext(); + List<Species> speciesList = dataContext.getReferentSpecies(); + List<CaracteristicQualitativeValue> genderValues = dataContext.getGenderValues(); + List<Caracteristic> caracteristics = dataContext.getCaracteristicWithProtected(); + List<CaracteristicQualitativeValue> dedOrAliveValues = dataContext.getDeadOrAliveValues(); - // Import caracteristics + // Import batches + // map containing the batches by their persistence id + final Map<String, AccidentalBatch> batches = importAccidentalCatchesBatches( + tempDir, + operation, + speciesList, + genderValues, + caracteristics, + dedOrAliveValues + ); - importAccidentalCatchesCaracteristics(file, batches, caracteristics); + // Import caracteristics - // Persist batches + importAccidentalCatchesCaracteristics(file, batches, caracteristics); - for (AccidentalBatch batch : batches.values()) { - persistenceService.createAccidentalBatch(batch); - } + // Persist batches - // Import attachments + for (AccidentalBatch batch : batches.values()) { + persistenceService.createAccidentalBatch(batch); + } - importAttachments(tempDir, batches, AttachementObjectTypeEnum.SAMPLE); + // Import attachments + + importAttachments(tempDir, batches, AttachementObjectTypeEnum.SAMPLE); + return null; + } + }; + persistenceService.invoke(call); } protected Map<String, AccidentalBatch> importAccidentalCatchesBatches(File file, FishingOperation operation, Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportServiceTest.java 2013-07-30 17:22:49 UTC (rev 1161) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostExportServiceTest.java 2013-07-31 18:19:34 UTC (rev 1162) @@ -38,6 +38,7 @@ /** * @author tchemit <chemit@codelutin.com> * @since 2.5 + * //FIXME Add more data in db */ public class TuttiMultiPostExportServiceTest { @@ -49,8 +50,6 @@ public static final String CRUISE_ID = "100001"; - public static final String CRUISE_CGFS_ID = "100000"; - public static final String OPERATION_1_ID = "100106"; public static final String OPERATION_2_ID = "100107";