r1156 - in trunk: tutti-persistence/src/main/java/fr/ifremer/tutti/persistence tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch tutti-persistence/src/main/resources/i18n tutti-persistence/src/main/xmi tutti-service/src/main/java/fr/ifremer/tutti/service tutti-service/src/main/java/fr/ifremer/tutti/service/catches tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost tutti-service/
Author: tchemit Date: 2013-07-25 19:32:14 +0200 (Thu, 25 Jul 2013) New Revision: 1156 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/1156 Log: - add export sumatra test - am?\195?\169lioration test de service - refs #2889: [TECH] - Prise en compte de nouvelles cat?\195?\169gories dans l'applicatif (ajout validation) Added: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/sumatra/ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportServiceTest.java 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-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportExportService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportService.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/ServiceDbResource.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportServiceTest.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.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-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistence.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -514,18 +514,6 @@ * <strong>Note:</strong> All childs of the batch should be loaded here. * * @param fishingOperationId if of the fishing operation to seek - * @return the list of root {@link SpeciesBatch} - * @since 1.0.2 - */ - BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId); - - /** - * Get the batch parent of all root {@link SpeciesBatch} for the given - * fishing operation. - * <p/> - * <strong>Note:</strong> All childs of the batch should be loaded here. - * - * @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 @@ -577,8 +565,6 @@ //-- Benthos Batch methods --// //------------------------------------------------------------------------// - BatchContainer<BenthosBatch> getRootBenthosBatch(String fishingOperationId); - /** * Get the batch parent of all root {@link BenthosBatch} for the given * fishing operation. 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-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -652,11 +652,6 @@ //------------------------------------------------------------------------// @Override - public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId) { - return getRootSpeciesBatch(fishingOperationId, null); - } - - @Override public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId, SampleCategoryModel sampleCategoryModel) throws InvalidBatchModelException { return speciesBatchService.getRootSpeciesBatch(fishingOperationId, sampleCategoryModel); } @@ -701,11 +696,6 @@ //------------------------------------------------------------------------// @Override - public BatchContainer<BenthosBatch> getRootBenthosBatch(String fishingOperationId) { - return benthosBatchService.getRootBenthosBatch(fishingOperationId, null); - } - - @Override public BatchContainer<BenthosBatch> getRootBenthosBatch(String fishingOperationId, SampleCategoryModel sampleCategoryModel) throws InvalidBatchModelException { return benthosBatchService.getRootBenthosBatch(fishingOperationId, sampleCategoryModel); } 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-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -448,11 +448,6 @@ } @Override - public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId) { - throw notImplemented(); - } - - @Override public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId, SampleCategoryModel sampleCategoryModel) throws InvalidBatchModelException { throw notImplemented(); } @@ -493,11 +488,6 @@ } @Override - public BatchContainer<BenthosBatch> getRootBenthosBatch(String fishingOperationId) { - throw notImplemented(); - } - - @Override public BatchContainer<BenthosBatch> getRootBenthosBatch(String fishingOperationId, SampleCategoryModel sampleCategoryModel) throws InvalidBatchModelException { throw notImplemented(); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/TuttiEntities.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -294,11 +294,11 @@ return value; } - public static Float getValueOrComputedValue(Float value, Float computedValue) { + public static <N extends Number> N getValueOrComputedValue(N value, N computedValue) { return value == null ? computedValue : value; } - public static Boolean getValueOrComputedValueComputed(Float value, Float computedValue) { + public static <N extends Number> Boolean getValueOrComputedValueComputed(N value, N computedValue) { Boolean result; if (value == null) { Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/BatchPersistenceHelper.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -132,7 +132,7 @@ errorsStr.add(error.getMessage()); } } - if (errorsStr.isEmpty()) { + if (!errorsStr.isEmpty()) { String join = Joiner.on("<br/>").join(errorsStr); throw new InvalidBatchModelException(_("tutti.persistence.batch.validation.bad.sample.categories", join)); } @@ -149,7 +149,7 @@ errorsStr.add(error.getMessage()); } } - if (errorsStr.isEmpty()) { + if (!errorsStr.isEmpty()) { String join = Joiner.on("<br/>").join(errorsStr); throw new InvalidBatchModelException(_("tutti.persistence.batch.validation.bad.sample.categories", join)); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/batch/ScientificCruiseCatchBatchValidator.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -33,6 +33,7 @@ import fr.ifremer.tutti.persistence.entities.data.BatchContainer; import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; +import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; import fr.ifremer.tutti.persistence.service.CatchBatchPersistenceService; import fr.ifremer.tutti.persistence.service.TuttiEnumerationFile; @@ -66,6 +67,10 @@ @Autowired protected BatchPersistenceHelper batchHelper; + // -----------------------------------------------------------------------// + // -- CatchBatchValidator methods --// + // -----------------------------------------------------------------------// + @Override public boolean isEnable(CatchBatch catchBatch) { // Apply validation only on catch batch for fishingOperation @@ -75,10 +80,14 @@ @Override public List<CatchBatchValidationError> validate(CatchBatch catchBatch) { List<CatchBatchValidationError> errors = Lists.newArrayList(); - validate(catchBatch.getChildBatchs(), errors); + validateCatchBatch(catchBatch.getChildBatchs(), errors); return errors; } + // -----------------------------------------------------------------------// + // -- TuttiCatchBatchValidator methods --// + // -----------------------------------------------------------------------// + @Override public List<CatchBatchValidationError> validateSpecies(SampleCategoryModel sampleCategoryModel, BatchContainer<SpeciesBatch> species) { @@ -87,6 +96,10 @@ for (SpeciesBatch speciesBatch : species.getChildren()) { + validateBatch(sampleCategoryModel, + errors, + speciesBatch, + n_("tutti.persistence.batch.validation.invalid.species.sampleCategoryId")); } return errors; } @@ -99,16 +112,20 @@ for (BenthosBatch benthosBatch : benthos.getChildren()) { + validateBatch(sampleCategoryModel, + errors, + benthosBatch, + n_("tutti.persistence.batch.validation.invalid.benthos.sampleCategoryId")); } return errors; } - // ------------------------------------------------------------------------// - // -- Internal methods --// - // ------------------------------------------------------------------------// + // -----------------------------------------------------------------------// + // -- Internal methods --// + // -----------------------------------------------------------------------// - protected void validate(Collection<Batch> batchs, - List<CatchBatchValidationError> errors) { + protected void validateCatchBatch(Collection<Batch> batchs, + List<CatchBatchValidationError> errors) { // Vrac SortingBatch vracBatch = batchHelper.getSortingBatch( @@ -270,6 +287,35 @@ } } + protected void validateBatch(SampleCategoryModel sampleCategoryModel, + List<CatchBatchValidationError> errors, + SpeciesAbleBatch aBatch, + String messageKey) { + + Integer sampleCategoryId = aBatch.getSampleCategoryId(); + + if (!sampleCategoryModel.containsCategoryId(sampleCategoryId)) { + + // invalid sample category id + addError(errors, + messageKey, + aBatch.getId(), + aBatch.getSpecies().getName(), + sampleCategoryId); + } + + if (!aBatch.isChildBatchsEmpty()) { + + for (SpeciesAbleBatch speciesAbleBatch : aBatch.getChildBatchs()) { + + validateBatch(sampleCategoryModel, + errors, + speciesAbleBatch, + messageKey); + } + } + } + protected void addError(List<CatchBatchValidationError> errors, String messageKey) { CatchBatchValidationError error = new CatchBatchValidationError( @@ -279,6 +325,15 @@ errors.add(error); } + protected void addError(List<CatchBatchValidationError> errors, + String messageKey, Object... params) { + CatchBatchValidationError error = new CatchBatchValidationError( + messageKey, + _(messageKey, params), + CatchBatchValidationError.GRAVITY_ERROR); + errors.add(error); + } + protected void addWarning(List<CatchBatchValidationError> errors, String messageKey) { CatchBatchValidationError error = new CatchBatchValidationError( Modified: trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties =================================================================== --- trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_en_GB.properties 2013-07-25 17:32:14 UTC (rev 1156) @@ -23,6 +23,8 @@ tutti.persistence.batch.validation.horsVracMarineLitterNotFound= tutti.persistence.batch.validation.horsVracNotFound= tutti.persistence.batch.validation.horsVracSpeciesNotFound= +tutti.persistence.batch.validation.invalid.benthos.sampleCategoryId= +tutti.persistence.batch.validation.invalid.species.sampleCategoryId= tutti.persistence.batch.validation.unkonwn.taxon= tutti.persistence.batch.validation.unsortedNotFound= tutti.persistence.batch.validation.vracBenthosAliveItemizedNotFound= Modified: trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties =================================================================== --- trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-persistence/src/main/resources/i18n/tutti-persistence_fr_FR.properties 2013-07-25 17:32:14 UTC (rev 1156) @@ -18,11 +18,13 @@ tutti.config.persistence=Configuration de la persistance de l'application tutti.persistence.attachment.copyFile.error=Erreur lors de la copie de la pièce jointe %1s dans le fichier %2s tutti.persistence.attachment.deleteFile.error=Erreur lors de la suppression de la pièce jointe %s -tutti.persistence.batch.validation.bad.sample.categories=Il existe des lots avec des catégories d'échantillon non compatible avec le modèle configuré \:<br/>%s +tutti.persistence.batch.validation.bad.sample.categories=Il existe des lots avec des catégories d'échantillon non compatible avec le modèle configuré \:<br/> %s tutti.persistence.batch.validation.horsVracBenthosNotFound=Lot 'Hors Vrac > Benthos' non trouvé ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.horsVracMarineLitterNotFound=Lot 'Hors Vrac > Macro-déchet' non trouvé, ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.horsVracNotFound=Lot 'Hors Vrac' non trouvé ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.horsVracSpeciesNotFound=Lot 'Hors Vrac > Espèces' non trouvé ou configuré avec d'autres critères de classement. +tutti.persistence.batch.validation.invalid.benthos.sampleCategoryId=Le lot benthos %s (espèce %s) utilise une caractéristique (id %s) de catégorisation non reconnue +tutti.persistence.batch.validation.invalid.species.sampleCategoryId=Le lot espèce %s (espèce %s) utilise une caractéristique (id %s) de catégorisation non reconnue tutti.persistence.batch.validation.unkonwn.taxon=Le lot (%s) utilise une espèce de code inconnu (%s). tutti.persistence.batch.validation.unsortedNotFound=Lot 'Hors Vrac > Espèces' non trouvé ou configuré avec d'autres critères de classement. tutti.persistence.batch.validation.vracBenthosAliveItemizedNotFound=Lot 'Vrac > Benthos > Vivant Trié' non trouvé, ou configuré avec d'autres critères de classement. Modified: trunk/tutti-persistence/src/main/xmi/tutti-persistence.zargo =================================================================== (Binary files differ) 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-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -745,11 +745,6 @@ //------------------------------------------------------------------------// @Override - public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId) { - return driver.getRootSpeciesBatch(fishingOperationId, null); - } - - @Override public BatchContainer<SpeciesBatch> getRootSpeciesBatch(String fishingOperationId, SampleCategoryModel sampleCategoryModel) { return driver.getRootSpeciesBatch(fishingOperationId, sampleCategoryModel); @@ -797,11 +792,6 @@ //------------------------------------------------------------------------// @Override - public BatchContainer<BenthosBatch> getRootBenthosBatch(String fishingOperationId) { - return driver.getRootBenthosBatch(fishingOperationId); - } - - @Override public BatchContainer<BenthosBatch> getRootBenthosBatch(String fishingOperationId, SampleCategoryModel sampleCategoryModel) throws InvalidBatchModelException { return driver.getRootBenthosBatch(fishingOperationId, sampleCategoryModel); } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingService.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -126,7 +126,7 @@ } catch (TuttiBusinessException e) { result.put(fishingOperationId, e.getMessage()); - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId); + rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, null); } BatchContainer<BenthosBatch> rootBenthosBatch; @@ -135,7 +135,7 @@ } catch (TuttiBusinessException e) { result.put(fishingOperationId, e.getMessage()); - rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId); + rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, null); } BatchContainer<MarineLitterBatch> rootMarineLitterBatch; @@ -360,7 +360,7 @@ BatchContainer<SpeciesBatch> rootSpeciesBatch = null; if (persistenceService.isFishingOperationWithCatchBatch(operation.getId())) { - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId()); + rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId(), null); currentSpeciesRowIndex = 0; if (rootSpeciesBatch != null) { @@ -545,7 +545,7 @@ BatchContainer<BenthosBatch> rootBenthosBatch = null; if (persistenceService.isFishingOperationWithCatchBatch(operation.getId())) { - rootBenthosBatch = persistenceService.getRootBenthosBatch(operation.getId()); + rootBenthosBatch = persistenceService.getRootBenthosBatch(operation.getId(), null); currentBenthosRowIndex = 0; if (rootBenthosBatch != null) { Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/ValidateCruiseOperationsService.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -244,7 +244,7 @@ boolean error = !isCatchBatch; if (isCatchBatch) { - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId); + rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, sampleCategoryModel); if (rootSpeciesBatch != null) { List<SpeciesBatch> roots = rootSpeciesBatch.getChildren(); @@ -261,13 +261,13 @@ } } if (error) { - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId); + rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, sampleCategoryModel); } BatchContainer<BenthosBatch> rootBenthosBatch = null; error = false; if (isCatchBatch) { - rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId); + rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, sampleCategoryModel); if (rootBenthosBatch != null) { List<BenthosBatch> roots = rootBenthosBatch.getChildren(); @@ -284,7 +284,7 @@ } } if (error) { - rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId); + rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, sampleCategoryModel); } BatchContainer<MarineLitterBatch> rootMarineLitterBatch; Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportExportService.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/multipost/TuttiMultiPostImportExportService.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -155,7 +155,7 @@ if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { BatchContainer<SpeciesBatch> speciesBatchContainer = - persistenceService.getRootSpeciesBatch(operationId); + persistenceService.getRootSpeciesBatch(operationId, null); List<CatchRow> rows = Lists.newArrayList(); List<CatchFrequencyRow> frequencyRows = Lists.newArrayList(); @@ -189,7 +189,7 @@ if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { BatchContainer<BenthosBatch> benthosBatchContainer = - persistenceService.getRootBenthosBatch(operationId); + persistenceService.getRootBenthosBatch(operationId, null); List<CatchRow> rows = Lists.newArrayList(); List<CatchFrequencyRow> frequencyRows = Lists.newArrayList(); @@ -526,7 +526,7 @@ final Map<String, SpeciesBatch> notImportedBatches = Maps.newLinkedHashMap(); BatchContainer<SpeciesBatch> speciesBatches = - persistenceService.getRootSpeciesBatch(operation.getId()); + persistenceService.getRootSpeciesBatch(operation.getId(), null); TuttiDataContext dataContext = context.getDataContext(); List<Species> speciesList = dataContext.getReferentSpecies(); @@ -733,7 +733,7 @@ final Map<String, BenthosBatch> notImportedBatches = Maps.newLinkedHashMap(); BatchContainer<BenthosBatch> benthosBatches = - persistenceService.getRootBenthosBatch(operation.getId()); + persistenceService.getRootBenthosBatch(operation.getId(), null); TuttiDataContext dataContext = context.getDataContext(); List<Species> speciesList = dataContext.getReferentSpecies(); Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportService.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -341,7 +341,7 @@ result = notFoundSpecies.size(); catchBatch.setCatchTotalSortedCarousselWeight(carrouselSortedWeight); - BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId()); + BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId(), null); for (SpeciesBatch batch : rootSpeciesBatch.getChildren()) { persistenceService.deleteSpeciesBatch(batch.getId()); } Modified: trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportService.java =================================================================== --- trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportService.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/main/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportService.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -30,6 +30,7 @@ import com.google.common.collect.Maps; import com.google.common.io.Files; import fr.ifremer.tutti.TuttiTechnicalException; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; import fr.ifremer.tutti.persistence.entities.data.Cruise; @@ -61,8 +62,6 @@ private static final Log log = LogFactory.getLog(TuttiCatchesSumatraExportService.class); - public static final char CSV_SEPARATOR = ';'; - protected PersistenceService persistenceService; protected TuttiWeightComputingService tuttiWeightComputingService; @@ -78,16 +77,17 @@ String cruiseId) { Preconditions.checkNotNull(cruiseId, "Cannot export a null cruise"); + Preconditions.checkNotNull(file, "Cannot export to a null file"); if (log.isInfoEnabled()) { log.info("Will export cruise " + cruiseId + " to file: " + file); } Cruise cruise = persistenceService.getCruise(cruiseId); - Preconditions.checkNotNull(cruise, "Cruise not found"); + Preconditions.checkNotNull(cruise, "Cruise [" + cruiseId + "] not found"); CatchRowModel csvModel = - new CatchRowModel(CSV_SEPARATOR); + new CatchRowModel(context.getConfig().getCsvSeparator()); List<CatchRow> rows = Lists.newArrayList(); List<FishingOperation> operations = persistenceService.getAllFishingOperation(cruiseId); @@ -147,16 +147,15 @@ for (BenthosBatch batch : benthosBatches) { Species sp = batch.getSpecies(); - Float weight = batch.getSampleCategoryWeight(); - if (weight == null) { - weight = batch.getSampleCategoryComputedWeight(); - } + Float weight = TuttiEntities.getValueOrComputedValue( + batch.getSampleCategoryWeight(), + batch.getSampleCategoryComputedWeight()); - Integer nb = batch.getNumber(); + Integer nb = TuttiEntities.getValueOrComputedValue( + batch.getNumber(), + batch.getComputedNumber()); + if (nb == null) { - nb = batch.getComputedNumber(); - } - if (nb == null) { nb = 0; } Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/ServiceDbResource.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/ServiceDbResource.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/ServiceDbResource.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -24,14 +24,24 @@ * #L% */ +import com.google.common.collect.Lists; +import com.google.common.io.Files; import fr.ifremer.tutti.persistence.RessourceClassLoader; import fr.ifremer.tutti.persistence.config.TuttiPersistenceConfigOption; +import fr.ifremer.tutti.persistence.entities.TuttiEntities; +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; +import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.persistence.test.DatabaseResource; import fr.ifremer.tutti.service.config.TuttiServiceConfig; import fr.ifremer.tutti.service.config.TuttiServiceConfigOption; import fr.ifremer.tutti.service.protocol.TuttiProtocolImportExportService; +import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Assert; import org.junit.runner.Description; import org.nuiton.config.ApplicationConfig; @@ -39,6 +49,7 @@ import java.io.File; import java.io.IOException; +import java.util.List; import java.util.Locale; /** @@ -49,6 +60,22 @@ */ public class ServiceDbResource extends DatabaseResource { + /** Logger. */ + private static final Log log = LogFactory.getLog(ServiceDbResource.class); + + public static void assertFileContent(String message, + File actualFile, + String expectedContent) throws IOException { + Assert.assertTrue(actualFile.exists()); + String fileContent = Files.toString(actualFile, + Charsets.UTF_8).trim(); + Assert.assertEquals(expectedContent, fileContent); + + if (log.isInfoEnabled()) { + log.info(message + fileContent); + } + } + protected TuttiServiceContext createServiceContext(RessourceClassLoader loader, TuttiServiceConfig config) { return new TuttiServiceContext(loader, config); @@ -144,4 +171,77 @@ IOUtils.closeQuietly(serviceContext); super.after(description); } + + public DataContext loadContext(String programId, String cruiseId, int nbExpectedOperations, String... expectedOperationId) { + + DataContext dataContext = new DataContext(); + PersistenceService persistenceService = getServiceContext().getService(PersistenceService.class); + + Program program = persistenceService.getProgram(programId); + Assert.assertNotNull(program); + + Cruise cruise = persistenceService.getCruise(cruiseId); + Assert.assertNotNull(cruise); + + List<FishingOperation> operations = persistenceService.getAllFishingOperation(cruise.getId()); + Assert.assertNotNull(operations); + Assert.assertEquals(nbExpectedOperations, operations.size()); + if (expectedOperationId != null) { + int index = 0; + for (String id : expectedOperationId) { + FishingOperation fishingOperation = operations.get(index); + Assert.assertEquals("Fishign operation at index " + (index++) + " should have id " + id + " but was " + fishingOperation.getId(), id, fishingOperation.getId()); + } + } + + // load fully operations + List<FishingOperation> loadedOperations = + Lists.newArrayListWithCapacity(operations.size()); + for (FishingOperation operation : operations) { + FishingOperation loadedOeration = + persistenceService.getFishingOperation(operation.getId()); + loadedOperations.add(loadedOeration); + } + operations = loadedOperations; + + dataContext.program = program; + dataContext.cruise = cruise; + dataContext.operations = operations; + + return dataContext; + } + + public void openDataContext() { + + TuttiServiceContext serviceContext = getServiceContext(); + + PersistenceService persistenceService = serviceContext.getService(PersistenceService.class); + + serviceContext.getDataContext().open(serviceContext.getConfig(), persistenceService); + } + + public TuttiServiceContext setCountryInConfig(String countryCode) { + TuttiServiceContext serviceContext = getServiceContext(); + + PersistenceService persistenceService = serviceContext.getService(PersistenceService.class); + + // set export country id in configuration + List<TuttiLocation> allCountry = persistenceService.getAllCountry(); + Assert.assertNotNull(allCountry); + Assert.assertFalse(allCountry.isEmpty()); + TuttiLocation franceCountry = TuttiEntities.splitById(allCountry).get(countryCode); + Assert.assertNotNull(franceCountry); + getServiceConfig().setExportCountry(franceCountry.getId()); + return serviceContext; + } + + public static class DataContext { + + public Program program; + + public Cruise cruise; + + public List<FishingOperation> operations; + + } } Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/catches/TuttiWeightComputingServiceTest.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -95,7 +95,7 @@ public void computeCatchWeights() { CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_2_ID); try { - BatchContainer<SpeciesBatch> batches = persistenceService.getRootSpeciesBatch(OPERATION_2_ID); + BatchContainer<SpeciesBatch> batches = persistenceService.getRootSpeciesBatch(OPERATION_2_ID, null); tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, batches, null, null); Assert.fail(); @@ -108,7 +108,7 @@ catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_3_ID); try { - BatchContainer<BenthosBatch> batches = persistenceService.getRootBenthosBatch(OPERATION_3_ID); + BatchContainer<BenthosBatch> batches = persistenceService.getRootBenthosBatch(OPERATION_3_ID, null); tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, null, batches, null); Assert.fail(); @@ -134,8 +134,8 @@ catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_5_ID); try { - BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_5_ID); - BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_5_ID); + BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_5_ID, null); + BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_5_ID, null); tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, speciesBatches, benthosBatches, null); Assert.fail(); @@ -160,8 +160,8 @@ catchBatch = persistenceService.getCatchBatchFromFishingOperation(OPERATION_7_ID); try { - BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_7_ID); - BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_7_ID); + BatchContainer<SpeciesBatch> speciesBatches = persistenceService.getRootSpeciesBatch(OPERATION_7_ID, null); + BatchContainer<BenthosBatch> benthosBatches = persistenceService.getRootBenthosBatch(OPERATION_7_ID, null); tuttiWeightComputingService.computeCatchBatchWeights(catchBatch, speciesBatches, benthosBatches, null); if (log.isInfoEnabled()) { log.info("Weight computing worked on operation #7"); @@ -174,7 +174,7 @@ @Test public void computeSpeciesBatch() { - BatchContainer<SpeciesBatch> speciesBatchContainer = persistenceService.getRootSpeciesBatch(OPERATION_1_ID); + BatchContainer<SpeciesBatch> speciesBatchContainer = persistenceService.getRootSpeciesBatch(OPERATION_1_ID, null); List<SpeciesBatch> speciesBatches = speciesBatchContainer.getChildren(); for (int i = 0 ; i < speciesBatches.size() - 1 ; i++) { try { @@ -199,7 +199,7 @@ Assert.fail(); } - BatchContainer<BenthosBatch> benthosBatchContainer = persistenceService.getRootBenthosBatch(OPERATION_1_ID); + BatchContainer<BenthosBatch> benthosBatchContainer = persistenceService.getRootBenthosBatch(OPERATION_1_ID, null); List<BenthosBatch> benthosBatches = benthosBatchContainer.getChildren(); for (int i = 0 ; i < benthosBatches.size() - 1 ; i++) { try { Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportService2Test.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -24,30 +24,13 @@ * #L% */ -import com.google.common.collect.Lists; -import com.google.common.io.Files; -import fr.ifremer.tutti.persistence.ProgressionModel; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; -import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; -import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; -import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ServiceDbResource; import fr.ifremer.tutti.service.TuttiServiceContext; -import org.apache.commons.io.Charsets; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import java.io.File; -import java.io.IOException; -import java.util.List; /** * Test export of catches. @@ -57,10 +40,6 @@ */ public class TuttiExportService2Test { - /** Logger. */ - private static final Log log = - LogFactory.getLog(TuttiExportService2Test.class); - @ClassRule public static final ServiceDbResource dbResource = ServiceDbResource.readDb("dbExport"); @@ -95,25 +74,10 @@ "\n" + "commentaire...\";Vrac;2;18.0;;Poids;kg;NA;;;;;kg;NA;;;;;kg;NA;;;;;kg;NA;;;;;kg;;;;;;;;;18.0;7.0;"; - protected TuttiExportService service; - protected PersistenceService persistenceService; + protected ServiceDbResource.DataContext dataContext; - protected Program program; - - protected Cruise cruise; - - protected Cruise cruiseCGFS; - - protected List<FishingOperation> operations; - - protected List<MarineLitterBatch> marineLitters; - - protected List<IndividualObservationBatch> individualObservations; - - protected ProgressionModel progressionModel; - protected File dataDirectory; @Before @@ -121,29 +85,15 @@ dataDirectory = dbResource.getServiceConfig().getDataDirectory(); - TuttiServiceContext serviceContext = dbResource.getServiceContext(); + dbResource.setCountryInConfig("12"); - persistenceService = serviceContext.getService(PersistenceService.class); + dbResource.openDataContext(); - // set export country id in configuration - List<TuttiLocation> allCountry = persistenceService.getAllCountry(); - Assert.assertNotNull(allCountry); - Assert.assertFalse(allCountry.isEmpty()); - TuttiLocation franceCountry = TuttiEntities.splitById(allCountry).get("12"); - Assert.assertNotNull(franceCountry); - dbResource.getServiceConfig().setExportCountry(franceCountry.getId()); + TuttiServiceContext serviceContext = dbResource.getServiceContext(); - serviceContext.getDataContext().open(serviceContext.getConfig(), persistenceService); - service = serviceContext.getService(TuttiExportService.class); - loadData(PROGRAM_ID, CRUISE_ID); - Assert.assertEquals(2, operations.size()); - Assert.assertEquals(OPERATION_1_ID, operations.get(0).getId()); - Assert.assertEquals(OPERATION_2_ID, operations.get(1).getId()); - - progressionModel = new ProgressionModel(); - progressionModel.setTotal(8); + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 2, OPERATION_1_ID, OPERATION_2_ID); } @Test @@ -153,46 +103,12 @@ service.createExportContext(dataDirectory, null); try { - service.exportCatches(exportContext, cruise, operations); + service.exportCatches(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("Catch export:\n", - exportContext.catchFile, - CATCH_CONTENT); + ServiceDbResource.assertFileContent("Catch export:\n", + exportContext.catchFile, + CATCH_CONTENT); } - - protected void assertFileContent(String message, - File actualFile, - String expectedContent) throws IOException { - Assert.assertTrue(actualFile.exists()); - String fileContent = Files.toString(actualFile, - Charsets.UTF_8).trim(); - Assert.assertEquals(expectedContent, fileContent); - - if (log.isInfoEnabled()) { - log.info(message + fileContent); - } - } - - protected void loadData(String programId, String cruiseId) { - program = persistenceService.getProgram(programId); - Assert.assertNotNull(program); - - cruise = persistenceService.getCruise(cruiseId); - Assert.assertNotNull(cruise); - - operations = persistenceService.getAllFishingOperation(cruise.getId()); - Assert.assertNotNull(operations); - - // load fully operations - List<FishingOperation> loadedOperations = - Lists.newArrayListWithCapacity(operations.size()); - for (FishingOperation operation : operations) { - FishingOperation loadedOeration = - persistenceService.getFishingOperation(operation.getId()); - loadedOperations.add(loadedOeration); - } - operations = loadedOperations; - } } Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/export/TuttiExportServiceTest.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -28,20 +28,12 @@ import com.google.common.io.Files; import fr.ifremer.tutti.persistence.ProgressionModel; import fr.ifremer.tutti.persistence.entities.TuttiEntities; -import fr.ifremer.tutti.persistence.entities.data.Cruise; import fr.ifremer.tutti.persistence.entities.data.FishingOperation; -import fr.ifremer.tutti.persistence.entities.data.IndividualObservationBatch; -import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; -import fr.ifremer.tutti.persistence.entities.data.Program; import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol; import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ServiceDbResource; import fr.ifremer.tutti.service.TuttiServiceContext; -import org.apache.commons.io.Charsets; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; @@ -49,7 +41,6 @@ import org.junit.Test; import java.io.File; -import java.io.IOException; import java.util.List; import java.util.Map; @@ -59,10 +50,6 @@ */ public class TuttiExportServiceTest { - /** Logger. */ - private static final Log log = - LogFactory.getLog(TuttiExportServiceTest.class); - @ClassRule public static final ServiceDbResource dbResource = ServiceDbResource.readDb("dbCGFS"); @@ -199,22 +186,14 @@ "1986;LIMDLIM;Limanda limanda;;\n" + "1988;MICTKIT;Microstomus kitt;;"; + public static final int NB_EXPECTED_CGFS_OPERATIONS = 106; + protected TuttiExportService service; protected PersistenceService persistenceService; - protected Program program; + protected ServiceDbResource.DataContext dataContext; - protected Cruise cruise; - - protected Cruise cruiseCGFS; - - protected List<FishingOperation> operations; - - protected List<MarineLitterBatch> marineLitters; - - protected List<IndividualObservationBatch> individualObservations; - protected ProgressionModel progressionModel; protected File dataDirectory; @@ -228,22 +207,12 @@ persistenceService = serviceContext.getService(PersistenceService.class); - // set export country id in configuration - List<TuttiLocation> allCountry = persistenceService.getAllCountry(); - Assert.assertNotNull(allCountry); - Assert.assertFalse(allCountry.isEmpty()); - TuttiLocation franceCountry = TuttiEntities.splitById(allCountry).get("12"); - Assert.assertNotNull(franceCountry); - dbResource.getServiceConfig().setExportCountry(franceCountry.getId()); + dbResource.setCountryInConfig("12"); + dbResource.openDataContext(); - serviceContext.getDataContext().open(serviceContext.getConfig(), persistenceService); - service = serviceContext.getService(TuttiExportService.class); - loadData(PROGRAM_ID, CRUISE_ID); - Assert.assertEquals(2, operations.size()); - Assert.assertEquals(OPERATION_1_ID, operations.get(0).getId()); - Assert.assertEquals(OPERATION_2_ID, operations.get(1).getId()); + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 2, OPERATION_1_ID, OPERATION_2_ID); progressionModel = new ProgressionModel(); progressionModel.setTotal(9); @@ -259,7 +228,7 @@ Assert.assertFalse(exportFile.exists()); - service.exportProgram(program.getId(), null, exportFile, progressionModel); + service.exportProgram(dataContext.program.getId(), null, exportFile, progressionModel); Assert.assertTrue(exportFile.exists()); } @@ -272,7 +241,7 @@ Assert.assertFalse(exportFile.exists()); - service.exportCruise(cruise.getId(), null, exportFile, progressionModel); + service.exportCruise(dataContext.cruise.getId(), null, exportFile, progressionModel); Assert.assertTrue(exportFile.exists()); } @@ -283,13 +252,13 @@ service.createExportContext(dataDirectory, null); try { - service.exportSurvey(exportContext, cruise); + service.exportSurvey(exportContext, dataContext.cruise); } finally { exportContext.close(); } - assertFileContent("Survey export:\n", - exportContext.surveyFile, - SURVEY_CONTENT); + ServiceDbResource.assertFileContent("Survey export:\n", + exportContext.surveyFile, + SURVEY_CONTENT); } @Test @@ -299,13 +268,13 @@ service.createExportContext(dataDirectory, null); try { - service.exportGearCaracteristics(exportContext, cruise); + service.exportGearCaracteristics(exportContext, dataContext.cruise); } finally { exportContext.close(); } - assertFileContent("Gear caracteristics export:\n", - exportContext.gearCaracteristicsFile, - GEAR_CARACTERISTICS_CONTENT); + ServiceDbResource.assertFileContent("Gear caracteristics export:\n", + exportContext.gearCaracteristicsFile, + GEAR_CARACTERISTICS_CONTENT); } @Test @@ -317,35 +286,35 @@ service.createExportContext(dataDirectory, null); try { - service.exportOperations(exportContext, cruise, operations); + service.exportOperations(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("Operation export:\n", - exportContext.operationFile, - OPERATION_CONTENT); + ServiceDbResource.assertFileContent("Operation export:\n", + exportContext.operationFile, + OPERATION_CONTENT); } @Test public void exportOperationsWithNoCatches() throws Exception { - loadData(PROGRAM_ID, CRUISE_CGFS_ID); + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_CGFS_ID, NB_EXPECTED_CGFS_OPERATIONS); - FishingOperation operation = TuttiEntities.findById(operations, "100105"); - operations = Lists.newArrayList(operation); + FishingOperation operation = TuttiEntities.findById(dataContext.operations, "100105"); + dataContext.operations = Lists.newArrayList(operation); TuttiExportService.ExportContext exportContext = service.createExportContext(dataDirectory, null); try { - service.exportOperations(exportContext, cruise, operations); + service.exportOperations(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("Operation export:\n", - exportContext.operationFile, - OPERATION_WITH_NO_CATCH_CONTENT); + ServiceDbResource.assertFileContent("Operation export:\n", + exportContext.operationFile, + OPERATION_WITH_NO_CATCH_CONTENT); } @Test @@ -355,13 +324,13 @@ service.createExportContext(dataDirectory, null); try { - service.exportParameters(exportContext, cruise, operations); + service.exportParameters(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("Parameter export:\n", - exportContext.parameterFile, - PARAMETER_CONTENT); + ServiceDbResource.assertFileContent("Parameter export:\n", + exportContext.parameterFile, + PARAMETER_CONTENT); } @Test @@ -371,13 +340,13 @@ service.createExportContext(dataDirectory, null); try { - service.exportCatches(exportContext, cruise, operations); + service.exportCatches(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("Catch export:\n", - exportContext.catchFile, - CATCH_CONTENT); + ServiceDbResource.assertFileContent("Catch export:\n", + exportContext.catchFile, + CATCH_CONTENT); } // To fix http://forge.codelutin.com/issues/2692 @@ -388,28 +357,28 @@ TuttiProtocol protocol = dbResource.loadProtocol(protocolFile); - loadData(PROGRAM_ID, CRUISE_CGFS_ID); + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_CGFS_ID, NB_EXPECTED_CGFS_OPERATIONS); - FishingOperation operation = TuttiEntities.findById(operations, "100000"); - operations = Lists.newArrayList(operation); + FishingOperation operation = TuttiEntities.findById(dataContext.operations, "100000"); + dataContext.operations = Lists.newArrayList(operation); TuttiExportService.ExportContext exportContext = service.createExportContext(dataDirectory, protocol); try { - service.exportCatches(exportContext, cruise, operations); + service.exportCatches(exportContext, dataContext.cruise, dataContext.operations); service.exportSpecies(exportContext, exportContext.getSpeciesToExport()); } finally { exportContext.close(); } - assertFileContent("species export:\n", - exportContext.speciesFile, - SPECIES_CONTENT_2); + ServiceDbResource.assertFileContent("species export:\n", + exportContext.speciesFile, + SPECIES_CONTENT_2); - assertFileContent("Catch export:\n", - exportContext.catchFile, - CATCH_CONTENT_2); + ServiceDbResource.assertFileContent("Catch export:\n", + exportContext.catchFile, + CATCH_CONTENT_2); } @@ -418,13 +387,13 @@ @Test public void exportBadCatches() throws Exception { - loadData(PROGRAM_ID, CRUISE_CGFS_ID); + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_CGFS_ID, NB_EXPECTED_CGFS_OPERATIONS); TuttiExportService.ExportContext exportContext = service.createExportContext(dataDirectory, null); try { - service.exportCatches(exportContext, cruise, operations); + service.exportCatches(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } @@ -437,13 +406,13 @@ service.createExportContext(dataDirectory, null); try { - service.exportMarineLitters(exportContext, cruise, operations); + service.exportMarineLitters(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("MarineLitter export:\n", - exportContext.marineLitterFile, - MARINE_LITTER_CONTENT); + ServiceDbResource.assertFileContent("MarineLitter export:\n", + exportContext.marineLitterFile, + MARINE_LITTER_CONTENT); } @Test @@ -453,13 +422,13 @@ service.createExportContext(dataDirectory, null); try { - service.exportIndividualObservations(exportContext, cruise, operations); + service.exportIndividualObservations(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("individualObservation export:\n", - exportContext.individualObservationFile, - INDIVIDUAL_OBSERVATION_CONTENT); + ServiceDbResource.assertFileContent("individualObservation export:\n", + exportContext.individualObservationFile, + INDIVIDUAL_OBSERVATION_CONTENT); } @Test @@ -469,13 +438,13 @@ service.createExportContext(dataDirectory, null); try { - service.exportAccidentalCatch(exportContext, cruise, operations); + service.exportAccidentalCatch(exportContext, dataContext.cruise, dataContext.operations); } finally { exportContext.close(); } - assertFileContent("accidentalCatch export:\n", - exportContext.accidentalCatchFile, - ACCIDENTAL_CATCH_CONTENT); + ServiceDbResource.assertFileContent("accidentalCatch export:\n", + exportContext.accidentalCatchFile, + ACCIDENTAL_CATCH_CONTENT); } @Test @@ -499,43 +468,9 @@ } finally { exportContext.close(); } - assertFileContent("species export:\n", - exportContext.speciesFile, - SPECIES_CONTENT); + ServiceDbResource.assertFileContent("species export:\n", + exportContext.speciesFile, + SPECIES_CONTENT); } - - protected void assertFileContent(String message, - File actualFile, - String expectedContent) throws IOException { - Assert.assertTrue(actualFile.exists()); - String fileContent = Files.toString(actualFile, - Charsets.UTF_8).trim(); - Assert.assertEquals(expectedContent, fileContent); - - if (log.isInfoEnabled()) { - log.info(message + fileContent); - } - } - - protected void loadData(String programId, String cruiseId) { - program = persistenceService.getProgram(programId); - Assert.assertNotNull(program); - - cruise = persistenceService.getCruise(cruiseId); - Assert.assertNotNull(cruise); - - operations = persistenceService.getAllFishingOperation(cruise.getId()); - Assert.assertNotNull(operations); - - // load fully operations - List<FishingOperation> loadedOperations = - Lists.newArrayListWithCapacity(operations.size()); - for (FishingOperation operation : operations) { - FishingOperation loadedOeration = - persistenceService.getFishingOperation(operation.getId()); - loadedOperations.add(loadedOeration); - } - operations = loadedOperations; - } } Modified: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportServiceTest.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/pupitri/TuttiPupitriImportExportServiceTest.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -24,15 +24,10 @@ * #L% */ -import com.google.common.collect.Lists; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.BatchContainer; 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.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.ServiceDbResource; import fr.ifremer.tutti.service.TuttiServiceContext; @@ -43,7 +38,6 @@ import java.io.File; import java.io.IOException; -import java.util.List; /** * @author tchemit <chemit@codelutin.com> @@ -67,14 +61,8 @@ protected PersistenceService persistenceService; - protected Program program; + protected ServiceDbResource.DataContext dataContext; - protected Cruise cruise; - - protected Cruise cruiseCGFS; - - protected List<FishingOperation> operations; - @Before public void setUp() throws Exception { @@ -82,60 +70,28 @@ persistenceService = serviceContext.getService(PersistenceService.class); - // set export country id in configuration - List<TuttiLocation> allCountry = persistenceService.getAllCountry(); - Assert.assertNotNull(allCountry); - Assert.assertFalse(allCountry.isEmpty()); - TuttiLocation franceCountry = TuttiEntities.splitById(allCountry).get("12"); - Assert.assertNotNull(franceCountry); - dbResource.getServiceConfig().setExportCountry(franceCountry.getId()); + dbResource.openDataContext(); - serviceContext.getDataContext().open(serviceContext.getConfig(), persistenceService); - service = serviceContext.getService(TuttiPupitriImportExportService.class); - loadData(PROGRAM_ID, CRUISE_ID); - Assert.assertEquals(2, operations.size()); - Assert.assertEquals(OPERATION_1_ID, operations.get(0).getId()); - Assert.assertEquals(OPERATION_2_ID, operations.get(1).getId()); + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 2, OPERATION_1_ID, OPERATION_2_ID); } - protected void loadData(String programId, String cruiseId) { - program = persistenceService.getProgram(programId); - Assert.assertNotNull(program); - - cruise = persistenceService.getCruise(cruiseId); - Assert.assertNotNull(cruise); - - operations = persistenceService.getAllFishingOperation(cruise.getId()); - Assert.assertNotNull(operations); - - // load fully operations - List<FishingOperation> loadedOperations = - Lists.newArrayListWithCapacity(operations.size()); - for (FishingOperation operation : operations) { - FishingOperation loadedOeration = - persistenceService.getFishingOperation(operation.getId()); - loadedOperations.add(loadedOeration); - } - operations = loadedOperations; - } - @Test public void importPupitri() throws IOException { File trunk = dbResource.copyClassPathResource("pupitri/pupitri.tnk", "pupitri.tnk"); File carroussel = dbResource.copyClassPathResource("pupitri/pupitri.car", "pupitri.car"); - FishingOperation operation = operations.get(0); + FishingOperation operation = dataContext.operations.get(0); CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(operation.getId()); catchBatch.setFishingOperation(operation); - BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId()); + BatchContainer<SpeciesBatch> rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operation.getId(), null); Assert.assertEquals(3, rootSpeciesBatch.sizeChildren()); int nbAdded = service.importPupitri(trunk, carroussel, operation, catchBatch); Assert.assertEquals(6, nbAdded); - BatchContainer<SpeciesBatch> rootSpeciesBatchAfter = persistenceService.getRootSpeciesBatch(operation.getId()); + BatchContainer<SpeciesBatch> rootSpeciesBatchAfter = persistenceService.getRootSpeciesBatch(operation.getId(), null); Assert.assertEquals(18, rootSpeciesBatchAfter.sizeChildren()); int index = 0; Added: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportServiceTest.java =================================================================== --- trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportServiceTest.java (rev 0) +++ trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportServiceTest.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -0,0 +1,94 @@ +package fr.ifremer.tutti.service.sumatra; + +/* + * #%L + * Tutti :: Service + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2012 - 2013 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.tutti.service.ServiceDbResource; +import fr.ifremer.tutti.service.TuttiServiceContext; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.io.File; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 2.5 + */ +public class TuttiCatchesSumatraExportServiceTest { + + @ClassRule + public static final ServiceDbResource dbResource = + ServiceDbResource.readDb("dbExport"); + + public static final String PROGRAM_ID = "CAM-TEST_ELEVATION"; + + public static final String CRUISE_ID = "100003"; + + public static final String OPERATION_1_ID = "100112"; + + public static final String OPERATION_2_ID = "100113"; + + public static final String EXPORT_CONTENT = + "Station;Espèce;Total;NbIndividus\n" + + "A;Agonus cataphractus;100.0;0;\n" + + "A;Alosa alosa;100.0;0;\n" + + "B;Agonus cataphractus;100.0;0;\n" + + "B;Alosa alosa;100.0;0;\n" + + "B;Abietinaria abietina;30.0;0;\n" + + "B;Acanthocardia echinata;18.0;0;"; + + protected TuttiCatchesSumatraExportService service; + + protected ServiceDbResource.DataContext dataContext; + + protected File dataDirectory; + + @Before + public void setUp() throws Exception { + + dataDirectory = dbResource.getServiceConfig().getDataDirectory(); + + TuttiServiceContext serviceContext = dbResource.getServiceContext(); + + dbResource.openDataContext(); + + service = serviceContext.getService(TuttiCatchesSumatraExportService.class); + + dataContext = dbResource.loadContext(PROGRAM_ID, CRUISE_ID, 2, OPERATION_1_ID, OPERATION_2_ID); + } + + + @Test + public void testExportCruiseForSumatra() throws Exception { + + File exportFile = new File(dataDirectory, "exportSumatra.csv"); + + service.exportCruiseForSumatra(exportFile, CRUISE_ID); + + ServiceDbResource.assertFileContent("Sumatra export file:\n", + exportFile, + EXPORT_CONTENT); + } +} Property changes on: trunk/tutti-service/src/test/java/fr/ifremer/tutti/service/sumatra/TuttiCatchesSumatraExportServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/EditFishingOperationAction.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -35,7 +35,6 @@ import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.service.TuttiDataContext; import fr.ifremer.tutti.ui.swing.content.operation.catches.ComputeWeightsAction; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI; import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel; @@ -47,7 +46,6 @@ import fr.ifremer.tutti.ui.swing.util.action.TuttiActionHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; import javax.swing.JLabel; import javax.swing.JOptionPane; @@ -468,21 +466,6 @@ handler.installCoordinatesListener(); } -// public String getFishingOperationTitle(FishingOperation bean) { -// String fishingOperationText; -// -// if (bean == null) { -// fishingOperationText = null; -// } else if (TuttiEntities.isNew(bean)) { -// fishingOperationText = _("tutti.editFishingOperation.label.traitReminder", -// _("tutti.editFishingOperation.label.traitReminder.inCreation")); -// } else { -// fishingOperationText = _("tutti.editFishingOperation.label.traitReminder", -// decorate(bean)); -// } -// return fishingOperationText; -// } - public void loadCatchBatch(FishingOperation bean, boolean loadOtherTabs) { Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/benthos/BenthosBatchUIHandler.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -198,7 +198,8 @@ // get all batch species root (says the one with only a species sample category) BatchContainer<BenthosBatch> rootBenthosBatch = - persistenceService.getRootBenthosBatch(bean.getId()); + persistenceService.getRootBenthosBatch( + bean.getId(), sampleCategoryModel); List<BenthosBatch> catches = rootBenthosBatch.getChildren(); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-07-25 14:45:48 UTC (rev 1155) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-07-25 17:32:14 UTC (rev 1156) @@ -202,7 +202,8 @@ // get all batch species root (says the one with only a species sample category) BatchContainer<SpeciesBatch> rootSpeciesBatch = - persistenceService.getRootSpeciesBatch(bean.getId()); + persistenceService.getRootSpeciesBatch( + bean.getId(), sampleCategoryModel); List<SpeciesBatch> catches = rootSpeciesBatch.getChildren();
participants (1)
-
tchemit@users.forge.codelutin.com