This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit 3aba570d9b5400698d0554947486f488b444a490 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Oct 21 18:11:58 2014 +0200 refs #5997 split import - export service + begin of implements delete and other stuff... --- .../tutti/persistence/TuttiPersistenceImpl.java | 36 +- .../persistence/TuttiPersistenceNoDbImpl.java | 28 +- .../service/ReferentialPersistenceService.java | 56 +- .../service/ReferentialPersistenceServiceImpl.java | 97 ++- .../ifremer/tutti/service/PersistenceService.java | 36 +- .../catches/WeightComputingService.java.orig | 778 --------------------- ...tService.java => ReferentialExportService.java} | 276 ++------ ...tService.java => ReferentialImportService.java} | 75 +- .../tutti/service/PersistenceServiceTest.java | 20 +- .../referential/ReferentialExportServiceTest.java | 139 ++++ ...Test.java => ReferentialImportServiceTest.java} | 69 +- .../fr/ifremer/tutti/ui/swing/TuttiUIContext.java | 11 +- .../action/AbstractReplaceTemporaryUIAction.java | 17 +- ...java => ExportExistingTemporaryGearAction.java} | 19 +- ...va => ExportExistingTemporaryPersonAction.java} | 19 +- ...a => ExportExistingTemporarySpeciesAction.java} | 19 +- ...va => ExportExistingTemporaryVesselAction.java} | 23 +- .../action/ExportTemporaryGearExampleAction.java | 5 +- .../action/ExportTemporaryPersonExampleAction.java | 7 +- .../ExportTemporarySpeciesExampleAction.java | 7 +- .../action/ExportTemporaryVesselExampleAction.java | 7 +- .../ui/swing/action/ImportTemporaryGearAction.java | 6 +- .../swing/action/ImportTemporaryPersonAction.java | 6 +- .../swing/action/ImportTemporarySpeciesAction.java | 6 +- .../swing/action/ImportTemporaryVesselAction.java | 6 +- .../swing/action/ReplaceTemporaryGearAction.java | 4 +- .../swing/action/ReplaceTemporaryPersonAction.java | 4 +- .../action/ReplaceTemporarySpeciesAction.java | 4 +- .../swing/action/ReplaceTemporaryVesselAction.java | 4 +- .../replace/AbstractReplaceTemporaryUIModel.java | 13 + .../resources/i18n/tutti-ui-swing_fr_FR.properties | 1 + 31 files changed, 622 insertions(+), 1176 deletions(-) diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java index a53de84..5a41454 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceImpl.java @@ -462,23 +462,43 @@ public class TuttiPersistenceImpl implements TuttiPersistence { } @Override - public void replaceGear(Gear source, Gear target) { - referentialService.replaceGear(source, target); + public void replaceGear(Gear source, Gear target, boolean delete) { + referentialService.replaceGear(source, target, delete); } @Override - public void replacePerson(Person source, Person target) { - referentialService.replacePerson(source, target); + public void replacePerson(Person source, Person target, boolean delete) { + referentialService.replacePerson(source, target, delete); } @Override - public void replaceSpecies(Species source, Species target) { - referentialService.replaceSpecies(source, target); + public void replaceSpecies(Species source, Species target, boolean delete) { + referentialService.replaceSpecies(source, target, delete); } @Override - public void replaceVessel(Vessel source, Vessel target) { - referentialService.replaceVessel(source, target); + public void replaceVessel(Vessel source, Vessel target, boolean delete) { + referentialService.replaceVessel(source, target, delete); + } + + @Override + public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { + referentialService.deleteTemporaryGear(id, checkIfUsed); + } + + @Override + public void deleteTemporarySpecies(Integer id, boolean checkIfUsed) { + referentialService.deleteTemporarySpecies(id, checkIfUsed); + } + + @Override + public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { + referentialService.deleteTemporaryPerson(id, checkIfUsed); + } + + @Override + public void deleteTemporaryVessel(String code, boolean checkIfUsed) { + referentialService.deleteTemporaryVessel(code, checkIfUsed); } //------------------------------------------------------------------------// diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java index df5d7eb..4ca7737 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/TuttiPersistenceNoDbImpl.java @@ -726,22 +726,42 @@ public class TuttiPersistenceNoDbImpl implements TuttiPersistence { } @Override - public void replaceGear(Gear source, Gear target) { + public void replaceGear(Gear source, Gear target, boolean delete) { throw notImplemented(); } @Override - public void replacePerson(Person source, Person target) { + public void replacePerson(Person source, Person target, boolean delete) { throw notImplemented(); } @Override - public void replaceSpecies(Species source, Species target) { + public void replaceSpecies(Species source, Species target, boolean delete) { throw notImplemented(); } @Override - public void replaceVessel(Vessel source, Vessel target) { + public void replaceVessel(Vessel source, Vessel target, boolean delete) { + throw notImplemented(); + } + + @Override + public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { + throw notImplemented(); + } + + @Override + public void deleteTemporarySpecies(Integer id, boolean checkIfUsed) { + throw notImplemented(); + } + + @Override + public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { + throw notImplemented(); + } + + @Override + public void deleteTemporaryVessel(String code, boolean checkIfUsed) { throw notImplemented(); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java index 88c23f2..a21b100 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java @@ -321,11 +321,12 @@ public interface ReferentialPersistenceService extends TuttiPersistenceServiceIm * * @param source the source gear to replace * @param target the target gear to use + * @param delete flag to delete the temporary vessel after replacement * @since 3.6 */ @Transactional(readOnly = false) @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", allEntries = true) - void replaceGear(Gear source, Gear target); + void replaceGear(Gear source, Gear target, boolean delete); /** * Replace the {@code source} species by @@ -333,11 +334,12 @@ public interface ReferentialPersistenceService extends TuttiPersistenceServiceIm * * @param source the source species to replace * @param target the target species to use + * @param delete flag to delete the temporary vessel after replacement * @since 3.6 */ @Transactional(readOnly = false) @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", allEntries = true) - void replaceSpecies(Species source, Species target); + void replaceSpecies(Species source, Species target, boolean delete); /** * Replace the {@code source} person by @@ -345,11 +347,12 @@ public interface ReferentialPersistenceService extends TuttiPersistenceServiceIm * * @param source the source person to replace * @param target the target person to use + * @param delete flag to delete the temporary vessel after replacement * @since 3.6 */ @Transactional(readOnly = false) @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", allEntries = true) - void replacePerson(Person source, Person target); + void replacePerson(Person source, Person target, boolean delete); /** * Replace the {@code source} vessel by @@ -357,10 +360,55 @@ public interface ReferentialPersistenceService extends TuttiPersistenceServiceIm * * @param source the source vessel to replace * @param target the target vessel to use + * @param delete flag to delete the temporary vessel after replacement * @since 3.6 */ @Transactional(readOnly = false) @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", allEntries = true) - void replaceVessel(Vessel source, Vessel target); + void replaceVessel(Vessel source, Vessel target, boolean delete); + + /** + * Delete the temporary gear with the given {@code id}. + * + * @param id id of the gear to remove + * @param checkIfUsed to check if gear is used before trying to delete it + * @since 3.9 + */ + @Transactional(readOnly = false) + @CacheEvict(value = "gears", allEntries = true) + void deleteTemporaryGear(Integer id, boolean checkIfUsed); + + /** + * Delete the temporary species with the given {@code id}. + * + * @param id id of the species to remove + * @param checkIfUsed to check if species is used before trying to delete it + * @since 3.9 + */ + @Transactional(readOnly = false) + @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular"}, allEntries = true) + void deleteTemporarySpecies(Integer id, boolean checkIfUsed); + + /** + * Delete the temporary person with the given {@code id}. + * + * @param id id of the person to remove + * @param checkIfUsed to check if person is used before trying to delete it + * @since 3.9 + */ + @Transactional(readOnly = false) + @CacheEvict(value = {"persons", "personById"}, allEntries = true) + void deleteTemporaryPerson(Integer id, boolean checkIfUsed); + + /** + * Delete the temporary vessel with the given {@code code}. + * + * @param code code of the vessel to remove + * @param checkIfUsed to check if vessel is used before trying to delete it + * @since 3.9 + */ + @Transactional(readOnly = false) + @CacheEvict(value = {"fishingVessels", "vesselByCode"}, allEntries = true) + void deleteTemporaryVessel(String code, boolean checkIfUsed); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java index 8c0447a..2db70c7 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java @@ -48,6 +48,7 @@ import fr.ifremer.adagio.core.dao.referential.pmfm.UnitId; import fr.ifremer.adagio.core.dao.referential.taxon.TaxonNameExtendDao; import fr.ifremer.adagio.core.dao.referential.taxon.TaxonRefVO; import fr.ifremer.adagio.core.dao.referential.transcribing.TranscribingItemTypeId; +import fr.ifremer.adagio.core.dao.technical.hibernate.TemporaryDataHelper; import fr.ifremer.adagio.core.service.technical.CacheService; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatchs; @@ -78,6 +79,7 @@ import org.hibernate.Query; import org.hibernate.type.DateType; import org.hibernate.type.IntegerType; import org.hibernate.type.StringType; +import org.nuiton.jaxx.application.ApplicationBusinessException; import org.springframework.cache.Cache; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataRetrievalFailureException; @@ -790,7 +792,7 @@ public class ReferentialPersistenceServiceImpl extends AbstractPersistenceServic } @Override - public void replaceGear(Gear source, Gear target) { + public void replaceGear(Gear source, Gear target, boolean delete) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(target); @@ -810,10 +812,16 @@ public class ReferentialPersistenceServiceImpl extends AbstractPersistenceServic //TODO Check doublon... + if (delete) { + + deleteTemporaryGear(sourceId, false); + + } + } @Override - public void replacePerson(Person source, Person target) { + public void replacePerson(Person source, Person target, boolean delete) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(target); @@ -843,10 +851,16 @@ public class ReferentialPersistenceServiceImpl extends AbstractPersistenceServic //TODO Check doublon... + if (delete) { + + deleteTemporaryPerson(sourceId, false); + + } + } @Override - public void replaceSpecies(Species source, Species target) { + public void replaceSpecies(Species source, Species target, boolean delete) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(target); @@ -866,10 +880,16 @@ public class ReferentialPersistenceServiceImpl extends AbstractPersistenceServic //TODO Check doublon... + if (delete) { + + deleteTemporarySpecies(sourceId, false); + + } + } @Override - public void replaceVessel(Vessel source, Vessel target) { + public void replaceVessel(Vessel source, Vessel target, boolean delete) { Preconditions.checkNotNull(source); Preconditions.checkNotNull(target); @@ -917,6 +937,75 @@ public class ReferentialPersistenceServiceImpl extends AbstractPersistenceServic //TODO Check doublon... + if (delete) { + + deleteTemporaryVessel(sourceId, false); + + } + + } + + @Override + public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { + + Preconditions.checkNotNull(id); + if (id > 0) { + throw new ApplicationBusinessException(String.format("Can't delete a Gear with a positive id %d.", id)); + } + Gear gear = getGear(id); + if (gear == null) { + throw new ApplicationBusinessException(String.format("Gear with id %d does not exists", id)); + } + + fishingGearDao.remove(id); + + } + + @Override + public void deleteTemporarySpecies(Integer id, boolean checkIfUsed) { + + Preconditions.checkNotNull(id); + if (id > 0) { + throw new ApplicationBusinessException(String.format("Can't delete a Species with a positive id %d.", id)); + } + Species species = getSpeciesByReferenceTaxonId(id); + if (species == null) { + throw new ApplicationBusinessException(String.format("Species with id %d does not exists", id)); + } + + taxonNameDao.remove(id); + + } + + @Override + public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { + + Preconditions.checkNotNull(id); + if (id > 0) { + throw new ApplicationBusinessException(String.format("Can't delete a Gear with a positive id %d.", id)); + } + Gear gear = getGear(id); + if (gear == null) { + throw new ApplicationBusinessException(String.format("Gear with id %d does not exists", id)); + } + personDao.remove(id); + + } + + @Override + public void deleteTemporaryVessel(String code, boolean checkIfUsed) { + + Preconditions.checkNotNull(code); + if (!code.startsWith(TemporaryDataHelper.TEMPORARY_NAME_PREFIX)) { + throw new ApplicationBusinessException(String.format("Can't delete a Vessel with a code %s not beginning with %s.", code, TemporaryDataHelper.TEMPORARY_NAME_PREFIX)); + } + Vessel vessel = getVessel(code); + if (vessel == null) { + throw new ApplicationBusinessException(String.format("Vessel with code %s does not exists", code)); + } + + vesselExtendDao.remove(code); + } //------------------------------------------------------------------------// diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java index f010359..3e3b874 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/PersistenceService.java @@ -967,23 +967,43 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } @Override - public void replaceGear(Gear source, Gear target) { - driver.replaceGear(source, target); + public void replaceGear(Gear source, Gear target, boolean delete) { + driver.replaceGear(source, target, delete); } @Override - public void replacePerson(Person source, Person target) { - driver.replacePerson(source, target); + public void replacePerson(Person source, Person target, boolean delete) { + driver.replacePerson(source, target, delete); } @Override - public void replaceSpecies(Species source, Species target) { - driver.replaceSpecies(source, target); + public void replaceSpecies(Species source, Species target, boolean delete) { + driver.replaceSpecies(source, target, delete); } @Override - public void replaceVessel(Vessel source, Vessel target) { - driver.replaceVessel(source, target); + public void replaceVessel(Vessel source, Vessel target, boolean delete) { + driver.replaceVessel(source, target, delete); + } + + @Override + public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { + driver.deleteTemporaryGear(id, checkIfUsed); + } + + @Override + public void deleteTemporarySpecies(Integer id, boolean checkIfUsed) { + driver.deleteTemporarySpecies(id, checkIfUsed); + } + + @Override + public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { + driver.deleteTemporaryPerson(id, checkIfUsed); + } + + @Override + public void deleteTemporaryVessel(String code, boolean checkIfUsed) { + driver.deleteTemporaryVessel(code, checkIfUsed); } //------------------------------------------------------------------------// diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java.orig b/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java.orig deleted file mode 100644 index dbedc61..0000000 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/catches/WeightComputingService.java.orig +++ /dev/null @@ -1,778 +0,0 @@ -package fr.ifremer.tutti.service.catches; - -/* - * #%L - * Tutti :: Service - * %% - * Copyright (C) 2012 - 2014 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 com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import fr.ifremer.tutti.util.Numbers; -import fr.ifremer.tutti.util.Weights; -import fr.ifremer.tutti.persistence.entities.data.BatchContainer; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatch; -import fr.ifremer.tutti.persistence.entities.data.BenthosBatchFrequency; -import fr.ifremer.tutti.persistence.entities.data.CatchBatch; -import fr.ifremer.tutti.persistence.entities.data.MarineLitterBatch; -import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModelEntry; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch; -import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.service.AbstractTuttiService; -import fr.ifremer.tutti.service.DecoratorService; -import fr.ifremer.tutti.service.PersistenceService; -import fr.ifremer.tutti.service.TuttiServiceContext; -import fr.ifremer.tutti.service.ValidationService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.jaxx.application.ApplicationBusinessException; -import org.nuiton.validator.NuitonValidatorResult; - -import java.util.List; -import java.util.Map; - -import static org.nuiton.i18n.I18n.t; - -/** - * @author kmorin <kmorin@codelutin.com> - * @since 1.3 - */ -public class WeightComputingService extends AbstractTuttiService { - - private static final Log log = - LogFactory.getLog(WeightComputingService.class); - - protected PersistenceService persistenceService; - - protected ValidationService validationService; - - protected DecoratorService decoratorService; - - protected SampleCategoryModel sampleCategoryModel; - - @Override - public void setServiceContext(TuttiServiceContext context) { - super.setServiceContext(context); - persistenceService = getService(PersistenceService.class); - validationService = getService(ValidationService.class); - decoratorService = getService(DecoratorService.class); - sampleCategoryModel = context.getSampleCategoryModel(); - } - - /** - * To check if can compute for any fishing operation of the cruise given - * by his id. - * <p/> - * If no error found, then return is a empty map, otherwise the first error - * found for any bad fishing operation. - * <p/> - * Result keys are fishing operation id, values the first error for - * the fishing operation. - * - * @param cruiseId id of the cruise to check. - * @param uniqueFishingOperationId optional unique fishing operation to check - * @return map of errors, or empty map if no error found. - * @since 1.4 - */ - public Map<String, String> checkCruise(String cruiseId, - String uniqueFishingOperationId) { - - if (log.isDebugEnabled()) { - log.debug("Will check cruise: " + cruiseId); - } - Map<String, String> result = Maps.newTreeMap(); - - List<String> allFishingOperation; - - if (StringUtils.isNotBlank(uniqueFishingOperationId)) { - allFishingOperation = Lists.newArrayList(uniqueFishingOperationId); - } else { - allFishingOperation = persistenceService.getAllFishingOperationIds(cruiseId); - } - - for (String fishingOperationId : allFishingOperation) { - - boolean withCatchBatch = - persistenceService.isFishingOperationWithCatchBatch( - fishingOperationId); - - if (!withCatchBatch) { - if (log.isWarnEnabled()) { - log.warn("Skip fishing operation " + fishingOperationId + - " since no catchBatch associated."); - } - continue; - } - CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId); - - BatchContainer<SpeciesBatch> rootSpeciesBatch; - try { - rootSpeciesBatch = getComputedSpeciesBatches(fishingOperationId); - - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(fishingOperationId, false); - } - - BatchContainer<BenthosBatch> rootBenthosBatch; - try { - rootBenthosBatch = getComputedBenthosBatches(fishingOperationId); - - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - rootBenthosBatch = persistenceService.getRootBenthosBatch(fishingOperationId, false); - } - - BatchContainer<MarineLitterBatch> rootMarineLitterBatch; - try { - Float weight = catchBatch == null ? null : catchBatch.getMarineLitterTotalWeight(); - rootMarineLitterBatch = getComputedMarineLitterBatches(fishingOperationId, weight); - - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - rootMarineLitterBatch = persistenceService.getRootMarineLitterBatch(fishingOperationId); - } - - try { - if (catchBatch != null) { - computeCatchBatchWeights(catchBatch, - rootSpeciesBatch, - rootBenthosBatch, - rootMarineLitterBatch); - } - } catch (ApplicationBusinessException e) { - result.put(fishingOperationId, e.getMessage()); - } - } - return result; - } - - /** - * Compute the weights of the catch batch (not the ones of the species, benthos nor marine litter batches) - * - * @param catchBatch the catch batch with the weights to compute - * @param rootSpeciesBatch the species batches with already computed weights - * @param rootBenthosBatch the benthos batches with already computed weights - * @param rootMarineLitterBatch the marine litter batches with already computed weights - */ - public void computeCatchBatchWeights(CatchBatch catchBatch, - BatchContainer<SpeciesBatch> rootSpeciesBatch, - BatchContainer<BenthosBatch> rootBenthosBatch, - BatchContainer<MarineLitterBatch> rootMarineLitterBatch) { - - // Species - Float speciesTotalComputedSortedWeight = 0f; - Float speciesTotalComputedUnsortedWeight = 0f; - - if (rootSpeciesBatch != null) { - List<SpeciesBatch> speciesBatches = rootSpeciesBatch.getChildren(); - for (SpeciesBatch row : speciesBatches) { - Float weight = Numbers.getValueOrComputedValue( - row.getSampleCategoryWeight(), - row.getSampleCategoryComputedWeight()); - if (weight == null) { - break; - } - - if (persistenceService.isVracBatch(row)) { - speciesTotalComputedSortedWeight += weight; - } else { - speciesTotalComputedUnsortedWeight += weight; - } - } - } - - Number inertWeight = catchBatch.getSpeciesTotalInertWeight(); - if (inertWeight != null) { - speciesTotalComputedSortedWeight += inertWeight.floatValue(); - } else { - catchBatch.setSpeciesTotalInertComputedWeight(0f); - } - - Number livingNotItemizedWeight = catchBatch.getSpeciesTotalLivingNotItemizedWeight(); - if (livingNotItemizedWeight != null) { - speciesTotalComputedSortedWeight += livingNotItemizedWeight.floatValue(); - } else { - catchBatch.setSpeciesTotalLivingNotItemizedComputedWeight(0f); - } - - catchBatch.setSpeciesTotalSampleSortedComputedWeight(speciesTotalComputedSortedWeight); - - Float speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedWeight(); - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = speciesTotalComputedSortedWeight; - catchBatch.setSpeciesTotalSortedComputedWeight( - Weights.roundKiloGram(speciesTotalSortedWeight)); - - } else if (speciesTotalSortedWeight < speciesTotalComputedSortedWeight) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted")); - } - catchBatch.setSpeciesTotalUnsortedComputedWeight( - Weights.roundKiloGram(speciesTotalComputedUnsortedWeight)); - - if (speciesTotalSortedWeight == null) { - speciesTotalSortedWeight = catchBatch.getSpeciesTotalSortedComputedWeight(); - } - Float speciesTotalWeight = speciesTotalComputedUnsortedWeight + speciesTotalSortedWeight; - catchBatch.setSpeciesTotalComputedWeight( - Weights.roundKiloGram(speciesTotalWeight)); - - // Benthos - Float benthosTotalComputedSortedWeight = 0f; - Float benthosTotalComputedUnsortedWeight = 0f; - - if (rootBenthosBatch != null) { - List<BenthosBatch> benthosBatches = rootBenthosBatch.getChildren(); - for (BenthosBatch row : benthosBatches) { - Float weight = Numbers.getValueOrComputedValue( - row.getSampleCategoryWeight(), - row.getSampleCategoryComputedWeight()); - if (weight == null) { - break; - } - - if (persistenceService.isVracBatch(row)) { - benthosTotalComputedSortedWeight += weight; - } else { - benthosTotalComputedUnsortedWeight += weight; - } - } - } - - inertWeight = catchBatch.getBenthosTotalInertWeight(); - if (inertWeight != null) { - benthosTotalComputedSortedWeight += inertWeight.floatValue(); - } else { - catchBatch.setBenthosTotalInertComputedWeight(0f); - } - - livingNotItemizedWeight = catchBatch.getBenthosTotalLivingNotItemizedWeight(); - if (livingNotItemizedWeight != null) { - benthosTotalComputedSortedWeight += livingNotItemizedWeight.floatValue(); - } else { - catchBatch.setBenthosTotalLivingNotItemizedComputedWeight(0f); - } - - catchBatch.setBenthosTotalSampleSortedComputedWeight( - Weights.roundKiloGram(benthosTotalComputedSortedWeight)); - - Float benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedWeight(); - if (benthosTotalSortedWeight == null) { - benthosTotalSortedWeight = benthosTotalComputedSortedWeight; - catchBatch.setBenthosTotalSortedComputedWeight( - Weights.roundKiloGram(benthosTotalSortedWeight)); - - } else if (benthosTotalSortedWeight < benthosTotalComputedSortedWeight) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.benthos.incoherentTotalSorted")); - } - catchBatch.setBenthosTotalUnsortedComputedWeight( - Weights.roundKiloGram(benthosTotalComputedUnsortedWeight)); - - if (benthosTotalSortedWeight == null) { - benthosTotalSortedWeight = catchBatch.getBenthosTotalSortedComputedWeight(); - } - Float benthosTotalWeight = benthosTotalComputedUnsortedWeight + benthosTotalSortedWeight; - catchBatch.setBenthosTotalComputedWeight( - Weights.roundKiloGram(benthosTotalWeight)); - - // Marine litter - Float marineLitterTotalComputedWeight = 0f; - - if (rootMarineLitterBatch != null) { - List<MarineLitterBatch> marineLitterBatches = rootMarineLitterBatch.getChildren(); - for (MarineLitterBatch row : marineLitterBatches) { - Float rowWeight = row.getWeight(); - if (rowWeight == null) { - marineLitterTotalComputedWeight = null; - break; - } - marineLitterTotalComputedWeight += rowWeight; - } - } - if (marineLitterTotalComputedWeight != null) { - catchBatch.setMarineLitterTotalComputedWeight( - Weights.roundKiloGram(marineLitterTotalComputedWeight)); - } - - Float marineLitterTotalWeight = catchBatch.getMarineLitterTotalWeight(); - if (marineLitterTotalWeight == null) { - marineLitterTotalWeight = marineLitterTotalComputedWeight; - - } else if (marineLitterTotalComputedWeight != null && marineLitterTotalWeight < marineLitterTotalComputedWeight) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.marineLitter.incoherentTotal")); - } - // nothing to do with the marine litter weight, it is an isolated weight - - // Catch - Float totalUnsortedWeight = catchBatch.getSpeciesTotalUnsortedComputedWeight() + - catchBatch.getBenthosTotalUnsortedComputedWeight(); - - Float totalSortedWeight = speciesTotalSortedWeight + benthosTotalSortedWeight; - - catchBatch.setCatchTotalSortedComputedWeight(Weights.roundKiloGram(totalSortedWeight)); - catchBatch.setCatchTotalUnsortedComputedWeight(Weights.roundKiloGram(totalUnsortedWeight)); - - Float totalWeight = catchBatch.getCatchTotalWeight(); - Float rejectedWeight = catchBatch.getCatchTotalRejectedWeight(); - - if (rejectedWeight == null && totalWeight != null) { -<<<<<<< HEAD - if (totalWeight.compareTo(totalUnsortedWeight + totalSortedWeight) < 1) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.totalLessThanSortedAndUnsorted")); -// -======= - if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedWeight)) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); - ->>>>>>> fixes #5139 [CAPTURE] répéter le champ "poids sous échantillon" dans la fenêtre de saisie des mensurations - } else { - catchBatch.setCatchTotalRejectedComputedWeight( - Weights.roundKiloGram(totalWeight - - totalUnsortedWeight - - totalSortedWeight)); - } - - } else if (totalWeight == null) { - if (rejectedWeight == null) { - rejectedWeight = 0f; - catchBatch.setCatchTotalRejectedComputedWeight(0f); - } - catchBatch.setCatchTotalComputedWeight( - Weights.roundKiloGram(totalUnsortedWeight - + totalSortedWeight - + rejectedWeight)); - - } else if (Weights.isNotEqualWeight(totalWeight, totalUnsortedWeight + totalSortedWeight + rejectedWeight)) { - throw new ApplicationBusinessException(t("tutti.service.operations.computeWeights.error.incoherentTotal")); - } - } - - private int currentSpeciesRowIndex; - - public BatchContainer<SpeciesBatch> getComputedSpeciesBatches(String operationId) { - - BatchContainer<SpeciesBatch> rootSpeciesBatch = null; - - if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { - rootSpeciesBatch = persistenceService.getRootSpeciesBatch(operationId, false); - - currentSpeciesRowIndex = 0; - if (rootSpeciesBatch != null) { - List<SpeciesBatch> roots = rootSpeciesBatch.getChildren(); - - for (SpeciesBatch batch : roots) { - computeSpeciesBatch(batch); - } - } - } - - return rootSpeciesBatch; - } - - protected String getCategoryLabel(Integer sampleCategoryId) { - SampleCategoryModelEntry category = - sampleCategoryModel.getCategoryById(sampleCategoryId); - String result = category.getLabel(); - return result; - } - - public Float computeSpeciesBatch(SpeciesBatch batch) { - Float result = null; - int thisIndex = currentSpeciesRowIndex++; - Float categoryWeight = batch.getSampleCategoryWeight(); - Float rowWeight = batch.getWeight(); - String species = decoratorService.getDecoratorByType(Species.class).toString(batch.getSpecies()); - String categoryValue = decoratorService.getDecorator(batch.getSampleCategoryValue()) - .toString(batch.getSampleCategoryValue()); - - NuitonValidatorResult validation = validationService.validateEditSpeciesBatch(batch); - if (!validation.isValid()) { - List<String> messages = validation.getErrorMessages(SpeciesBatch.PROPERTY_WEIGHT); - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); - } - - List<SpeciesBatch> children = batch.getChildBatchs(); - // if the row is not a leaf - if (batch.sizeChildBatchs() > 0) { - Float sum = 0f; - // make the sum of the children weights - for (SpeciesBatch child : children) { - Float weight = computeSpeciesBatch(child); - if (weight == null) { - sum = null; - break; - } - sum += weight; - } - - if (sum != null) { - if (categoryWeight == null) { - batch.setSampleCategoryComputedWeight(Weights.roundKiloGram(sum)); - - } else if (Weights.isSmallerWeight(categoryWeight, sum)) { - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); - - } else { - sum = categoryWeight; - } - result = sum; - } - - } else {// the row is a leaf - - batch.setComputedWeight(null); - - List<SpeciesBatchFrequency> frequencies = persistenceService.getAllSpeciesBatchFrequency(batch.getId()); - - if (CollectionUtils.isNotEmpty(frequencies)) { - // if there are frequencies, then compute their weight - Float frequencyWeight = 0f; - for (SpeciesBatchFrequency frequency : frequencies) { - Float w = frequency.getWeight(); - if (w == null) { - - // can't sum when a null value appears - frequencyWeight = null; - break; - - } else if (frequencyWeight != null) { - - // still can sum weights - frequencyWeight += w; - } - } - - if (categoryWeight == null && rowWeight != null) { -// throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - - } else if (rowWeight != null && frequencyWeight != null - && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { - - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency", - species, - categoryLabel, - categoryValue, - frequencyWeight, - rowWeight), - SpeciesBatch.PROPERTY_WEIGHT, - thisIndex); - - } else if (categoryWeight == null && frequencyWeight != null) { - // if the category weight is null and the frequencies have a weight, - // then this weight is the result - batch.setSampleCategoryComputedWeight(Weights.roundKiloGram(frequencyWeight)); - result = frequencyWeight; - - } else if (frequencyWeight != null - && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { - - // if the weight of the frequencies is different from the category - // weight, then set the weight of the sample - if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { - - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); - - } else if (rowWeight == null) { - batch.setComputedWeight(Weights.roundKiloGram(frequencyWeight)); - - } - result = categoryWeight; - - } else { - result = categoryWeight; - } - - // compute number from frequencies - Integer frequencyNumber = 0; - for (SpeciesBatchFrequency frequency : frequencies) { - Integer c = frequency.getNumber(); - frequencyNumber += c; - } - batch.setComputedNumber(frequencyNumber); - - } else { - result = categoryWeight; - } - } - if (result == null) { - - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.species.noWeight", - species, - categoryLabel, - categoryValue), - SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); - } - - return Weights.roundKiloGram(result); - } - - private int currentBenthosRowIndex; - - public BatchContainer<BenthosBatch> getComputedBenthosBatches(String operationId) { - - BatchContainer<BenthosBatch> rootBenthosBatch = null; - - if (persistenceService.isFishingOperationWithCatchBatch(operationId)) { - rootBenthosBatch = persistenceService.getRootBenthosBatch(operationId, false); - - currentBenthosRowIndex = 0; - if (rootBenthosBatch != null) { - List<BenthosBatch> roots = rootBenthosBatch.getChildren(); - - for (BenthosBatch batch : roots) { - computeBenthosBatch(batch); - } - } - } - - return rootBenthosBatch; - } - - public Float computeBenthosBatch(BenthosBatch batch) { - Float result = null; - int thisIndex = currentBenthosRowIndex++; - Float categoryWeight = batch.getSampleCategoryWeight(); - Float rowWeight = batch.getWeight(); - String species = decoratorService.getDecoratorByType(Species.class).toString(batch.getSpecies()); - String categoryValue = decoratorService.getDecorator(batch.getSampleCategoryValue()) - .toString(batch.getSampleCategoryValue()); - - NuitonValidatorResult validation = validationService.validateEditBenthosBatch(batch); - if (!validation.isValid()) { - List<String> messages = validation.getErrorMessages(BenthosBatch.PROPERTY_WEIGHT); - - String categoryLabel = getCategoryLabel(batch.getSampleCategoryId()); - throw new TuttiWeightComputingException(t(messages.get(0), - species, - categoryLabel, - categoryValue, - batch.getWeight(), - batch.getSampleCategoryWeight()), - BenthosBatch.PROPERTY_WEIGHT, - thisIndex); - } - - List<BenthosBatch> children = batch.getChildBatchs(); - // if the row is not a leaf - if (!batch.isChildBatchsEmpty()) { - Float sum = 0f; - // make the sum of the children weights - for (BenthosBatch child : children) { - Float weight = computeBenthosBatch(child); - if (weight == null) { - sum = null; - break; - } - sum += weight; - } - - if (sum != null) { - if (categoryWeight == null) { - batch.setSampleCategoryComputedWeight(Weights.roundKiloGram(sum)); - - } else if (Weights.isSmallerWeight(categoryWeight, sum)) { - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); - - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.incoherentParentCategoryWeight", - species, - categoryLabel, - categoryValue, - categoryWeight, - sum), - BenthosBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); - - } else { - sum = categoryWeight; - } - result = sum; - - } - - } else {// the row is a leaf - - batch.setComputedWeight(null); - - List<BenthosBatchFrequency> frequencies = persistenceService.getAllBenthosBatchFrequency(batch.getId()); - - if (CollectionUtils.isNotEmpty(frequencies)) { - // if there are frequencies, then compute their weight - Float frequencyWeight = 0f; - for (BenthosBatchFrequency frequency : frequencies) { - Float w = frequency.getWeight(); - if (w == null) { - - // can't sum when a null value appears - frequencyWeight = null; - break; - - } else if (frequencyWeight != null) { - - // still can sum weights - frequencyWeight += w; - } - } - - if (categoryWeight == null && rowWeight != null) { -// throw new TuttiBusinessException(t("tutti.service.operations.computeWeights.error.incoherentRowWeightCategory")); - - } else if (rowWeight != null && frequencyWeight != null - && Weights.isNotEqualWeight(rowWeight, frequencyWeight)) { - - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); - - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.incoherentRowWeightFrequency", - species, - categoryLabel, - categoryValue, - rowWeight, - categoryWeight), - BenthosBatch.PROPERTY_WEIGHT, - thisIndex); - - } else if (categoryWeight == null && frequencyWeight != null) { - // if the category weight is null and the frequencies have a weight, - // then this weight is the result - batch.setSampleCategoryComputedWeight(Weights.roundKiloGram(frequencyWeight)); - result = frequencyWeight; - - } else if (frequencyWeight != null - && Weights.isNotEqualWeight(frequencyWeight, categoryWeight)) { - - // if the weight of the frequencies is different from the category - // weight, then set the weight of the sample - if (Weights.isGreaterWeight(frequencyWeight, categoryWeight)) { - - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); - - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.incoherentCategoryWeight", - species, - categoryLabel, - categoryValue, - frequencyWeight, - categoryWeight), - BenthosBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); - - } else if (rowWeight == null) { - batch.setComputedWeight(Weights.roundKiloGram(frequencyWeight)); - - } - result = categoryWeight; - - } else { - result = categoryWeight; - } - - // compute number from frequencies - Integer frequencyNumber = 0; - for (BenthosBatchFrequency frequency : frequencies) { - Integer c = frequency.getNumber(); - frequencyNumber += c; - } - batch.setComputedNumber(frequencyNumber); - } else { - result = categoryWeight; - } - } - if (result == null) { - - String categoryLabel = - getCategoryLabel(batch.getSampleCategoryId()); - - throw new TuttiWeightComputingException( - t("tutti.service.operations.computeWeights.error.benthos.noWeight", - species, - categoryLabel, - categoryValue), - BenthosBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, - thisIndex); - } - - return Weights.roundKiloGram(result); - } - - public BatchContainer<MarineLitterBatch> getComputedMarineLitterBatches(String fishingOperationId, - Float marineLitterweight) { - - BatchContainer<MarineLitterBatch> rootMarineLitterBatch = - persistenceService.getRootMarineLitterBatch(fishingOperationId); - - if (rootMarineLitterBatch != null) { - boolean checkWeight = marineLitterweight == null; - - List<MarineLitterBatch> children = rootMarineLitterBatch.getChildren(); - for (int i = 0; i < children.size(); i++) { - MarineLitterBatch batch = children.get(i); - if (checkWeight && batch.getWeight() == null) { - throw new TuttiWeightComputingException( - t("tutti.validator.warning.marineLitter.weight.required"), - MarineLitterBatch.PROPERTY_WEIGHT, - i); - } - } - } - - return rootMarineLitterBatch; - } -} diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialExportService.java similarity index 50% copy from tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportExportService.java copy to tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialExportService.java index 4d8fede..1e69ee9 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialExportService.java @@ -23,12 +23,8 @@ package fr.ifremer.tutti.service.referential; */ import com.google.common.base.Charsets; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.google.common.io.Files; -import org.nuiton.jaxx.application.ApplicationTechnicalException; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Gears; import fr.ifremer.tutti.persistence.entities.referential.Person; @@ -41,32 +37,23 @@ import fr.ifremer.tutti.service.AbstractTuttiService; import fr.ifremer.tutti.service.PersistenceService; import fr.ifremer.tutti.service.TuttiServiceContext; import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Export; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportRuntimeException; +import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.BufferedWriter; import java.io.File; import java.io.IOException; -import java.io.Reader; import java.util.List; -import java.util.Set; import static org.nuiton.i18n.I18n.t; /** - * Service to import or export referential. + * Service to export temporary referential. * * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public class ReferentialImportExportService extends AbstractTuttiService { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ReferentialImportExportService.class); +public class ReferentialExportService extends AbstractTuttiService { protected PersistenceService persistenceService; @@ -76,206 +63,14 @@ public class ReferentialImportExportService extends AbstractTuttiService { persistenceService = getService(PersistenceService.class); } - public List<Species> importTemporarySpecies(File file) throws IOException { - - if (log.isInfoEnabled()) { - log.info("Will import species from file: " + file); - } - - // get all species names - Set<String> existingSpeciesName = Sets.newHashSet(Iterables.transform(persistenceService.getAllSpecies(), new Function<Species, String>() { - @Override - public String apply(Species input) { - return input.getName(); - } - })); - - List<Species> toImport = Lists.newArrayList(); - - Reader reader = Files.newReader(file, Charsets.UTF_8); - SpeciesModel csvModel = new SpeciesModel(getCsvSeparator(), existingSpeciesName); - try { - Import<Species> importer = Import.newImport(csvModel, reader); - - try { - - for (Species bean : importer) { - toImport.add(bean); - } - importer.close(); - } finally { - IOUtils.closeQuietly(importer); - } - reader.close(); - - } catch (IOException e) { - throw new IOException(t("tutti.service.referential.import.species.error", file), e); - - } catch (ImportRuntimeException e) { - String message; - if (e.getCause() != null) { - message = e.getCause().getMessage(); - } else { - message = e.getMessage(); - } - throw new ApplicationTechnicalException(message, e); - - } finally { - - IOUtils.closeQuietly(reader); - } - - List<Species> result = - persistenceService.importTemporarySpecies(toImport); - return result; - } - - public List<Vessel> importTemporaryVessel(File file) throws IOException { - if (log.isInfoEnabled()) { - log.info("Will import vessels from file: " + file); - } - - // get all vessels - List<Vessel> existingVessels = Lists.newArrayList(persistenceService.getAllFishingVessel()); - existingVessels.addAll(persistenceService.getAllScientificVessel()); + public void exportExistingTemporarySpecies(File file) throws IOException { - Function<Vessel, String> vesselToId = new Function<Vessel, String>() { - @Override - public String apply(Vessel input) { - return input.getName() + "#" + input.getInternationalRegistrationCode(); - } - }; + List<Species> targetList = Lists.newArrayList(persistenceService.getAllReferentSpecies()); - Set<String> existingIds = Sets.newHashSet( - Lists.transform(existingVessels, vesselToId)); + List<Species> toExport = persistenceService.retainTemporaryList(targetList); - List<Vessel> toImport = Lists.newArrayList(); + exportTemporarySpecies(file, toExport); - Reader reader = Files.newReader(file, Charsets.UTF_8); - VesselModel csvModel = new VesselModel(getCsvSeparator()); - try { - Import<Vessel> importer = Import.newImport(csvModel, reader); - - try { - - for (final Vessel bean : importer) { - - String currentId = vesselToId.apply(bean); - - if (!existingIds.add(currentId)) { - - // id was already in universe - throw new ApplicationTechnicalException( - t("tutti.service.referential.import.vessels.existingValue.error", - bean.getName(), - bean.getInternationalRegistrationCode())); - } - toImport.add(bean); - } - importer.close(); - } finally { - IOUtils.closeQuietly(importer); - } - reader.close(); - } catch (IOException e) { - throw new IOException(t("tutti.service.referential.import.vessels.error", file), e); - } finally { - - IOUtils.closeQuietly(reader); - } - List<Vessel> result = - persistenceService.importTemporaryVessel(toImport); - return result; - } - - public List<Person> importTemporaryPerson(File file) throws IOException { - if (log.isInfoEnabled()) { - log.info("Will import persons from file: " + file); - } - - List<Person> toImport = Lists.newArrayList(); - - Reader reader = Files.newReader(file, Charsets.UTF_8); - PersonModel csvModel = new PersonModel(getCsvSeparator()); - try { - Import<Person> importer = Import.newImport(csvModel, reader); - - try { - - for (Person bean : importer) { - toImport.add(bean); - } - importer.close(); - } finally { - IOUtils.closeQuietly(importer); - } - reader.close(); - } catch (IOException e) { - throw new IOException(t("tutti.service.referential.import.persons.error", file), e); - } finally { - - IOUtils.closeQuietly(reader); - } - List<Person> result = - persistenceService.importTemporaryPerson(toImport); - return result; - } - - public List<Gear> importTemporaryGear(File file) throws IOException { - if (log.isInfoEnabled()) { - log.info("Will import gears from file: " + file); - } - - // get all vessel names - Set<String> existingGearName = Sets.newHashSet(Iterables.transform(persistenceService.getAllFishingGear(), new Function<Gear, String>() { - @Override - public String apply(Gear input) { - return input.getName(); - } - })); - - existingGearName.addAll(Lists.transform(persistenceService.getAllScientificGear(), new Function<Gear, String>() { - @Override - public String apply(Gear input) { - return input.getName(); - } - })); - - List<Gear> toImport = Lists.newArrayList(); - - Reader reader = Files.newReader(file, Charsets.UTF_8); - GearModel csvModel = new GearModel(getCsvSeparator(), existingGearName); - try { - Import<Gear> importer = Import.newImport(csvModel, reader); - - try { - - for (Gear bean : importer) { - toImport.add(bean); - } - importer.close(); - } finally { - IOUtils.closeQuietly(importer); - } - reader.close(); - } catch (IOException e) { - throw new IOException(t("tutti.service.referential.import.gears.error", file), e); - - } catch (ImportRuntimeException e) { - String message; - if (e.getCause() != null) { - message = e.getCause().getMessage(); - } else { - message = e.getMessage(); - } - throw new ApplicationTechnicalException(message, e); - - } finally { - - IOUtils.closeQuietly(reader); - } - List<Gear> result = persistenceService.importTemporaryGear(toImport); - return result; } public void exportTemporarySpeciesExample(File file) throws IOException { @@ -296,6 +91,12 @@ public class ReferentialImportExportService extends AbstractTuttiService { s.setName("Temporary Species name 3"); toExport.add(s); + exportTemporarySpecies(file, toExport); + + } + + protected void exportTemporarySpecies(File file, List<Species> toExport) throws IOException { + SpeciesModel csvModel = new SpeciesModel(getCsvSeparator(), null); BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8); @@ -313,7 +114,19 @@ public class ReferentialImportExportService extends AbstractTuttiService { } + public void exportExistingTemporaryVessel(File file) throws IOException { + + List<Vessel> targetList = Lists.newArrayList(persistenceService.getAllFishingVessel()); + targetList.addAll(persistenceService.getAllScientificVessel()); + + List<Vessel> toExport = persistenceService.retainTemporaryList(targetList); + + exportTemporaryVessel(file, toExport); + + } + public void exportTemporaryVesselExample(File file) throws IOException { + List<Vessel> toExport = Lists.newArrayList(); Vessel v; @@ -342,6 +155,12 @@ public class ReferentialImportExportService extends AbstractTuttiService { v.setScientificVessel(true); toExport.add(v); + exportTemporaryVessel(file, toExport); + + } + + protected void exportTemporaryVessel(File file, List<Vessel> toExport) throws IOException { + VesselModel csvModel = new VesselModel(getCsvSeparator()); BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8); @@ -358,7 +177,18 @@ public class ReferentialImportExportService extends AbstractTuttiService { } } + public void exportExistingTemporaryPerson(File file) throws IOException { + + List<Person> targetList = Lists.newArrayList(persistenceService.getAllPerson()); + + List<Person> toExport = persistenceService.retainTemporaryList(targetList); + + exportTemporaryPerson(file, toExport); + + } + public void exportTemporaryPersonExample(File file) throws IOException { + List<Person> toExport = Lists.newArrayList(); Person p; @@ -378,6 +208,11 @@ public class ReferentialImportExportService extends AbstractTuttiService { p.setLastName("Last name 3"); toExport.add(p); + exportTemporaryPerson(file, toExport); + + } + + protected void exportTemporaryPerson(File file, List<Person> toExport) throws IOException { PersonModel csvModel = new PersonModel(getCsvSeparator()); @@ -395,6 +230,17 @@ public class ReferentialImportExportService extends AbstractTuttiService { } } + public void exportExistingTemporaryGear(File file) throws IOException { + + List<Gear> targetList = Lists.newArrayList(persistenceService.getAllFishingGear()); + targetList.addAll(persistenceService.getAllScientificGear()); + + List<Gear> toExport = persistenceService.retainTemporaryList(targetList); + + exportTemporaryGear(file, toExport); + + } + public void exportTemporaryGearExample(File file) throws IOException { List<Gear> toExport = Lists.newArrayList(); @@ -422,6 +268,12 @@ public class ReferentialImportExportService extends AbstractTuttiService { g.setScientificGear(true); toExport.add(g); + exportTemporaryGear(file, toExport); + + } + + protected void exportTemporaryGear(File file, List<Gear> toExport) throws IOException { + GearModel csvModel = new GearModel(getCsvSeparator(), null); BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportExportService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportService.java similarity index 87% rename from tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportExportService.java rename to tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportService.java index 4d8fede..46ff4cd 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportExportService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialImportService.java @@ -28,7 +28,6 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.common.io.Files; -import org.nuiton.jaxx.application.ApplicationTechnicalException; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Gears; import fr.ifremer.tutti.persistence.entities.referential.Person; @@ -46,6 +45,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.csv.Export; import org.nuiton.csv.Import; import org.nuiton.csv.ImportRuntimeException; +import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.BufferedWriter; import java.io.File; @@ -57,16 +57,16 @@ import java.util.Set; import static org.nuiton.i18n.I18n.t; /** - * Service to import or export referential. + * Service to import temporary referential. * * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public class ReferentialImportExportService extends AbstractTuttiService { +public class ReferentialImportService extends AbstractTuttiService { /** Logger. */ private static final Log log = - LogFactory.getLog(ReferentialImportExportService.class); + LogFactory.getLog(ReferentialImportService.class); protected PersistenceService persistenceService; @@ -278,6 +278,16 @@ public class ReferentialImportExportService extends AbstractTuttiService { return result; } + public void exportExistingTemporarySpecies(File file) throws IOException { + + List<Species> targetList = Lists.newArrayList(persistenceService.getAllReferentSpecies()); + + List<Species> toExport = persistenceService.retainTemporaryList(targetList); + + exportTemporarySpecies(file, toExport); + + } + public void exportTemporarySpeciesExample(File file) throws IOException { List<Species> toExport = Lists.newArrayList(); @@ -296,6 +306,12 @@ public class ReferentialImportExportService extends AbstractTuttiService { s.setName("Temporary Species name 3"); toExport.add(s); + exportTemporarySpecies(file, toExport); + + } + + protected void exportTemporarySpecies(File file, List<Species> toExport) throws IOException { + SpeciesModel csvModel = new SpeciesModel(getCsvSeparator(), null); BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8); @@ -313,7 +329,19 @@ public class ReferentialImportExportService extends AbstractTuttiService { } + public void exportExistingTemporaryVessel(File file) throws IOException { + + List<Vessel> targetList = Lists.newArrayList(persistenceService.getAllFishingVessel()); + targetList.addAll(persistenceService.getAllScientificVessel()); + + List<Vessel> toExport = persistenceService.retainTemporaryList(targetList); + + exportTemporaryVessel(file, toExport); + + } + public void exportTemporaryVesselExample(File file) throws IOException { + List<Vessel> toExport = Lists.newArrayList(); Vessel v; @@ -342,6 +370,12 @@ public class ReferentialImportExportService extends AbstractTuttiService { v.setScientificVessel(true); toExport.add(v); + exportTemporaryVessel(file, toExport); + + } + + protected void exportTemporaryVessel(File file, List<Vessel> toExport) throws IOException { + VesselModel csvModel = new VesselModel(getCsvSeparator()); BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8); @@ -358,7 +392,18 @@ public class ReferentialImportExportService extends AbstractTuttiService { } } + public void exportExistingTemporaryPerson(File file) throws IOException { + + List<Person> targetList = Lists.newArrayList(persistenceService.getAllPerson()); + + List<Person> toExport = persistenceService.retainTemporaryList(targetList); + + exportTemporaryPerson(file, toExport); + + } + public void exportTemporaryPersonExample(File file) throws IOException { + List<Person> toExport = Lists.newArrayList(); Person p; @@ -378,6 +423,11 @@ public class ReferentialImportExportService extends AbstractTuttiService { p.setLastName("Last name 3"); toExport.add(p); + exportTemporaryPerson(file, toExport); + + } + + protected void exportTemporaryPerson(File file, List<Person> toExport) throws IOException { PersonModel csvModel = new PersonModel(getCsvSeparator()); @@ -395,6 +445,17 @@ public class ReferentialImportExportService extends AbstractTuttiService { } } + public void exportExistingTemporaryGear(File file) throws IOException { + + List<Gear> targetList = Lists.newArrayList(persistenceService.getAllFishingGear()); + targetList.addAll(persistenceService.getAllScientificGear()); + + List<Gear> toExport = persistenceService.retainTemporaryList(targetList); + + exportTemporaryGear(file, toExport); + + } + public void exportTemporaryGearExample(File file) throws IOException { List<Gear> toExport = Lists.newArrayList(); @@ -422,6 +483,12 @@ public class ReferentialImportExportService extends AbstractTuttiService { g.setScientificGear(true); toExport.add(g); + exportTemporaryGear(file, toExport); + + } + + protected void exportTemporaryGear(File file, List<Gear> toExport) throws IOException { + GearModel csvModel = new GearModel(getCsvSeparator(), null); BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8); diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java index fede063..0915db0 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/PersistenceServiceTest.java @@ -91,7 +91,7 @@ public class PersistenceServiceTest { Gear source = service.getGear(-3); Gear target = service.getGear(377); - service.replaceGear(source, target); + service.replaceGear(source, target, ); } { @@ -110,7 +110,7 @@ public class PersistenceServiceTest { Gear source = service.getGear(-4); Gear target = service.getGear(378); - service.replaceGear(source, target); + service.replaceGear(source, target, ); } { @@ -152,7 +152,7 @@ public class PersistenceServiceTest { Person source = service.getPerson(-1); Person target = service.getPerson(1); - service.replacePerson(source, target); + service.replacePerson(source, target, ); } { service = dbResource.getServiceContext().getService(PersistenceService.class); @@ -169,7 +169,7 @@ public class PersistenceServiceTest { Person source = service.getPerson(-2); Person target = service.getPerson(2); - service.replacePerson(source, target); + service.replacePerson(source, target, ); } { Cruise cruise = service.getCruise("0"); @@ -184,7 +184,7 @@ public class PersistenceServiceTest { Person source = service.getPerson(-3); Person target = service.getPerson(3); - service.replacePerson(source, target); + service.replacePerson(source, target, ); } { Cruise cruise = service.getCruise("0"); @@ -225,7 +225,7 @@ public class PersistenceServiceTest { Species source = service.getSpeciesByReferenceTaxonId(-1); Species target = service.getSpeciesByReferenceTaxonId(1); - service.replaceSpecies(source, target); + service.replaceSpecies(source, target, ); } { @@ -246,7 +246,7 @@ public class PersistenceServiceTest { Species source = service.getSpeciesByReferenceTaxonId(-2); Species target = service.getSpeciesByReferenceTaxonId(2); - service.replaceSpecies(source, target); + service.replaceSpecies(source, target, ); } { @@ -266,7 +266,7 @@ public class PersistenceServiceTest { Species source = service.getSpeciesByReferenceTaxonId(-3); Species target = service.getSpeciesByReferenceTaxonId(3); - service.replaceSpecies(source, target); + service.replaceSpecies(source, target, ); } { @@ -307,7 +307,7 @@ public class PersistenceServiceTest { Vessel source = service.getVessel("#TEMP¿International registration code S3"); Vessel target = service.getVessel("267206"); - service.replaceVessel(source, target); + service.replaceVessel(source, target, ); } { Cruise cruise = service.getCruise("0"); @@ -322,7 +322,7 @@ public class PersistenceServiceTest { Vessel source = service.getVessel("#TEMP¿International registration code S4"); Vessel target = service.getVessel("278970"); - service.replaceVessel(source, target); + service.replaceVessel(source, target, ); } { Cruise cruise = service.getCruise("0"); diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialExportServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialExportServiceTest.java new file mode 100644 index 0000000..8c5f62e --- /dev/null +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialExportServiceTest.java @@ -0,0 +1,139 @@ +package fr.ifremer.tutti.service.referential; + +/* + * #%L + * Tutti :: Service + * %% + * Copyright (C) 2012 - 2014 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 com.google.common.base.Charsets; +import com.google.common.io.Files; +import fr.ifremer.tutti.service.ServiceDbResource; +import fr.ifremer.tutti.service.TuttiServiceContext; +import org.junit.Assert; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; + +import java.io.File; + +/** + * @author tchemit <chemit@codelutin.com> + * @since 1.0 + */ +public class ReferentialExportServiceTest { + + @ClassRule + public static final ServiceDbResource dbResource = + ServiceDbResource.writeDb("dbCGFS"); + + protected File dataDirectory; + + private static final String SPECIES_FILE_CONTENT = + "name\n" + + "Temporary Species name 1\n" + + "Temporary Species name 2\n" + + "Temporary Species name 3"; + + private static final String GEAR_FILE_CONTENT = + "name;label;scientificGear\n" + + "Gear fishing name 1;Gear fishing label 1;N\n" + + "Gear fishing name 2;Gear fishing label 2;N\n" + + "Gear scientific name 3;Gear scientific label 3;Y\n" + + "Gear scientific name 4;Gear scientific label 4;Y"; + + private static final String PERSON_FILE_CONTENT = + "firstName;lastName\n" + + "First name 1;Last name 1\n" + + "First name 2;Last name 2\n" + + "First name 3;Last name 3"; + + private static final String VESSEL_FILE_CONTENT = + "name;internationalRegistrationCode;scientificVessel\n" + + "Temporary fishing vessel name 1;International registration code F1;N\n" + + "Temporary fishing vessel name 2;International registration code F2;N\n" + + "Temporary scientific vessel name 3;International registration code S3;Y\n" + + "Temporary scientific vessel name 4;International registration code S4;Y"; + + protected ReferentialImportService service; + + @Before + public void setUp() throws Exception { + + dataDirectory = dbResource.getConfig().getDataDirectory(); + + TuttiServiceContext serviceContext = dbResource.getServiceContext(); + + serviceContext.getConfig().setCsvSeparator(';'); + + service = serviceContext.getService(ReferentialImportService.class); + } + + @Test + public void exportTemporarySpeciesExample() throws Exception { + + File file = new File(dataDirectory, "exportSpecies.csv"); + + Assert.assertFalse(file.exists()); + service.exportTemporarySpeciesExample(file); + Assert.assertTrue(file.exists()); + + String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); + Assert.assertEquals(SPECIES_FILE_CONTENT, exportFileToString); + } + + @Test + public void exportTemporaryVesselExample() throws Exception { + File file = new File(dataDirectory, "exportVessel.csv"); + + Assert.assertFalse(file.exists()); + service.exportTemporaryVesselExample(file); + Assert.assertTrue(file.exists()); + + String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); + Assert.assertEquals(VESSEL_FILE_CONTENT, exportFileToString); + } + + @Test + public void exportTemporaryPersonExample() throws Exception { + + File file = new File(dataDirectory, "exportPerson.csv"); + + Assert.assertFalse(file.exists()); + service.exportTemporaryPersonExample(file); + Assert.assertTrue(file.exists()); + + String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); + Assert.assertEquals(PERSON_FILE_CONTENT, exportFileToString); + } + + @Test + public void exportTemporaryGearExample() throws Exception { + + File file = new File(dataDirectory, "exportGear.csv"); + + Assert.assertFalse(file.exists()); + service.exportTemporaryGearExample(file); + Assert.assertTrue(file.exists()); + + String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); + Assert.assertEquals(GEAR_FILE_CONTENT, exportFileToString); + } + +} diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialImportExportServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialImportServiceTest.java similarity index 79% rename from tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialImportExportServiceTest.java rename to tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialImportServiceTest.java index 1902dc5..3a840b3 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialImportExportServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialImportServiceTest.java @@ -24,7 +24,6 @@ package fr.ifremer.tutti.service.referential; import com.google.common.base.Charsets; import com.google.common.io.Files; -import org.nuiton.jaxx.application.ApplicationTechnicalException; import fr.ifremer.tutti.persistence.entities.referential.Gear; import fr.ifremer.tutti.persistence.entities.referential.Person; import fr.ifremer.tutti.persistence.entities.referential.Species; @@ -35,6 +34,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; +import org.nuiton.jaxx.application.ApplicationTechnicalException; import java.io.File; import java.util.List; @@ -43,7 +43,7 @@ import java.util.List; * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public class ReferentialImportExportServiceTest { +public class ReferentialImportServiceTest { @ClassRule public static final ServiceDbResource dbResource = @@ -51,33 +51,33 @@ public class ReferentialImportExportServiceTest { protected File dataDirectory; - public static final String SPECIES_FILE_CONTENT = + private static final String SPECIES_FILE_CONTENT = "name\n" + "Temporary Species name 1\n" + "Temporary Species name 2\n" + "Temporary Species name 3"; - public static final String GEAR_FILE_CONTENT = + private static final String GEAR_FILE_CONTENT = "name;label;scientificGear\n" + "Gear fishing name 1;Gear fishing label 1;N\n" + "Gear fishing name 2;Gear fishing label 2;N\n" + "Gear scientific name 3;Gear scientific label 3;Y\n" + "Gear scientific name 4;Gear scientific label 4;Y"; - public static final String PERSON_FILE_CONTENT = + private static final String PERSON_FILE_CONTENT = "firstName;lastName\n" + "First name 1;Last name 1\n" + "First name 2;Last name 2\n" + "First name 3;Last name 3"; - public static final String VESSEL_FILE_CONTENT = + private static final String VESSEL_FILE_CONTENT = "name;internationalRegistrationCode;scientificVessel\n" + "Temporary fishing vessel name 1;International registration code F1;N\n" + "Temporary fishing vessel name 2;International registration code F2;N\n" + "Temporary scientific vessel name 3;International registration code S3;Y\n" + "Temporary scientific vessel name 4;International registration code S4;Y"; - public static final String DUPLICATE_VESSEL_FILE_CONTENT = + private static final String DUPLICATE_VESSEL_FILE_CONTENT = "name;internationalRegistrationCode;scientificVessel\n" + "Temporary fishing vessel name 1;International registration code F1;N\n" + "Temporary fishing vessel name 1;International registration code F1;N\n" + @@ -85,7 +85,7 @@ public class ReferentialImportExportServiceTest { "Temporary scientific vessel name 3;International registration code S3;Y\n" + "Temporary scientific vessel name 4;International registration code S4;Y"; - protected ReferentialImportExportService service; + protected ReferentialImportService service; @Before public void setUp() throws Exception { @@ -96,7 +96,7 @@ public class ReferentialImportExportServiceTest { serviceContext.getConfig().setCsvSeparator(';'); - service = serviceContext.getService(ReferentialImportExportService.class); + service = serviceContext.getService(ReferentialImportService.class); } @Test @@ -231,55 +231,4 @@ public class ReferentialImportExportServiceTest { } } - @Test - public void exportTemporarySpeciesExample() throws Exception { - - File file = new File(dataDirectory, "exportSpecies.csv"); - - Assert.assertFalse(file.exists()); - service.exportTemporarySpeciesExample(file); - Assert.assertTrue(file.exists()); - - String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); - Assert.assertEquals(SPECIES_FILE_CONTENT, exportFileToString); - } - - @Test - public void exportTemporaryVesselExample() throws Exception { - File file = new File(dataDirectory, "exportVessel.csv"); - - Assert.assertFalse(file.exists()); - service.exportTemporaryVesselExample(file); - Assert.assertTrue(file.exists()); - - String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); - Assert.assertEquals(VESSEL_FILE_CONTENT, exportFileToString); - } - - @Test - public void exportTemporaryPersonExample() throws Exception { - - File file = new File(dataDirectory, "exportPerson.csv"); - - Assert.assertFalse(file.exists()); - service.exportTemporaryPersonExample(file); - Assert.assertTrue(file.exists()); - - String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); - Assert.assertEquals(PERSON_FILE_CONTENT, exportFileToString); - } - - @Test - public void exportTemporaryGearExample() throws Exception { - - File file = new File(dataDirectory, "exportGear.csv"); - - Assert.assertFalse(file.exists()); - service.exportTemporaryGearExample(file); - Assert.assertTrue(file.exists()); - - String exportFileToString = Files.toString(file, Charsets.UTF_8).trim(); - Assert.assertEquals(GEAR_FILE_CONTENT, exportFileToString); - } - } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java index 5997762..b2309b7 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/TuttiUIContext.java @@ -45,7 +45,8 @@ import fr.ifremer.tutti.service.export.sumatra.CatchesSumatraExportService; import fr.ifremer.tutti.service.protocol.ProtocolImportExportService; import fr.ifremer.tutti.service.psionimport.PsionImportService; import fr.ifremer.tutti.service.pupitri.PupitriImportExportService; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; +import fr.ifremer.tutti.service.referential.ReferentialImportService; import fr.ifremer.tutti.service.referential.TuttiReferentialSynchronizeService; import fr.ifremer.tutti.service.report.ReportService; import fr.ifremer.tutti.ui.swing.content.MainUI; @@ -676,8 +677,12 @@ public class TuttiUIContext extends AbstractBean implements Closeable, UIMessage return serviceContext.getService(BigfinImportService.class); } - public ReferentialImportExportService getTuttiReferentialImportExportService() { - return serviceContext.getService(ReferentialImportExportService.class); + public ReferentialImportService getTuttiReferentialImportService() { + return serviceContext.getService(ReferentialImportService.class); + } + + public ReferentialExportService getTuttiReferentialExportService() { + return serviceContext.getService(ReferentialExportService.class); } public WeightComputingService getWeightComputingService() { diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/AbstractReplaceTemporaryUIAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/AbstractReplaceTemporaryUIAction.java index c4e6c2e..4fb3794 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/AbstractReplaceTemporaryUIAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/AbstractReplaceTemporaryUIAction.java @@ -53,7 +53,9 @@ public abstract class AbstractReplaceTemporaryUIAction<E extends TuttiReferentia protected E target; - protected abstract void replaceReferentialEntity(PersistenceService persistenceService, E source, E target); + protected Boolean delete; + + protected abstract void replaceReferentialEntity(PersistenceService persistenceService, E source, E target, boolean delete); protected abstract void resetCaches(); @@ -75,6 +77,7 @@ public abstract class AbstractReplaceTemporaryUIAction<E extends TuttiReferentia if (doAction) { source = model.getSelectedSource(); target = model.getSelectedTarget(); + delete = model.isDelete(); } } @@ -88,6 +91,7 @@ public abstract class AbstractReplaceTemporaryUIAction<E extends TuttiReferentia Preconditions.checkNotNull(source); Preconditions.checkNotNull(target); + Preconditions.checkNotNull(delete); String entityLabel = getEntityLabel(); @@ -96,7 +100,7 @@ public abstract class AbstractReplaceTemporaryUIAction<E extends TuttiReferentia entityLabel, source.getName(), target.getName())); } - replaceReferentialEntity(getContext().getPersistenceService(), source, target); + replaceReferentialEntity(getContext().getPersistenceService(), source, target, delete); // reset cache resetCaches(); @@ -106,6 +110,7 @@ public abstract class AbstractReplaceTemporaryUIAction<E extends TuttiReferentia @Override public void releaseAction() { source = target = null; + delete = null; super.releaseAction(); } @@ -113,7 +118,13 @@ public abstract class AbstractReplaceTemporaryUIAction<E extends TuttiReferentia @Override public void postSuccessAction() { super.postSuccessAction(); - sendMessage(t("tutti.replaceTemporary.done", getEntityLabel(), decorate(source), decorate(target))); + + if (delete) { + sendMessage(t("tutti.replaceTemporaryAndDelete.done", getEntityLabel(), decorate(source), decorate(target))); + } else { + sendMessage(t("tutti.replaceTemporary.done", getEntityLabel(), decorate(source), decorate(target))); + } + } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryGearExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryGearAction.java similarity index 78% copy from tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryGearExampleAction.java copy to tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryGearAction.java index 6a59e8f..3f03f94 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryGearExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryGearAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -40,15 +40,15 @@ import static org.nuiton.i18n.I18n.t; * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public class ExportTemporaryGearExampleAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { +public class ExportExistingTemporaryGearAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { /** Logger. */ private static final Log log = - LogFactory.getLog(ExportTemporaryGearExampleAction.class); + LogFactory.getLog(ExportExistingTemporaryGearAction.class); private File file; - public ExportTemporaryGearExampleAction(ManageTemporaryReferentialUIHandler handler) { + public ExportExistingTemporaryGearAction(ManageTemporaryReferentialUIHandler handler) { super(handler, true); } @@ -61,9 +61,9 @@ public class ExportTemporaryGearExampleAction extends AbstractTuttiAction<TuttiU // choose file to export file = saveFile( - "exportGearExample", + "exportTemporaryGear", "csv", - t("tutti.manageTemporaryReferential.title.choose.exportTemporaryGearExampleFile"), + t("tutti.manageTemporaryReferential.title.choose.exportExistingTemporaryGearFile"), t("tutti.manageTemporaryReferential.action.chooseReferentialGearFile.export"), "^.*\\.csv", t("tutti.common.file.csv") ); @@ -82,13 +82,12 @@ public class ExportTemporaryGearExampleAction extends AbstractTuttiAction<TuttiU public void doAction() throws Exception { Preconditions.checkNotNull(file); if (log.isInfoEnabled()) { - log.info("Will export example gears temporary " + + log.info("Will export existing gears temporary " + "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); - service.exportTemporaryGearExample(file); + ReferentialExportService service = getContext().getTuttiReferentialExportService(); + service.exportExistingTemporaryGear(file); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryPersonExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryPersonAction.java similarity index 77% copy from tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryPersonExampleAction.java copy to tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryPersonAction.java index 2d112e2..40ff64f 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryPersonExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryPersonAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -40,16 +40,16 @@ import static org.nuiton.i18n.I18n.t; * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public class ExportTemporaryPersonExampleAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { +public class ExportExistingTemporaryPersonAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { /** Logger. */ private static final Log log = - LogFactory.getLog(ExportTemporaryPersonExampleAction.class); + LogFactory.getLog(ExportExistingTemporaryPersonAction.class); private File file; - public ExportTemporaryPersonExampleAction(ManageTemporaryReferentialUIHandler handler) { + public ExportExistingTemporaryPersonAction(ManageTemporaryReferentialUIHandler handler) { super(handler, true); } @@ -62,9 +62,9 @@ public class ExportTemporaryPersonExampleAction extends AbstractTuttiAction<Tutt // choose file to export file = saveFile( - "exportPersonExample", + "exportTemporaryPerson", "csv", - t("tutti.manageTemporaryReferential.title.choose.exportTemporaryPersonExampleFile"), + t("tutti.manageTemporaryReferential.title.choose.exportExistingTemporaryPersonFile"), t("tutti.manageTemporaryReferential.action.chooseReferentialPersonFile.export"), "^.*\\.csv", t("tutti.common.file.csv") ); @@ -83,14 +83,13 @@ public class ExportTemporaryPersonExampleAction extends AbstractTuttiAction<Tutt public void doAction() throws Exception { Preconditions.checkNotNull(file); if (log.isInfoEnabled()) { - log.info("Will export example persons temporary " + + log.info("Will export existing persons temporary " + "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); + ReferentialExportService service = getContext().getTuttiReferentialExportService(); + service.exportExistingTemporaryPerson(file); - service.exportTemporaryPersonExample(file); } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporarySpeciesAction.java similarity index 77% copy from tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java copy to tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporarySpeciesAction.java index 83ac232..aed0f77 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporarySpeciesAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -40,15 +40,15 @@ import static org.nuiton.i18n.I18n.t; * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public class ExportTemporarySpeciesExampleAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { +public class ExportExistingTemporarySpeciesAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { /** Logger. */ private static final Log log = - LogFactory.getLog(ExportTemporarySpeciesExampleAction.class); + LogFactory.getLog(ExportExistingTemporarySpeciesAction.class); private File file; - public ExportTemporarySpeciesExampleAction(ManageTemporaryReferentialUIHandler handler) { + public ExportExistingTemporarySpeciesAction(ManageTemporaryReferentialUIHandler handler) { super(handler, true); } @@ -61,9 +61,9 @@ public class ExportTemporarySpeciesExampleAction extends AbstractTuttiAction<Tut // choose file to export file = saveFile( - "exportSpeciesExample", + "exportTemporarySpecies", "csv", - t("tutti.manageTemporaryReferential.title.choose.exportTemporarySpeciesExampleFile"), + t("tutti.manageTemporaryReferential.title.choose.exportExistingTemporarySpeciesFile"), t("tutti.manageTemporaryReferential.action.chooseReferentialSpeciesFile.export"), "^.*\\.csv", t("tutti.common.file.csv") ); @@ -82,14 +82,13 @@ public class ExportTemporarySpeciesExampleAction extends AbstractTuttiAction<Tut public void doAction() throws Exception { Preconditions.checkNotNull(file); if (log.isInfoEnabled()) { - log.info("Will export example species temporary " + + log.info("Will export existing species temporary " + "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); + ReferentialExportService service = getContext().getTuttiReferentialExportService(); + service.exportExistingTemporarySpecies(file); - service.exportTemporarySpeciesExample(file); } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryVesselAction.java similarity index 79% copy from tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java copy to tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryVesselAction.java index 83ac232..267d803 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportExistingTemporaryVesselAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -40,15 +40,15 @@ import static org.nuiton.i18n.I18n.t; * @author tchemit <chemit@codelutin.com> * @since 1.0 */ -public class ExportTemporarySpeciesExampleAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { +public class ExportExistingTemporaryVesselAction extends AbstractTuttiAction<TuttiUIContext, ManageTemporaryReferentialUI, ManageTemporaryReferentialUIHandler> { /** Logger. */ private static final Log log = - LogFactory.getLog(ExportTemporarySpeciesExampleAction.class); + LogFactory.getLog(ExportExistingTemporaryVesselAction.class); private File file; - public ExportTemporarySpeciesExampleAction(ManageTemporaryReferentialUIHandler handler) { + public ExportExistingTemporaryVesselAction(ManageTemporaryReferentialUIHandler handler) { super(handler, true); } @@ -61,10 +61,10 @@ public class ExportTemporarySpeciesExampleAction extends AbstractTuttiAction<Tut // choose file to export file = saveFile( - "exportSpeciesExample", + "exportTemporaryExample", "csv", - t("tutti.manageTemporaryReferential.title.choose.exportTemporarySpeciesExampleFile"), - t("tutti.manageTemporaryReferential.action.chooseReferentialSpeciesFile.export"), + t("tutti.manageTemporaryReferential.title.choose.exportExistingTemporaryVesselFile"), + t("tutti.manageTemporaryReferential.action.chooseReferentialVesselFile.export"), "^.*\\.csv", t("tutti.common.file.csv") ); doAction = file != null; @@ -82,19 +82,18 @@ public class ExportTemporarySpeciesExampleAction extends AbstractTuttiAction<Tut public void doAction() throws Exception { Preconditions.checkNotNull(file); if (log.isInfoEnabled()) { - log.info("Will export example species temporary " + + log.info("Will export existing vessels temporary " + "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); + ReferentialExportService service = getContext().getTuttiReferentialExportService(); + service.exportExistingTemporaryVessel(file); - service.exportTemporarySpeciesExample(file); } @Override public void postSuccessAction() { super.postSuccessAction(); - sendMessage(t("tutti.manageTemporaryReferential.action.chooseReferentialSpeciesFile.export.success", file)); + sendMessage(t("tutti.manageTemporaryReferential.action.chooseReferentialVesselFile.export.success", file)); } } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryGearExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryGearExampleAction.java index 6a59e8f..f407390 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryGearExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryGearExampleAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -86,8 +86,7 @@ public class ExportTemporaryGearExampleAction extends AbstractTuttiAction<TuttiU "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); + ReferentialExportService service = getContext().getTuttiReferentialExportService(); service.exportTemporaryGearExample(file); } diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryPersonExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryPersonExampleAction.java index 2d112e2..68bc2b1 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryPersonExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryPersonExampleAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -87,10 +87,9 @@ public class ExportTemporaryPersonExampleAction extends AbstractTuttiAction<Tutt "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); - + ReferentialExportService service = getContext().getTuttiReferentialExportService(); service.exportTemporaryPersonExample(file); + } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java index 83ac232..5760244 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporarySpeciesExampleAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -86,10 +86,9 @@ public class ExportTemporarySpeciesExampleAction extends AbstractTuttiAction<Tut "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); - + ReferentialExportService service = getContext().getTuttiReferentialExportService(); service.exportTemporarySpeciesExample(file); + } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryVesselExampleAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryVesselExampleAction.java index 92b7fbb..24389de 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryVesselExampleAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ExportTemporaryVesselExampleAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialExportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -86,10 +86,9 @@ public class ExportTemporaryVesselExampleAction extends AbstractTuttiAction<Tutt "referential to file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); - + ReferentialExportService service = getContext().getTuttiReferentialExportService(); service.exportTemporaryVesselExample(file); + } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryGearAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryGearAction.java index b9f1f7c..775c0ca 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryGearAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryGearAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialImportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -84,9 +84,7 @@ public class ImportTemporaryGearAction extends AbstractTuttiAction<TuttiUIContex "referential from file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); - + ReferentialImportService service = getContext().getTuttiReferentialImportService(); service.importTemporaryGear(file); // reset ui cache diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryPersonAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryPersonAction.java index fdcbb00..3ed7033 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryPersonAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryPersonAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialImportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -84,8 +84,8 @@ public class ImportTemporaryPersonAction extends AbstractTuttiAction<TuttiUICont "referential from file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); + ReferentialImportService service = + getContext().getTuttiReferentialImportService(); service.importTemporaryPerson(file); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporarySpeciesAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporarySpeciesAction.java index 926d450..a3d9107 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporarySpeciesAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporarySpeciesAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialImportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -83,8 +83,8 @@ public class ImportTemporarySpeciesAction extends AbstractTuttiAction<TuttiUICon "referential from file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); + ReferentialImportService service = + getContext().getTuttiReferentialImportService(); service.importTemporarySpecies(file); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryVesselAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryVesselAction.java index b1348d7..1c9aac0 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryVesselAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ImportTemporaryVesselAction.java @@ -23,7 +23,7 @@ package fr.ifremer.tutti.ui.swing.action; */ import com.google.common.base.Preconditions; -import fr.ifremer.tutti.service.referential.ReferentialImportExportService; +import fr.ifremer.tutti.service.referential.ReferentialImportService; import fr.ifremer.tutti.ui.swing.TuttiUIContext; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUI; import fr.ifremer.tutti.ui.swing.content.referential.ManageTemporaryReferentialUIHandler; @@ -83,8 +83,8 @@ public class ImportTemporaryVesselAction extends AbstractTuttiAction<TuttiUICont "referential from file: " + file); } - ReferentialImportExportService service = - getContext().getTuttiReferentialImportExportService(); + ReferentialImportService service = + getContext().getTuttiReferentialImportService(); service.importTemporaryVessel(file); diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryGearAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryGearAction.java index bc8d48b..bbb9d16 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryGearAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryGearAction.java @@ -50,9 +50,9 @@ public class ReplaceTemporaryGearAction extends AbstractReplaceTemporaryUIAction } @Override - protected void replaceReferentialEntity(PersistenceService persistenceService, Gear source, Gear target) { + protected void replaceReferentialEntity(PersistenceService persistenceService, Gear source, Gear target, boolean delete) { - persistenceService.replaceGear(source, target); + persistenceService.replaceGear(source, target, delete); } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryPersonAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryPersonAction.java index cb06143..5874645 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryPersonAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryPersonAction.java @@ -50,9 +50,9 @@ public class ReplaceTemporaryPersonAction extends AbstractReplaceTemporaryUIActi } @Override - protected void replaceReferentialEntity(PersistenceService persistenceService, Person source, Person target) { + protected void replaceReferentialEntity(PersistenceService persistenceService, Person source, Person target, boolean delete) { - persistenceService.replacePerson(source, target); + persistenceService.replacePerson(source, target, delete); } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporarySpeciesAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporarySpeciesAction.java index 6130830..ef1bba3 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporarySpeciesAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporarySpeciesAction.java @@ -50,9 +50,9 @@ public class ReplaceTemporarySpeciesAction extends AbstractReplaceTemporaryUIAct } @Override - protected void replaceReferentialEntity(PersistenceService persistenceService, Species source, Species target) { + protected void replaceReferentialEntity(PersistenceService persistenceService, Species source, Species target, boolean delete) { - persistenceService.replaceSpecies(source, target); + persistenceService.replaceSpecies(source, target, delete); } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryVesselAction.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryVesselAction.java index 10ad939..98bad85 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryVesselAction.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/action/ReplaceTemporaryVesselAction.java @@ -50,9 +50,9 @@ public class ReplaceTemporaryVesselAction extends AbstractReplaceTemporaryUIActi } @Override - protected void replaceReferentialEntity(PersistenceService persistenceService, Vessel source, Vessel target) { + protected void replaceReferentialEntity(PersistenceService persistenceService, Vessel source, Vessel target, boolean delete) { - persistenceService.replaceVessel(source, target); + persistenceService.replaceVessel(source, target, delete); } @Override diff --git a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/replace/AbstractReplaceTemporaryUIModel.java b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/replace/AbstractReplaceTemporaryUIModel.java index 0eaac62..b4e2fef 100644 --- a/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/replace/AbstractReplaceTemporaryUIModel.java +++ b/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/referential/replace/AbstractReplaceTemporaryUIModel.java @@ -47,6 +47,8 @@ public class AbstractReplaceTemporaryUIModel<E extends TuttiReferentialEntity> e public static final String PROPERTY_SELECTED_TARGET = "selectedTarget"; + public static final String PROPERTY_DELETE = "delete"; + protected List<E> sourceList; protected List<E> targetList; @@ -55,6 +57,8 @@ public class AbstractReplaceTemporaryUIModel<E extends TuttiReferentialEntity> e protected E selectedTarget; + protected boolean delete = true; + public AbstractReplaceTemporaryUIModel() { super(null, null); } @@ -97,6 +101,15 @@ public class AbstractReplaceTemporaryUIModel<E extends TuttiReferentialEntity> e firePropertyChange(PROPERTY_SELECTED_SOURCE, oldvalue, selectedSource); } + public boolean isDelete() { + return delete; + } + + public void setDelete(boolean delete) { + this.delete = delete; + firePropertyChange(PROPERTY_DELETE, null/*force boolean propagation*/, delete); + } + @Override protected E newEntity() { return null; diff --git a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties index dfaf1e0..fb8f70d 100644 --- a/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties +++ b/tutti-ui-swing/src/main/resources/i18n/tutti-ui-swing_fr_FR.properties @@ -1461,6 +1461,7 @@ tutti.reimport.step.reloadApplication=Redémarrage de l'application... tutti.reinstallDb.step.backupDb=Sauvegarde de la base dans l'archive %s tutti.reinstallDb.step.closeDb=Fermeture de la base <strong>%s</strong> tutti.reinstallDb.step.reloadApplication=Redémarrage de l'application... +tutti.replaceTemporaryAndDelete.done=<html><body>Le référentiel temporaire de type %s <strong>%s</strong> a été remplacée par <strong>%s</strong> puis supprimé. tutti.replaceTemporary.done=<html><body>Le référentiel temporaire de type %s <strong>%s</strong> a été remplacée par <strong>%s</strong> tutti.replaceTemporaryGear.title=Remplacer un engin temporaire tutti.replaceTemporaryPerson.title=Remplacer un utilisateur temporaire -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.