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 b9d1960116151a0b796024d4ee1ca376f2108086 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Nov 17 18:33:17 2014 +0100 fixes #6096 --- .../tutti/persistence/TuttiPersistenceImpl.java | 62 +++++++++++------- .../persistence/TuttiPersistenceNoDbImpl.java | 16 ++--- .../entities/protocol/TuttiProtocols.java | 8 +++ .../referential/GearPersistenceService.java | 10 ++- .../referential/GearPersistenceServiceImpl.java | 8 +-- .../referential/PersonPersistenceService.java | 6 +- .../referential/PersonPersistenceServiceImpl.java | 8 +-- .../referential/SpeciesPersistenceService.java | 6 +- .../referential/SpeciesPersistenceServiceImpl.java | 12 ++-- .../referential/VesselPersistenceService.java | 10 ++- .../referential/VesselPersistenceServiceImpl.java | 8 +-- .../ifremer/tutti/service/PersistenceService.java | 32 +++++----- .../ReferentialTemporaryGearService.java | 68 +++++++++++++------- .../ReferentialTemporaryPersonService.java | 74 +++++++++++++--------- .../ReferentialTemporarySpeciesService.java | 66 +++++++++++-------- .../ReferentialTemporaryVesselService.java | 69 +++++++++++++------- .../resources/i18n/tutti-service_en_GB.properties | 7 ++ .../resources/i18n/tutti-service_fr_FR.properties | 6 +- .../ReferentialTemporaryPersonServiceTest.java | 4 +- 19 files changed, 286 insertions(+), 194 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 d4920e8..a9fbad4 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 @@ -471,13 +471,13 @@ public class TuttiPersistenceImpl implements TuttiPersistence { } @Override - public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { - gearService.deleteTemporaryGear(id, checkIfUsed); + public void deleteTemporaryGear(Integer id) { + gearService.deleteTemporaryGear(id); } @Override - public void deleteTemporaryGears(Collection<Integer> id, boolean checkIfUsed) { - gearService.deleteTemporaryGears(id, checkIfUsed); + public void deleteTemporaryGears(Collection<Integer> id) { + gearService.deleteTemporaryGears(id); } //------------------------------------------------------------------------// @@ -517,16 +517,10 @@ public class TuttiPersistenceImpl implements TuttiPersistence { // check first if species is used in protocol - SpeciesProtocol speciesProtocol = TuttiProtocols.getSpeciesProtocol(protocol, referenceTaxonId); + SpeciesProtocol speciesProtocol = TuttiProtocols.getSpeciesOrBenthosProtocol(protocol, referenceTaxonId); if (speciesProtocol != null) { - // used in species protocol - return true; - } - SpeciesProtocol benthosProtocol = TuttiProtocols.getBenthosProtocol(protocol, referenceTaxonId); - if (benthosProtocol != null) { - - // use in benthos protocol + // used in species or benthos protocol return true; } @@ -541,17 +535,37 @@ public class TuttiPersistenceImpl implements TuttiPersistence { @Override public void replaceSpecies(Species source, Species target, boolean delete) { + speciesService.replaceSpecies(source, target, delete); + + TuttiProtocol protocol = getProtocol(); + + if (protocol != null) { + + SpeciesProtocol speciesProtocol = TuttiProtocols.getSpeciesOrBenthosProtocol(protocol, source.getReferenceTaxonId()); + + if (speciesProtocol != null) { + + if (log.isInfoEnabled()) { + log.info("Change referenceTaxonId " + source.getReferenceTaxonId() + " to " + target.getReferenceTaxonId() + " in protocol."); + } + speciesProtocol.setSpeciesReferenceTaxonId(target.getReferenceTaxonId()); + + saveProtocol(protocol); + + } + } + } @Override - public void deleteTemporarySpecies(Integer referenceTaxonId, boolean checkIfUsed) { - speciesService.deleteTemporarySpecies(referenceTaxonId, checkIfUsed); + public void deleteTemporarySpecies(Integer referenceTaxonId) { + speciesService.deleteTemporarySpecies(referenceTaxonId); } @Override - public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds, boolean checkIfUsed) { - speciesService.deleteTemporarySpecies(referenceTaxonIds, checkIfUsed); + public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds) { + speciesService.deleteTemporarySpecies(referenceTaxonIds); } //------------------------------------------------------------------------// @@ -584,13 +598,13 @@ public class TuttiPersistenceImpl implements TuttiPersistence { } @Override - public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { - personService.deleteTemporaryPerson(id, checkIfUsed); + public void deleteTemporaryPerson(Integer id) { + personService.deleteTemporaryPerson(id); } @Override - public void deleteTemporaryPersons(Collection<Integer> ids, boolean checkIfUsed) { - personService.deleteTemporaryPersons(ids, checkIfUsed); + public void deleteTemporaryPersons(Collection<Integer> ids) { + personService.deleteTemporaryPersons(ids); } //------------------------------------------------------------------------// @@ -628,13 +642,13 @@ public class TuttiPersistenceImpl implements TuttiPersistence { } @Override - public void deleteTemporaryVessel(String code, boolean checkIfUsed) { - vesselService.deleteTemporaryVessel(code, checkIfUsed); + public void deleteTemporaryVessel(String code) { + vesselService.deleteTemporaryVessel(code); } @Override - public void deleteTemporaryVessels(Collection<String> codes, boolean checkIfUsed) { - vesselService.deleteTemporaryVessels(codes, checkIfUsed); + public void deleteTemporaryVessels(Collection<String> codes) { + vesselService.deleteTemporaryVessels(codes); } //------------------------------------------------------------------------// 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 b935f6a..1ee8f35 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 @@ -756,42 +756,42 @@ public class TuttiPersistenceNoDbImpl implements TuttiPersistence { } @Override - public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { + public void deleteTemporaryGear(Integer id) { throw notImplemented(); } @Override - public void deleteTemporaryGears(Collection<Integer> id, boolean checkIfUsed) { + public void deleteTemporaryGears(Collection<Integer> id) { throw notImplemented(); } @Override - public void deleteTemporarySpecies(Integer referenceTaxonId, boolean checkIfUsed) { + public void deleteTemporarySpecies(Integer referenceTaxonId) { throw notImplemented(); } @Override - public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds, boolean checkIfUsed) { + public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds) { throw notImplemented(); } @Override - public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { + public void deleteTemporaryPerson(Integer id) { throw notImplemented(); } @Override - public void deleteTemporaryPersons(Collection<Integer> ids, boolean checkIfUsed) { + public void deleteTemporaryPersons(Collection<Integer> ids) { throw notImplemented(); } @Override - public void deleteTemporaryVessel(String code, boolean checkIfUsed) { + public void deleteTemporaryVessel(String code) { throw notImplemented(); } @Override - public void deleteTemporaryVessels(Collection<String> codes, boolean checkIfUsed) { + public void deleteTemporaryVessels(Collection<String> codes) { throw notImplemented(); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java index 17fd573..2503372 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/entities/protocol/TuttiProtocols.java @@ -316,6 +316,14 @@ public class TuttiProtocols extends AbstractTuttiProtocols { return result; } + public static SpeciesProtocol getSpeciesOrBenthosProtocol(TuttiProtocol protocol, Integer speciesReferenceTaxonId) { + SpeciesProtocol speciesProtocol = getSpeciesProtocol(protocol, speciesReferenceTaxonId); + if (speciesProtocol == null) { + speciesProtocol = getBenthosProtocol(protocol, speciesReferenceTaxonId); + } + return speciesProtocol; + } + /** * Return the species Protocol corresponding to the species of the given protocol. * diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceService.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceService.java index 79d9b8d..d0499fd 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceService.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceService.java @@ -81,22 +81,20 @@ public interface GearPersistenceService extends TuttiPersistenceServiceImplement /** * 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 + * @param id id of the gear to remove * @since 3.8 */ @Transactional(readOnly = false) @CacheEvict(value = "gears", allEntries = true) - void deleteTemporaryGear(Integer id, boolean checkIfUsed); + void deleteTemporaryGear(Integer id); /** * Delete the temporary gears with the given {@code idss}. * - * @param ids ids of the gears to remove - * @param checkIfUsed to check if gear is used before trying to delete it + * @param ids ids of the gears to remove * @since 3.8 */ @Transactional(readOnly = false) @CacheEvict(value = "gears", allEntries = true) - void deleteTemporaryGears(Collection<Integer> ids, boolean checkIfUsed); + void deleteTemporaryGears(Collection<Integer> ids); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceServiceImpl.java index 3e719e1..04e6673 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/GearPersistenceServiceImpl.java @@ -148,23 +148,23 @@ public class GearPersistenceServiceImpl extends ReferentialPersistenceServiceSup if (delete) { - deleteTemporaryGear(sourceId, false); + deleteTemporaryGear(sourceId); } } @Override - public void deleteTemporaryGears(Collection<Integer> ids, boolean checkIfUsed) { + public void deleteTemporaryGears(Collection<Integer> ids) { for (Integer id : ids) { - deleteTemporaryGear(id, checkIfUsed); + deleteTemporaryGear(id); } } @Override - public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { + public void deleteTemporaryGear(Integer id) { Preconditions.checkNotNull(id); if (id > 0) { diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceService.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceService.java index cdc75f2..e25c6aa 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceService.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceService.java @@ -84,21 +84,19 @@ public interface PersonPersistenceService extends TuttiPersistenceServiceImpleme * Delete the temporary persons with the given {@code ids}. * * @param ids ids of the persons to remove - * @param checkIfUsed to check if person is used before trying to delete it * @since 3.8 */ @Transactional(readOnly = false) @CacheEvict(value = {"persons", "personById"}, allEntries = true) - void deleteTemporaryPersons(Collection<Integer> ids, boolean checkIfUsed); + void deleteTemporaryPersons(Collection<Integer> ids); /** * 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.8 */ @Transactional(readOnly = false) @CacheEvict(value = {"persons", "personById"}, allEntries = true) - void deleteTemporaryPerson(Integer id, boolean checkIfUsed); + void deleteTemporaryPerson(Integer id); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceServiceImpl.java index fce34fc..44e6798 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/PersonPersistenceServiceImpl.java @@ -160,23 +160,23 @@ public class PersonPersistenceServiceImpl extends ReferentialPersistenceServiceS if (delete) { - deleteTemporaryPerson(sourceId, false); + deleteTemporaryPerson(sourceId); } } @Override - public void deleteTemporaryPersons(Collection<Integer> ids, boolean checkIfUsed) { + public void deleteTemporaryPersons(Collection<Integer> ids) { for (Integer id : ids) { - deleteTemporaryPerson(id, checkIfUsed); + deleteTemporaryPerson(id); } } @Override - public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { + public void deleteTemporaryPerson(Integer id) { Preconditions.checkNotNull(id); if (id > 0) { diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceService.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceService.java index 173c5f4..8b79ff0 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceService.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceService.java @@ -120,22 +120,20 @@ public interface SpeciesPersistenceService extends TuttiPersistenceServiceImplem * Delete the temporary species with the given {@code referenceTaxonId}. * * @param referenceTaxonIds referenceTaxonId of the species to remove - * @param checkIfUsed to check if species is used before trying to delete it * @since 3.8 */ @Transactional(readOnly = false) @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular"}, allEntries = true) - void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds, boolean checkIfUsed); + void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds); /** * Delete the temporary species with the given {@code referenceTaxonId}. * * @param referenceTaxonId reference taxonId of the species to remove - * @param checkIfUsed to check if species is used before trying to delete it * @since 3.8 */ @Transactional(readOnly = false) @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular"}, allEntries = true) - void deleteTemporarySpecies(Integer referenceTaxonId, boolean checkIfUsed); + void deleteTemporarySpecies(Integer referenceTaxonId); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceServiceImpl.java index a2b294e..e2d5e80 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/SpeciesPersistenceServiceImpl.java @@ -202,23 +202,23 @@ public class SpeciesPersistenceServiceImpl extends ReferentialPersistenceService if (delete) { - deleteTemporarySpecies(sourceId, false); + deleteTemporarySpecies(sourceId); } } @Override - public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds, boolean checkIfUsed) { + public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds) { for (Integer id : referenceTaxonIds) { - deleteTemporarySpecies(id, checkIfUsed); + deleteTemporarySpecies(id); } } @Override - public void deleteTemporarySpecies(Integer referenceTaxonId, boolean checkIfUsed) { + public void deleteTemporarySpecies(Integer referenceTaxonId) { Preconditions.checkNotNull(referenceTaxonId); if (referenceTaxonId > 0) { @@ -229,10 +229,6 @@ public class SpeciesPersistenceServiceImpl extends ReferentialPersistenceService throw new ApplicationBusinessException(String.format("Species with id %d does not exists", referenceTaxonId)); } - if (checkIfUsed) { - isTemporarySpeciesUsed(referenceTaxonId); - } - taxonNameDao.remove(species.getIdAsInt()); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceService.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceService.java index adb6e13..370fa8f 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceService.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceService.java @@ -103,23 +103,21 @@ public interface VesselPersistenceService extends TuttiPersistenceServiceImpleme /** * Delete the temporary vessels with the given {@code codes}. * - * @param codes code of the vessels to remove - * @param checkIfUsed to check if vessel is used before trying to delete it + * @param codes code of the vessels to remove * @since 3.8 */ @Transactional(readOnly = false) @CacheEvict(value = {"fishingVessels", "vesselByCode"}, allEntries = true) - void deleteTemporaryVessels(Collection<String> codes, boolean checkIfUsed); + void deleteTemporaryVessels(Collection<String> codes); /** * 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 + * @param code code of the vessel to remove * @since 3.8 */ @Transactional(readOnly = false) @CacheEvict(value = {"fishingVessels", "vesselByCode"}, allEntries = true) - void deleteTemporaryVessel(String code, boolean checkIfUsed); + void deleteTemporaryVessel(String code); } diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceServiceImpl.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceServiceImpl.java index df29132..82673d7 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceServiceImpl.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/VesselPersistenceServiceImpl.java @@ -263,23 +263,23 @@ public class VesselPersistenceServiceImpl extends ReferentialPersistenceServiceS if (delete) { - deleteTemporaryVessel(sourceId, false); + deleteTemporaryVessel(sourceId); } } @Override - public void deleteTemporaryVessels(Collection<String> codes, boolean checkIfUsed) { + public void deleteTemporaryVessels(Collection<String> codes) { for (String code : codes) { - deleteTemporaryVessel(code, checkIfUsed); + deleteTemporaryVessel(code); } } @Override - public void deleteTemporaryVessel(String code, boolean checkIfUsed) { + public void deleteTemporaryVessel(String code) { Preconditions.checkNotNull(code); if (!code.startsWith(TemporaryDataHelper.TEMPORARY_NAME_PREFIX)) { 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 e28ce9a..6b8c046 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 @@ -1020,43 +1020,43 @@ public class PersistenceService extends AbstractTuttiService implements TuttiPer } @Override - public void deleteTemporaryGear(Integer id, boolean checkIfUsed) { - driver.deleteTemporaryGear(id, checkIfUsed); + public void deleteTemporaryGear(Integer id) { + driver.deleteTemporaryGear(id); } @Override - public void deleteTemporaryGears(Collection<Integer> id, boolean checkIfUsed) { - driver.deleteTemporaryGears(id, checkIfUsed); + public void deleteTemporaryGears(Collection<Integer> id) { + driver.deleteTemporaryGears(id); } @Override - public void deleteTemporarySpecies(Integer referenceTaxonId, boolean checkIfUsed) { - driver.deleteTemporarySpecies(referenceTaxonId, checkIfUsed); + public void deleteTemporarySpecies(Integer referenceTaxonId) { + driver.deleteTemporarySpecies(referenceTaxonId); } @Override - public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds, boolean checkIfUsed) { - driver.deleteTemporarySpecies(referenceTaxonIds, checkIfUsed); + public void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds) { + driver.deleteTemporarySpecies(referenceTaxonIds); } @Override - public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { - driver.deleteTemporaryPerson(id, checkIfUsed); + public void deleteTemporaryPerson(Integer id) { + driver.deleteTemporaryPerson(id); } @Override - public void deleteTemporaryPersons(Collection<Integer> ids, boolean checkIfUsed) { - driver.deleteTemporaryPersons(ids, checkIfUsed); + public void deleteTemporaryPersons(Collection<Integer> ids) { + driver.deleteTemporaryPersons(ids); } @Override - public void deleteTemporaryVessel(String code, boolean checkIfUsed) { - driver.deleteTemporaryVessel(code, checkIfUsed); + public void deleteTemporaryVessel(String code) { + driver.deleteTemporaryVessel(code); } @Override - public void deleteTemporaryVessels(Collection<String> codes, boolean checkIfUsed) { - driver.deleteTemporaryVessels(codes, checkIfUsed); + public void deleteTemporaryVessels(Collection<String> codes) { + driver.deleteTemporaryVessels(codes); } @Override diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryGearService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryGearService.java index 871b668..1909181 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryGearService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryGearService.java @@ -67,7 +67,7 @@ public class ReferentialTemporaryGearService extends AbstractTuttiService { if (requestResult.withToDelete()) { Collection<Integer> idsToDelete = requestResult.getIdsToDelete(); - persistenceService.deleteTemporaryGears(idsToDelete, true); + persistenceService.deleteTemporaryGears(idsToDelete); result.setNbRefDeleted(idsToDelete.size()); } @@ -182,43 +182,65 @@ public class ReferentialTemporaryGearService extends AbstractTuttiService { private void importGear(GearRow bean, ImportRequestResult<Gear, Integer> requestResult) { Integer id = bean.getIdAsInt(); - Gear gear = requestResult.getExistingEntityById(id); String name = bean.getName(); boolean delete = BooleanUtils.isTrue(bean.getToDelete()); - if (id != null && requestResult.addExistingEntityId(id)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.gear.notExistingId.error", id)); - } - if (StringUtils.isBlank(name)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.gear.noName.error", id)); - } - if (!delete && !requestResult.addExistingNaturalId(name) && - (id == null || gear != null && !gear.getName().equals(name))) { - throw new IllegalArgumentException(t("tutti.service.referential.import.gear.existingName.error", name)); - } + if (id == null) { - if (delete) { - if (id == null) { + // Ajout + + if (delete) { throw new IllegalArgumentException(t("tutti.service.referential.import.gear.cannotDeleteWithoutId.error")); } - if (gear==null) { - // can't delete if gear does not exists - throw new IllegalArgumentException(t("tutti.service.referential.import.gear.cannotDeleteNotExisting.error")); + + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.gear.add.noName.error")); } - if (persistenceService.isTemporaryGearUsed(id)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.gear.used.error", id)); + + if (!requestResult.addExistingNaturalId(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.gear.existingName.error", name)); } - requestResult.addIdToDelete(id); - requestResult.removeExistingNaturalId(name); + + requestResult.addEntityToAdd(bean.toEntity()); } else { - if (bean.getId() == null) { - requestResult.addEntityToAdd(bean.toEntity()); + + // Mise à jour ou Suppression + + Gear gear = requestResult.getExistingEntityById(id); + + if (gear == null) { + throw new IllegalArgumentException(t("tutti.service.referential.import.gear.notExistingId.error", id)); + } + + if (delete) { + + // Suppression + + if (persistenceService.isTemporaryGearUsed(id)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.species.used.error", id)); + } + + requestResult.addIdToDelete(id); + requestResult.removeExistingNaturalId(name); } else { + + // Mise à jour + + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.gear.noName.error", id)); + } + + if (!name.equals(gear.getName()) && !requestResult.addExistingNaturalId(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.gear.existingName.error", name)); + } + requestResult.addEntityToUpdate(bean.toEntity()); + } } + } protected void exportTemporaryGear(File file, List<Gear> toExport) throws IOException { diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonService.java index 1dd9b83..003dc34 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonService.java @@ -65,7 +65,7 @@ public class ReferentialTemporaryPersonService extends AbstractTuttiService { Collection<Integer> idsToDelete = requestResult.getIdsToDelete(); - persistenceService.deleteTemporaryPersons(idsToDelete, true); + persistenceService.deleteTemporaryPersons(idsToDelete); result.setNbRefDeleted(idsToDelete.size()); } @@ -169,53 +169,67 @@ public class ReferentialTemporaryPersonService extends AbstractTuttiService { private void importPerson(PersonRow bean, ImportRequestResult<Person, Integer> requestResult) { Integer id = bean.getIdAsInt(); - Person person = requestResult.getExistingEntityById(id); String name = Persons.GET_FULL_NAME.apply(bean.toEntity()); - boolean delete = BooleanUtils.isTrue(bean.getToDelete()); - if (id != null && requestResult.addExistingEntityId(id)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.person.notExistingId.error", id)); - } - if (StringUtils.isBlank(name)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.person.noName.error", id)); - } - if (!delete && !requestResult.addExistingNaturalId(name) && - (id == null || person != null && !person.getName().equals(name))) { - throw new IllegalArgumentException(t("tutti.service.referential.import.person.existingName.error", name)); - } + if (id == null) { - if (delete) { - if (id == null) { + // Ajout + + if (delete) { throw new IllegalArgumentException(t("tutti.service.referential.import.person.cannotDeleteWithoutId.error")); } - if (person==null) { - // can't delete if person does not exists - throw new IllegalArgumentException(t("tutti.service.referential.import.person.cannotDeleteNotExisting.error")); + + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.person.add.noName.error")); } - if (persistenceService.isTemporaryPersonUsed(id)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.person.used.error", id)); + + if (!requestResult.addExistingNaturalId(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.person.existingName.error", name)); } - requestResult.addIdToDelete(id); - requestResult.removeExistingNaturalId(name); + + requestResult.addEntityToAdd(bean.toEntity()); } else { - if (bean.getId() == null) { - requestResult.addEntityToAdd(bean.toEntity()); + + // Mise à jour ou Suppression + + Person person = requestResult.getExistingEntityById(id); + + if (person == null) { + throw new IllegalArgumentException(t("tutti.service.referential.import.person.notExistingId.error", id)); + } + + if (delete) { + + // Suppression + + if (persistenceService.isTemporaryPersonUsed(id)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.person.used.error", id)); + } + + requestResult.addIdToDelete(id); + requestResult.removeExistingNaturalId(name); } else { + + // Mise à jour + + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.person.noName.error", id)); + } + + if (!name.equals(person.getName()) && !requestResult.addExistingNaturalId(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.person.existingName.error", name)); + } + requestResult.addEntityToUpdate(bean.toEntity()); + } } } -// protected String getPersonFullName(Person person) { -// return StringUtils.lowerCase( -// StringUtils.trimToEmpty(person.getFirstName()) + -// StringUtils.trimToEmpty(person.getLastName())); -// } - protected void exportTemporaryPerson(File file, List<Person> toExport) throws IOException { PersonModel csvModel = new PersonModel(getCsvSeparator()); diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporarySpeciesService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporarySpeciesService.java index b6b8f74..2d4d180 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporarySpeciesService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporarySpeciesService.java @@ -64,7 +64,7 @@ public class ReferentialTemporarySpeciesService extends AbstractTuttiService { if (requestResult.withToDelete()) { Collection<Integer> idsToDelete = requestResult.getIdsToDelete(); - persistenceService.deleteTemporarySpecies(idsToDelete, true); + persistenceService.deleteTemporarySpecies(idsToDelete); result.setNbRefDeleted(idsToDelete.size()); } @@ -194,46 +194,62 @@ public class ReferentialTemporarySpeciesService extends AbstractTuttiService { Integer id = bean.getIdAsInt(); String name = bean.getName(); - Species species = requestResult.getExistingEntityById(id); boolean delete = BooleanUtils.isTrue(bean.getToDelete()); - if (id != null && requestResult.addExistingEntityId(id)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.species.notExistingId.error", id)); - } - if (StringUtils.isBlank(name)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.species.noName.error", id)); - } - if (!delete && !requestResult.addExistingNaturalId(name) && - (id == null || species != null && !species.getName().equals(name))) { - throw new IllegalArgumentException(t("tutti.service.referential.import.species.existingName.error", name)); - } + if (id == null) { - if (delete) { - if (id == null) { + // Ajout + + if (delete) { throw new IllegalArgumentException(t("tutti.service.referential.import.species.cannotDeleteWithoutId.error")); } + + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.species.add.noName.error")); + } + + if (!requestResult.addExistingNaturalId(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.species.existingName.error", name)); + } + + requestResult.addEntityToAdd(bean.toEntity(null)); + + } else { + + // Mise à jour ou Suppression + + Species species = requestResult.getExistingEntityById(id); + if (species == null) { - // can't delete if species does not exists - throw new IllegalArgumentException(t("tutti.service.referential.import.species.cannotDeleteNotExisting.error")); + throw new IllegalArgumentException(t("tutti.service.referential.import.species.notExistingId.error", id)); } Integer referenceTaxonId = species.getReferenceTaxonId(); - if (persistenceService.isTemporarySpeciesUsed(referenceTaxonId)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.species.used.error", id)); - } + if (delete) { - requestResult.addIdToDelete(referenceTaxonId); - requestResult.removeExistingNaturalId(name); + // Suppression - } else { - if (bean.getId() == null) { + if (persistenceService.isTemporarySpeciesUsed(referenceTaxonId)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.species.used.error", id)); + } - requestResult.addEntityToAdd(bean.toEntity(null)); + requestResult.addIdToDelete(referenceTaxonId); + requestResult.removeExistingNaturalId(name); } else { - requestResult.addEntityToUpdate(bean.toEntity(species.getReferenceTaxonId())); + // Mise à jour + + if (StringUtils.isBlank(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.species.noName.error", id)); + } + + if (!species.getName().equals(name) && !requestResult.addExistingNaturalId(name)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.species.existingName.error", name)); + } + + requestResult.addEntityToUpdate(bean.toEntity(referenceTaxonId)); } } diff --git a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryVesselService.java b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryVesselService.java index 40f8bae..ae27251 100644 --- a/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryVesselService.java +++ b/tutti-service/src/main/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryVesselService.java @@ -66,7 +66,7 @@ public class ReferentialTemporaryVesselService extends AbstractTuttiService { if (requestResult.withToDelete()) { Collection<String> idsToDelete = requestResult.getIdsToDelete(); - persistenceService.deleteTemporaryVessels(idsToDelete, true); + persistenceService.deleteTemporaryVessels(idsToDelete); result.setNbRefDeleted(idsToDelete.size()); } @@ -187,43 +187,64 @@ public class ReferentialTemporaryVesselService extends AbstractTuttiService { String id = StringUtils.trimToNull(bean.getId()); String internationalRegistrationCode = bean.getInternationalRegistrationCode(); - Vessel vessel = requestResult.getExistingEntityById(id); boolean delete = BooleanUtils.isTrue(bean.getToDelete()); - if (id != null && requestResult.addExistingEntityId(id)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.notExistingId.error", id)); - } - if (StringUtils.isBlank(internationalRegistrationCode)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.noInternationalRegistrationCode.error", id)); - } - if (!delete && !requestResult.addExistingNaturalId(internationalRegistrationCode) && - (id == null || vessel != null && !vessel.getRegistrationCode().equals(internationalRegistrationCode))) { - throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.existingInternationalRegistrationCode.error", - internationalRegistrationCode)); - } + if (id == null) { + + // Ajout - if (delete) { - if (id == null) { + if (delete) { throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.cannotDeleteWithoutId.error")); } - if (vessel == null) { - // can't delete if vessel does not exists - throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.cannotDeleteNotExisting.error")); + + if (StringUtils.isBlank(internationalRegistrationCode)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.add.noRegistrationCode.error")); } - if (persistenceService.isTemporaryVesselUsed(id)) { - throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.used.error", id)); + + if (!requestResult.addExistingNaturalId(internationalRegistrationCode)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.existingRegistrationCode.error", internationalRegistrationCode)); } - requestResult.addIdToDelete(id); - requestResult.removeExistingNaturalId(internationalRegistrationCode); + + requestResult.addEntityToAdd(bean.toEntity()); } else { - if (id == null) { - requestResult.addEntityToAdd(bean.toEntity()); + + // Mise à jour ou Suppression + + Vessel vessel = requestResult.getExistingEntityById(id); + + if (vessel == null) { + throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.notExistingId.error", id)); + } + + if (delete) { + + // Suppression + + if (persistenceService.isTemporaryVesselUsed(id)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.used.error", id)); + } + + requestResult.addIdToDelete(id); + requestResult.removeExistingNaturalId(internationalRegistrationCode); } else { + + // Mise à jour + + if (StringUtils.isBlank(internationalRegistrationCode)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.noRegistrationCode.error", id)); + } + + if (!internationalRegistrationCode.equals(vessel.getName()) && !requestResult.addExistingNaturalId(internationalRegistrationCode)) { + throw new IllegalArgumentException(t("tutti.service.referential.import.vessel.existingRegistrationCode.error", internationalRegistrationCode)); + } + requestResult.addEntityToUpdate(bean.toEntity()); + } } + } protected void exportTemporaryVessel(File file, List<Vessel> toExport) throws IOException { diff --git a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties index 6132c96..2774bc4 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_en_GB.properties @@ -217,6 +217,7 @@ tutti.service.referential.export.gear.error= tutti.service.referential.export.person.error= tutti.service.referential.export.species.error= tutti.service.referential.export.vessel.error= +tutti.service.referential.import.gear.add.noName.error= tutti.service.referential.import.gear.cannotDeleteNotExisting.error= tutti.service.referential.import.gear.cannotDeleteWithoutId.error= tutti.service.referential.import.gear.existingName.error= @@ -225,6 +226,7 @@ tutti.service.referential.import.gear.noName.error= tutti.service.referential.import.gear.notExistingId.error= tutti.service.referential.import.gear.used.error= tutti.service.referential.import.gears.error= +tutti.service.referential.import.person.add.noName.error= tutti.service.referential.import.person.cannotDeleteNotExisting.error= tutti.service.referential.import.person.cannotDeleteWithoutId.error= tutti.service.referential.import.person.existingName.error= @@ -233,6 +235,7 @@ tutti.service.referential.import.person.noName.error= tutti.service.referential.import.person.notExistingId.error= tutti.service.referential.import.person.used.error= tutti.service.referential.import.persons.error= +tutti.service.referential.import.species.add.noName.error= tutti.service.referential.import.species.cannotDeleteNotExisting.error= tutti.service.referential.import.species.cannotDeleteWithoutId.error= tutti.service.referential.import.species.error= @@ -241,12 +244,16 @@ tutti.service.referential.import.species.idNotNegative.error= tutti.service.referential.import.species.noName.error= tutti.service.referential.import.species.notExistingId.error= tutti.service.referential.import.species.used.error= +tutti.service.referential.import.vessel.add.noName.error= +tutti.service.referential.import.vessel.add.noRegistrationCode.error= tutti.service.referential.import.vessel.cannotDeleteNotExisting.error= tutti.service.referential.import.vessel.cannotDeleteWithoutId.error= tutti.service.referential.import.vessel.codePrefixMissing.error= tutti.service.referential.import.vessel.existingInternationalRegistrationCode.error= +tutti.service.referential.import.vessel.existingName.error= tutti.service.referential.import.vessel.existingRegistrationCode.error= tutti.service.referential.import.vessel.noInternationalRegistrationCode.error= +tutti.service.referential.import.vessel.noName.error= tutti.service.referential.import.vessel.noRegistrationCode.error= tutti.service.referential.import.vessel.notExistingId.error= tutti.service.referential.import.vessel.used.error= diff --git a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties index ae27c48..4a69a80 100644 --- a/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties +++ b/tutti-service/src/main/resources/i18n/tutti-service_fr_FR.properties @@ -197,6 +197,7 @@ tutti.service.referential.export.gear.error=Erreur lors de l'export des engins d tutti.service.referential.export.person.error=Erreur lors de l'export des personnes dans le fichier %s tutti.service.referential.export.species.error=Erreur lors de l'export des espèces dans le fichier %s tutti.service.referential.export.vessel.error=Erreur lors de l'export des navires dans le fichier %s +tutti.service.referential.import.gear.add.noName.error=Le nom de l'engin est obligatoire tutti.service.referential.import.gear.cannotDeleteNotExisting.error=L'engin temporaire d'identifiant %s n'extsite pas, impossible de la supprimer tutti.service.referential.import.gear.cannotDeleteWithoutId.error=L'identifiant est obligatoire pour la suppression tutti.service.referential.import.gear.existingName.error=L'engin '%s' n'a pas été ajouté au référentiel car il est déjà présent @@ -205,6 +206,7 @@ tutti.service.referential.import.gear.noName.error=Le nom de l'engin est obligat tutti.service.referential.import.gear.notExistingId.error=L'identifiant '%s' n'a pas été trouvé parmi les engins temporaires tutti.service.referential.import.gear.used.error=L'engin temporaire %s est utilisé dans l'application. Vous devez le remplacer pour pouvoir le supprimer. tutti.service.referential.import.gears.error=Erreur lors de l'import des engins du fichier %s +tutti.service.referential.import.person.add.noName.error=Le nom de la personne (prénom ou nom) est obligatoire tutti.service.referential.import.person.cannotDeleteNotExisting.error=La personne temporaire d'identifiant %s n'extsite pas, impossible de la supprimer tutti.service.referential.import.person.cannotDeleteWithoutId.error=L'identifiant est obligatoire pour la suppression tutti.service.referential.import.person.existingName.error=Une personne avec ce nom %s (nom + prénom) existe déjà @@ -213,6 +215,7 @@ tutti.service.referential.import.person.noName.error=Le nom de la personne (pré tutti.service.referential.import.person.notExistingId.error=L'identifiant '%s' n'a pas été trouvé parmi les personnes temporaires tutti.service.referential.import.person.used.error=La personne temporaire %s est utilisée dans l'application. Vous devez la remplacer pour pouvoir la supprimer. tutti.service.referential.import.persons.error=Erreur lors de l'import des personnes du fichier %s +tutti.service.referential.import.species.add.noName.error=Le nom pour l'espèce %s est obligatoire. tutti.service.referential.import.species.cannotDeleteNotExisting.error=L'espèce temporaire d'identifiant %s n'extsite pas, impossible de la supprimer tutti.service.referential.import.species.cannotDeleteWithoutId.error=L'identifiant est obligatoire pour la suppression tutti.service.referential.import.species.error=Erreur lors de l'import des espèces du fichier %s @@ -221,12 +224,11 @@ tutti.service.referential.import.species.idNotNegative.error=L'identifiant d'une tutti.service.referential.import.species.noName.error=Le nom pour l'espèce %s est obligatoire. tutti.service.referential.import.species.notExistingId.error=L'identifiant '%s' n'a pas été trouvé parmi les espèces temporaires tutti.service.referential.import.species.used.error=L'espèce temporaire %s est utilisée dans l'application. Vous devez la remplacer pour pouvoir la supprimer. +tutti.service.referential.import.vessel.add.noRegistrationCode.error=L'immatriculation est obligatoire tutti.service.referential.import.vessel.cannotDeleteNotExisting.error=Le navire temporaire d'identifiant %s n'extsite pas, impossible de la supprimer tutti.service.referential.import.vessel.cannotDeleteWithoutId.error=L'identifiant est obligatoire pour la suppression tutti.service.referential.import.vessel.codePrefixMissing.error=L'identifiant d'un navire temporaire doit commencer par %1$s \: %2$s -tutti.service.referential.import.vessel.existingInternationalRegistrationCode.error= tutti.service.referential.import.vessel.existingRegistrationCode.error=Le navire '%s' n'a pas été ajouté au référentiel car il est déjà présent -tutti.service.referential.import.vessel.noInternationalRegistrationCode.error= tutti.service.referential.import.vessel.noRegistrationCode.error=L'immatriculation est obligatoire tutti.service.referential.import.vessel.notExistingId.error=L'identifiant '%s' n'a pas été trouvé parmi les navires temporaires tutti.service.referential.import.vessel.used.error=Le navire temporaire %s est utilisé dans l'application. Vous devez le remplacer pour pouvoir le supprimer. diff --git a/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonServiceTest.java b/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonServiceTest.java index fd56385..37c15c3 100644 --- a/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonServiceTest.java +++ b/tutti-service/src/test/java/fr/ifremer/tutti/service/referential/ReferentialTemporaryPersonServiceTest.java @@ -31,8 +31,8 @@ public class ReferentialTemporaryPersonServiceTest { private static final String PERSON_UPDATE_FILE_CONTENT = "id;firstName;lastName;toDelete\n" + - "-1;First name 11;Last name 11;N\n" + - "-2;;;Y"; + "-1111;First name 11;Last name 11;N\n" + + "-2222;;;Y"; private static final String PERSON_DELETE_USED_FILE_CONTENT = "id;firstName;lastName;toDelete\n" + -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.