This is an automated email from the git hooks/post-receive script. New change to branch feature/7909_import_generique_id_obsoletes in repository tutti. See http://git.codelutin.com/tutti.git from 9b20e27 Test d'import de données obsolètes pour les engins, strates new 5f644ac Permettre de récupérer des référentiels obsolètes (See #7909) new 8139a51 Suppresion d'un service obsolète new fa6349e Correction de la requete pour récupérer les navires obsolètes The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit fa6349e9037578b41cb222d3714e234c0b824fdd Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Jan 17 18:36:09 2016 +0100 Correction de la requete pour récupérer les navires obsolètes commit 8139a516c28b1f28437da90118fc817b2d2434c0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Jan 17 17:31:48 2016 +0100 Suppresion d'un service obsolète commit 5f644aced15eaa3bf6196d3fb3f14bfb584198a5 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Jan 17 17:02:51 2016 +0100 Permettre de récupérer des référentiels obsolètes (See #7909) Summary of changes: .../service/ReferentialPersistenceService.java | 495 ------- .../service/ReferentialPersistenceServiceImpl.java | 1423 -------------------- .../referential/GearPersistenceServiceImpl.java | 4 +- .../referential/PersonPersistenceServiceImpl.java | 18 +- .../ReferentialPersistenceServiceSupport.java | 11 + .../referential/VesselPersistenceServiceImpl.java | 117 +- .../src/main/resources/queries-failsafe.hbm.xml | 21 +- .../genericFormat/withObsoletes/operation.csv | 2 +- .../genericFormat/withObsoletes/survey.csv | 2 +- 9 files changed, 85 insertions(+), 2008 deletions(-) delete mode 100644 tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java delete mode 100644 tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7909_import_generique_id_obsoletes in repository tutti. See http://git.codelutin.com/tutti.git commit 5f644aced15eaa3bf6196d3fb3f14bfb584198a5 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Jan 17 17:02:51 2016 +0100 Permettre de récupérer des référentiels obsolètes (See #7909) --- .../referential/GearPersistenceServiceImpl.java | 4 +- .../referential/PersonPersistenceServiceImpl.java | 18 ++-- .../ReferentialPersistenceServiceSupport.java | 11 ++ .../referential/VesselPersistenceServiceImpl.java | 117 +++++++++------------ .../src/main/resources/queries-failsafe.hbm.xml | 20 ++-- 5 files changed, 83 insertions(+), 87 deletions(-) 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 72d4b81..137cd42 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 @@ -100,7 +100,7 @@ public class GearPersistenceServiceImpl extends ReferentialPersistenceServiceSup @Override public Gear getGear(Integer gearId) { - Object[] source = queryUniqueWithStatus( + Object[] source = queryUniqueWithStatus2( "gearById", "gearId", IntegerType.INSTANCE, gearId); @@ -287,7 +287,7 @@ public class GearPersistenceServiceImpl extends ReferentialPersistenceServiceSup Preconditions.checkNotNull(source.getName()); Preconditions.checkArgument(Gears.isTemporaryId(source.getIdAsInt())); - Object[] row = queryUniqueWithStatus( + Object[] row = queryUniqueWithStatus2( "gearByName", "gearName", StringType.INSTANCE, source.getName()); 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 1be9acd..b4faad7 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 @@ -90,18 +90,10 @@ public class PersonPersistenceServiceImpl extends ReferentialPersistenceServiceS return Collections.unmodifiableList(result); } - protected void loadPersons(Iterator<Object[]> list, List<Person> result) { - while (list.hasNext()) { - Object[] source = list.next(); - Person target = loadPerson(source); - result.add(target); - } - } - @Override public Person getPerson(Integer personId) { - Object[] source = queryUniqueWithStatus( + Object[] source = queryUniqueWithStatus2( "personById", "personId", IntegerType.INSTANCE, personId); @@ -299,6 +291,14 @@ public class PersonPersistenceServiceImpl extends ReferentialPersistenceServiceS } + protected void loadPersons(Iterator<Object[]> list, List<Person> result) { + while (list.hasNext()) { + Object[] source = list.next(); + Person target = loadPerson(source); + result.add(target); + } + } + protected Person loadPerson(Object... source) { Person target = Persons.newPerson(); diff --git a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/ReferentialPersistenceServiceSupport.java b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/ReferentialPersistenceServiceSupport.java index 5c613b6..68dc077 100644 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/ReferentialPersistenceServiceSupport.java +++ b/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/referential/ReferentialPersistenceServiceSupport.java @@ -79,6 +79,17 @@ public abstract class ReferentialPersistenceServiceSupport extends AbstractPersi return (Object[]) result; } + protected Object[] queryUniqueWithStatus2(String queryName, Object... params) { + + Query query = createQuery(queryName, params); + query.setString("statusValidCode", StatusCode.ENABLE.getValue()); + query.setString("statusTemporaryCode", StatusCode.TEMPORARY.getValue()); + query.setString("statusDisableCode", StatusCode.DISABLE.getValue()); + + Object result = query.uniqueResult(); + return (Object[]) result; + } + protected <E extends TuttiReferentialEntity> void setStatus(String statusCode, E entity) { Status newStatus = Statuss.newStatus(); fr.ifremer.adagio.core.dao.referential.Status status = statusDao.load(statusCode); 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 ad0295c..29e11ff 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 @@ -25,9 +25,7 @@ package fr.ifremer.tutti.persistence.service.referential; */ import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import fr.ifremer.adagio.core.dao.data.vessel.VesselExtendDao; import fr.ifremer.adagio.core.dao.referential.StatusCode; import fr.ifremer.adagio.core.dao.referential.VesselTypeId; @@ -35,7 +33,6 @@ import fr.ifremer.adagio.core.dao.referential.location.LocationExtendDao; import fr.ifremer.adagio.core.dao.referential.location.LocationLabel; import fr.ifremer.adagio.core.dao.referential.location.LocationLevelId; import fr.ifremer.adagio.core.dao.technical.hibernate.TemporaryDataHelper; -import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.Vessels; import org.apache.commons.lang3.StringUtils; @@ -45,6 +42,7 @@ import org.hibernate.type.DateType; import org.hibernate.type.IntegerType; import org.hibernate.type.StringType; import org.nuiton.jaxx.application.ApplicationBusinessException; +import org.nuiton.jaxx.application.ApplicationTechnicalException; import org.springframework.cache.Cache; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; @@ -96,8 +94,7 @@ public class VesselPersistenceServiceImpl extends ReferentialPersistenceServiceS Iterator<Object[]> list = queryListWithStatus( "allVessels", "refDate", DateType.INSTANCE, new Date(), - "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.FISHING_VESSEL.getValue() - ); + "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.FISHING_VESSEL.getValue()); List<Vessel> result = Lists.newArrayList(); Cache vesselByCodeCache = cacheService.getCache("vesselByCode"); @@ -112,94 +109,50 @@ public class VesselPersistenceServiceImpl extends ReferentialPersistenceServiceS List<Vessel> result = Lists.newArrayList(); -// // Récupération des navires actifs -// result.addAll(getAllFishingVessel()); -// result.addAll(getAllScientificVessel()); - - Iterator<Object[]> fishingVesselList = queryListWithStatus2( "allVesselsWithObsoletes", "refDate", DateType.INSTANCE, new Date(), - "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.FISHING_VESSEL.getValue() - ); + "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.FISHING_VESSEL.getValue()); loadVesselsWithObsoletes(fishingVesselList, result, false); int fishingVesselCount = result.size(); - if (log.isInfoEnabled()) { - log.info("fishing vessels: " + fishingVesselCount); + if (log.isDebugEnabled()) { + log.debug("fishing vessels: " + fishingVesselCount); } Iterator<Object[]> scientificVesselList = queryListWithStatus2( "allVesselsWithObsoletes", "refDate", DateType.INSTANCE, new Date(), - "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.SCIENTIFIC_RESEARCH_VESSEL.getValue() - ); + "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.SCIENTIFIC_RESEARCH_VESSEL.getValue()); loadVesselsWithObsoletes(scientificVesselList, result, true); - if (log.isInfoEnabled()) { - log.info("scientific vessels: " + (result.size() - fishingVesselCount)); - } - try { - ImmutableMap<String, Vessel> index = Maps.uniqueIndex(result, TuttiEntities.GET_ID); - if (log.isInfoEnabled()) { - log.info("Total count: "+index.size()); - } - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("...", e); - } + if (log.isDebugEnabled()) { + log.debug("scientific vessels: " + (result.size() - fishingVesselCount)); } return Collections.unmodifiableList(result); } - protected void loadVessels(Iterator<Object[]> list, List<Vessel> result, boolean scientificVessel, Cache vesselByCodeCache) { - while (list.hasNext()) { - Object[] source = list.next(); - Vessel target = loadVessel(source); - target.setScientificVessel(scientificVessel); - result.add(target); - // Add to cache - vesselByCodeCache.put(target.getId(), target); - } - } - - protected void loadVesselsWithObsoletes(Iterator<Object[]> list, List<Vessel> result, boolean scientificVessel) { - - Vessel lastTarget = null; - while (list.hasNext()) { - Object[] source = list.next(); - Vessel target = loadVessel(source); - target.setScientificVessel(scientificVessel); - if (lastTarget != null && !target.getId().equals(lastTarget.getId())) { - - // nouveau code à traiter, on doit enregister l'ancien navire - result.add(lastTarget); - } - lastTarget = target; - } - result.add(lastTarget); - - } - @Override public Vessel getVessel(String vesselCode) { if (log.isDebugEnabled()) { log.debug("get vessel: " + vesselCode); } - // Warning : return a list because more than one line could be found, - // but 'order by' assume that the first one in the good row - Iterator<Object[]> source = queryListWithStatus( + // On ne peut pas récupérer directement un unique objet à cause des période de validité d'immtriculation + // L'ordre induit par la requete nous donne cependant un match en dernière position + Iterator<Object[]> source = queryListWithStatus2( "vesselByCode", "vesselCode", StringType.INSTANCE, vesselCode, "refDate", DateType.INSTANCE, new Date() ); - Vessel result; - if (source.hasNext()) - result = loadVessel(source.next()); - else - result = null; - return result; + Object[] vesselSource = null; + while (source.hasNext()) { + vesselSource = source.next(); + } + if (vesselSource == null) { + throw new ApplicationTechnicalException("Could not find vessel with code: " + vesselCode); + } + return loadVessel(vesselSource); } @@ -474,8 +427,36 @@ public class VesselPersistenceServiceImpl extends ReferentialPersistenceServiceS "vesselInternationalRegistrationCode", StringType.INSTANCE, source.getInternationalRegistrationCode(), "refDate", DateType.INSTANCE, new Date() ); - Vessel result = row.hasNext() ? loadVessel(row.next()) : null; - return result; + return row.hasNext() ? loadVessel(row.next()) : null; + + } + + protected void loadVessels(Iterator<Object[]> list, List<Vessel> result, boolean scientificVessel, Cache vesselByCodeCache) { + while (list.hasNext()) { + Object[] source = list.next(); + Vessel target = loadVessel(source); + target.setScientificVessel(scientificVessel); + result.add(target); + // Add to cache + vesselByCodeCache.put(target.getId(), target); + } + } + + protected void loadVesselsWithObsoletes(Iterator<Object[]> list, List<Vessel> result, boolean scientificVessel) { + + Vessel lastTarget = null; + while (list.hasNext()) { + Object[] source = list.next(); + Vessel target = loadVessel(source); + target.setScientificVessel(scientificVessel); + if (lastTarget != null && !target.getId().equals(lastTarget.getId())) { + + // nouveau code à traiter, on doit enregister l'ancien navire + result.add(lastTarget); + } + lastTarget = target; + } + result.add(lastTarget); } diff --git a/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml b/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml index a364d7e..e666615 100644 --- a/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml +++ b/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml @@ -1280,16 +1280,17 @@ LEFT OUTER JOIN v.vesselFeatures AS vf WHERE v.code = :vesselCode - AND v.status.code IN (:statusValidCode, :statusTemporaryCode) - AND NOT(coalesce(vrp.endDateTime, '2999-12-31 00:00:00') < coalesce(:refDate,sysdate) - OR vrp.vesselRegistrationPeriodPk.startDateTime > coalesce(:refDate,sysdate) - ) - ORDER BY vf.startDateTime DESC + AND v.status.code IN (:statusValidCode, :statusTemporaryCode, :statusDisableCode) + AND vrp.vesselRegistrationPeriodPk.startDateTime <= :refDate + AND vf.startDateTime <= :refDate + AND coalesce(vf.endDateTime, :refDate) >= :refDate + ORDER BY vf.startDateTime, vrp.vesselRegistrationPeriodPk.startDateTime ]]> <query-param name="vesselCode" type="java.lang.String"/> <query-param name="refDate" type="java.util.Date"/> <query-param name="statusValidCode" type="java.lang.String"/> <query-param name="statusTemporaryCode" type="java.lang.String"/> + <query-param name="statusDisableCode" type="java.lang.String"/> </query> <!-- [REF-02-2] Get a vessel by his internationalRegistrationCode --> @@ -1385,11 +1386,12 @@ FROM GearImpl g WHERE g.id = :gearId - AND g.status.code IN (:statusValidCode, :statusTemporaryCode) + AND g.status.code IN (:statusValidCode, :statusTemporaryCode, :statusDisableCode) ]]> <query-param name="gearId" type="java.lang.Integer"/> <query-param name="statusValidCode" type="java.lang.String"/> <query-param name="statusTemporaryCode" type="java.lang.String"/> + <query-param name="statusDisableCode" type="java.lang.String"/> </query> <!-- [REF-03-2] Get a gear by his name --> @@ -1404,11 +1406,12 @@ FROM GearImpl g WHERE g.name = :gearName - AND g.status.code IN (:statusValidCode, :statusTemporaryCode) + AND g.status.code IN (:statusValidCode, :statusTemporaryCode, :statusDisableCode) ]]> <query-param name="gearName" type="java.lang.String"/> <query-param name="statusValidCode" type="java.lang.String"/> <query-param name="statusTemporaryCode" type="java.lang.String"/> + <query-param name="statusDisableCode" type="java.lang.String"/> </query> <!-- [REF-03-3] Get all gears (with obsoletes) for a given gearType --> @@ -1472,11 +1475,12 @@ FROM PersonImpl p WHERE p.id = :personId - AND p.status.code IN (:statusValidCode, :statusTemporaryCode) + AND p.status.code IN (:statusValidCode, :statusTemporaryCode, :statusDisableCode) ]]> <query-param name="personId" type="java.lang.Integer"/> <query-param name="statusValidCode" type="java.lang.String"/> <query-param name="statusTemporaryCode" type="java.lang.String"/> + <query-param name="statusDisableCode" type="java.lang.String"/> </query> <!-- [REF-04-2] Get one person by his full name --> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7909_import_generique_id_obsoletes in repository tutti. See http://git.codelutin.com/tutti.git commit 8139a516c28b1f28437da90118fc817b2d2434c0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Jan 17 17:31:48 2016 +0100 Suppresion d'un service obsolète --- .../service/ReferentialPersistenceService.java | 495 ------- .../service/ReferentialPersistenceServiceImpl.java | 1423 -------------------- 2 files changed, 1918 deletions(-) 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 deleted file mode 100644 index 526b910..0000000 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java +++ /dev/null @@ -1,495 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence - * %% - * 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.Predicate; -import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; -import fr.ifremer.tutti.persistence.entities.data.Cruise; -import fr.ifremer.tutti.persistence.entities.data.Program; -import fr.ifremer.tutti.persistence.entities.data.SampleCategoryModel; -import fr.ifremer.tutti.persistence.entities.data.SpeciesAbleBatch; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.Gear; -import fr.ifremer.tutti.persistence.entities.referential.ObjectType; -import fr.ifremer.tutti.persistence.entities.referential.Person; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; -import fr.ifremer.tutti.persistence.entities.referential.TuttiReferentialEntity; -import fr.ifremer.tutti.persistence.entities.referential.Vessel; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Collection; -import java.util.List; - -/** - * API to obtain all referentail referential data. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Transactional(readOnly = true) -public interface ReferentialPersistenceService extends TuttiPersistenceServiceImplementor { - - //------------------------------------------------------------------------// - //-- Referential methods --// - //------------------------------------------------------------------------// - - /** - * @return all available zones (used by a {@link Program}. - * @see Program#getZone() - * @see Program#setZone(TuttiLocation) - * @since 0.3 - */ - @Cacheable(value = "programZones") - List<TuttiLocation> getAllProgramZone(); - - /** - * @return all countries (used by a {@link Cruise}). - * @since 0.1 - */ - @Cacheable(value = "countries") - List<TuttiLocation> getAllCountry(); - - /** - * @return all harbours (used by a {@link Cruise}). - * @see {@link Cruise#getDepartureLocation()} - * @see {@link Cruise#setDepartureLocation(TuttiLocation)} - * @see {@link Cruise#getReturnLocation()} - * @see {@link Cruise#setReturnLocation(TuttiLocation)} - * @since 1.2 - */ - @Cacheable(value = "harbours") - List<TuttiLocation> getAllHarbour(); - - /** - * Get the list of location of type strata that match the given zone id. - * - * @param zoneId id of the parent zone (can not be null) - * @return the stratas with given zone id as location parent - * @since 1.0 - */ - List<TuttiLocation> getAllFishingOperationStrata(String zoneId); - - /** - * Get the list of location of type substra that match the given zone id or - * if not null the given strata id. - * - * @param zoneId id of the parent zone (can not be null) - * @param strataId id of the optional parent strata - * @return the list of localite with given zone id as location parent / or strata - * @since 1.0 - */ - List<TuttiLocation> getAllFishingOperationSubStrata(String zoneId, String strataId); - - /** - * Get the list of location of type substra that match the given zone id or - * if not null the given strata id or if not null the given substrata id if - * not null. - * - * @param zoneId id of the parent zone (can not be null) - * @param strataId id of the optional parent strata - * @param subStrataId id of the optional parent subStrata - * @return the list of localite with given zone id as location parent / or strata or substrata - * @since 1.0 - */ - List<TuttiLocation> getAllFishingOperationLocation(String zoneId, String strataId, String subStrataId); - - /** - * @return all scientific vessels (used by a {@link Cruise}). - * @see Cruise#getVessel() - * @see Cruise#setVessel(Vessel) - * @since 0.3 - */ - List<Vessel> getAllScientificVessel(); - - /** - * @return all commercial vessels (used by a {@link Cruise}). - * @see Cruise#getVessel() - * @see Cruise#setVessel(Vessel) - * @since 0.3 - */ - @Cacheable(value = "fishingVessels") - List<Vessel> getAllFishingVessel(); - - /** - * @param vesselCode code of the vessel to find - * @return the vessel - * @since 0.3 - */ - @Cacheable(value = "vesselByCode", key = "#vesselCode") - Vessel getVessel(String vesselCode); - - /** - * @return all referent species - * @since 0.3 - */ - @Cacheable(value = "referentSpecies") - List<Species> getAllReferentSpecies(); - - /** - * @return all species - * @since 0.3 - */ - @Cacheable(value = "species") - List<Species> getAllSpecies(); - - /** - * Get a location by id . - * - * @param id the id of location to load - * @return the location for the given id, or {@code null} if not found - * @since 1.0 - */ - TuttiLocation getLocation(String id); - - /** - * Obtain a species given his referenceTaxonId. - * - * @param referenceTaxonId id of the reference taxon of the species to load - * @return the species or {@code null} if not found. - * @see Species#getReferenceTaxonId() - * @see Species#getRefTaxCode() - * @since 0.3 - */ - @Cacheable(value = "referentSpeciesById", key = "#referenceTaxonId") - Species getSpeciesByReferenceTaxonId(Integer referenceTaxonId); - - /** - * Obtain a species with external code as vernacular code given his referenceTaxonId. - * <p/> - * <strong>Note:</strong> {@link Species#getRefTaxCode()} will not be - * filled by with method. - * - * @param referenceTaxonId id of the reference taxon of the species to load - * @return the species or {@code null} if not found. - * @see Species#getReferenceTaxonId() - * @see Species#getVernacularCode() - * @since 2.0 - */ - @Cacheable(value = "referentSpeciesByIdVernacular", key = "#referenceTaxonId") - Species getSpeciesByReferenceTaxonIdWithVernacularCode(Integer referenceTaxonId); - - /** - * @return all caracteristics of the system. - * @since 1.0 - */ - @Cacheable(value = "pmfms") - List<Caracteristic> getAllCaracteristic(); - - /** - * @return all caracteristics of the system with the ones which are kind of protected. - * @since 2.3 - */ - @Cacheable(value = "pmfmsWithProtected") - List<Caracteristic> getAllCaracteristicWithProtected(); - - /** - * @return all caracteristics of the system useable for {@link SampleCategoryModel}. - * @since 2.4 - */ - List<Caracteristic> getAllCaracteristicForSampleCategory(); - - /** - * @return all numeric caracteristics of the system. - * @since 1.0.2 - */ - List<Caracteristic> getAllNumericCaracteristic(); - - /** - * @return all object type - * @since 1.0.2 - */ - @Cacheable(value = "objectTypes") - List<ObjectType> getAllObjectType(); - - Caracteristic getSizeCategoryCaracteristic(); - - Caracteristic getSexCaracteristic(); - - Caracteristic getSortedUnsortedCaracteristic(); - - Caracteristic getMaturityCaracteristic(); - - Caracteristic getAgeCaracteristic(); - - Caracteristic getMarineLitterCategoryCaracteristic(); - - Caracteristic getMarineLitterSizeCategoryCaracteristic(); - - Caracteristic getVerticalOpeningCaracteristic(); - - Caracteristic getHorizontalOpeningWingsCaracteristic(); - - Caracteristic getHorizontalOpeningDoorCaracteristic(); - - Caracteristic getDeadOrAliveCaracteristic(); - - Caracteristic getPmfmIdCaracteristic(); - - Caracteristic getWeightMeasuredCaracteristic(); - - boolean isTemporary(TuttiReferentialEntity entity); - - List<Gear> getAllScientificGear(); - - List<Gear> getAllFishingGear(); - - @Cacheable(value = "persons") - List<Person> getAllPerson(); - - @Cacheable(value = "personById", key = "#personId") - Person getPerson(Integer personId); - - Gear getGear(Integer gearId); - - @Cacheable(value = "pmfmById", key = "#pmfmId") - Caracteristic getCaracteristic(Integer pmfmId); - - Predicate<SpeciesAbleBatch> getVracBatchPredicate(); - - boolean isVracBatch(SpeciesAbleBatch speciesBatch); - - boolean isHorsVracBatch(SpeciesAbleBatch speciesBatch); - - @Cacheable(value = "objectTypeByCode", key = "#objectTypeCode") - ObjectType getObjectType(String objectTypeCode); - - /** - * Import given temporary species. - * - * @param species species to import - * @since 1.0 - */ - @Transactional(readOnly = false) - @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons"}, allEntries = true) - List<Species> importTemporarySpecies(List<Species> species); - - /** - * Import given temporary vessels. - * - * @param vessels vessels to import - * @since 1.0 - */ - @Transactional(readOnly = false) - @CacheEvict(value = {"fishingVessels", "vesselByCode"}, allEntries = true) - List<Vessel> importTemporaryVessel(List<Vessel> vessels); - - /** - * Import given temporary persons. - * - * @param persons persons to import - * @since 1.0 - */ - @Transactional(readOnly = false) - @CacheEvict(value = {"persons", "personById"}, allEntries = true) - List<Person> importTemporaryPerson(List<Person> persons); - - /** - * Import given temporary gears. - * - * @param gears gears to import - * @since 1.0 - */ - @Transactional(readOnly = false) - @CacheEvict(value = "gears", allEntries = true) - List<Gear> importTemporaryGear(List<Gear> gears); - - /** - * Replace the {@code source} gear by - * the {@code target} one in all data. - * - * @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", "gears"}, allEntries = true) - void replaceGear(Gear source, Gear target, boolean delete); - - /** - * Replace the {@code source} species by - * the {@code target} one in all data. - * - * @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", - "species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons"}, - allEntries = true) - void replaceSpecies(Species source, Species target, boolean delete); - - /** - * Replace the {@code source} person by - * the {@code target} one in all data. - * - * @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", "persons", "personById"}, - allEntries = true) - void replacePerson(Person source, Person target, boolean delete); - - /** - * Replace the {@code source} vessel by - * the {@code target} one in all data. - * - * @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", "fishingVessels", "vesselByCode"}, - allEntries = true) - 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.8 - */ - @Transactional(readOnly = false) - @CacheEvict(value = "gears", allEntries = true) - void deleteTemporaryGear(Integer id, boolean checkIfUsed); - - /** - * 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 - * @since 3.8 - */ - @Transactional(readOnly = false) - @CacheEvict(value = "gears", allEntries = true) - void deleteTemporaryGears(Collection<Integer> ids, 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.8 - */ - @Transactional(readOnly = false) - @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons"}, allEntries = true) - void deleteTemporarySpecies(Integer id, boolean checkIfUsed); - - /** - * Delete the temporary species with the given {@code ids}. - * - * @param ids ids 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", "obsoleteReferentTaxons"}, allEntries = true) - void deleteTemporarySpecies(Collection<Integer> ids, 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.8 - */ - @Transactional(readOnly = false) - @CacheEvict(value = {"persons", "personById"}, allEntries = true) - void deleteTemporaryPerson(Integer id, boolean checkIfUsed); - - /** - * 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); - - /** - * 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.8 - */ - @Transactional(readOnly = false) - @CacheEvict(value = {"fishingVessels", "vesselByCode"}, allEntries = true) - void deleteTemporaryVessel(String code, boolean checkIfUsed); - - /** - * 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 - * @since 3.8 - */ - @Transactional(readOnly = false) - @CacheEvict(value = {"fishingVessels", "vesselByCode"}, allEntries = true) - void deleteTemporaryVessels(Collection<String> codes, boolean checkIfUsed); - - /** - * Check if the temporary person with the given {@code id} is used. - * - * @param id id of the person to check - * @since 3.8 - */ - boolean isTemporaryPersonUsed(Integer id); - - /** - * Check if the temporary species with the given {@code id} is used. - * - * @param id id of the species to check - * @since 3.8 - */ - boolean isTemporarySpeciesUsed(Integer id); - - /** - * Check if the temporary gear with the given {@code id} is used. - * - * @param id id of the gear to remove - * @since 3.8 - */ - boolean isTemporaryGearUsed(Integer id); - - /** - * Check if the temporary vessel with the given {@code id} is used. - * - * @param code code of the vessel to remove - * @since 3.8 - */ - boolean isTemporaryVesselUsed(String code); - -} 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 deleted file mode 100644 index 57d7208..0000000 --- a/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java +++ /dev/null @@ -1,1423 +0,0 @@ -package fr.ifremer.tutti.persistence.service; - -/* - * #%L - * Tutti :: Persistence - * %% - * 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.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import fr.ifremer.adagio.core.dao.administration.user.DepartmentId; -import fr.ifremer.adagio.core.dao.administration.user.PersonExtendDao; -import fr.ifremer.adagio.core.dao.administration.user.UserProfilId; -import fr.ifremer.adagio.core.dao.data.vessel.VesselExtendDao; -import fr.ifremer.adagio.core.dao.referential.StatusCode; -import fr.ifremer.adagio.core.dao.referential.StatusDao; -import fr.ifremer.adagio.core.dao.referential.VesselTypeId; -import fr.ifremer.adagio.core.dao.referential.gear.FishingGearExtendDao; -import fr.ifremer.adagio.core.dao.referential.gear.GearClassification; -import fr.ifremer.adagio.core.dao.referential.gear.GearClassificationId; -import fr.ifremer.adagio.core.dao.referential.location.LocationClassificationId; -import fr.ifremer.adagio.core.dao.referential.location.LocationExtendDao; -import fr.ifremer.adagio.core.dao.referential.location.LocationLabel; -import fr.ifremer.adagio.core.dao.referential.location.LocationLevelId; -import fr.ifremer.adagio.core.dao.referential.pmfm.PmfmId; -import fr.ifremer.adagio.core.dao.referential.pmfm.QualitativeValueId; -import fr.ifremer.adagio.core.dao.referential.pmfm.UnitId; -import fr.ifremer.adagio.core.dao.referential.taxon.TaxonName; -import fr.ifremer.adagio.core.dao.referential.taxon.TaxonNameExtendDao; -import fr.ifremer.adagio.core.dao.referential.taxon.TaxonNameImpl; -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; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristic; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValue; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicQualitativeValues; -import fr.ifremer.tutti.persistence.entities.referential.CaracteristicType; -import fr.ifremer.tutti.persistence.entities.referential.Caracteristics; -import fr.ifremer.tutti.persistence.entities.referential.Gear; -import fr.ifremer.tutti.persistence.entities.referential.Gears; -import fr.ifremer.tutti.persistence.entities.referential.ObjectType; -import fr.ifremer.tutti.persistence.entities.referential.ObjectTypes; -import fr.ifremer.tutti.persistence.entities.referential.Person; -import fr.ifremer.tutti.persistence.entities.referential.Persons; -import fr.ifremer.tutti.persistence.entities.referential.Species; -import fr.ifremer.tutti.persistence.entities.referential.Speciess; -import fr.ifremer.tutti.persistence.entities.referential.Status; -import fr.ifremer.tutti.persistence.entities.referential.Statuss; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocation; -import fr.ifremer.tutti.persistence.entities.referential.TuttiLocations; -import fr.ifremer.tutti.persistence.entities.referential.TuttiReferentialEntity; -import fr.ifremer.tutti.persistence.entities.referential.Vessel; -import fr.ifremer.tutti.persistence.entities.referential.Vessels; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -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; -import org.springframework.stereotype.Service; - -import javax.annotation.Resource; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -/** - * Implementation of the {@link ReferentialPersistenceService} using a adagio - * data-source. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -@Service("referentialPersistenceService") -public class ReferentialPersistenceServiceImpl extends AbstractPersistenceService implements ReferentialPersistenceService { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ReferentialPersistenceServiceImpl.class); - - @Resource(name = "taxonNameDao") - protected TaxonNameExtendDao taxonNameDao; - - @Resource(name = "statusDao") - protected StatusDao statusDao; - - @Resource(name = "personDao") - protected PersonExtendDao personDao; - - @Resource(name = "fishingGearDao") - protected FishingGearExtendDao fishingGearDao; - - @Resource(name = "vesselExtendDao") - protected VesselExtendDao vesselExtendDao; - - @Resource(name = "locationDao") - protected LocationExtendDao locationDao; - - @Resource(name = "cacheService") - protected CacheService cacheService; - - //TODO-TC We should prefer AOP thant Proxy stuff to avoid this. - @Resource(name = "referentialPersistenceService") - protected ReferentialPersistenceService thisService; - - protected Predicate<SpeciesAbleBatch> batchVracPredicate; - - protected Set<Integer> propertedPmfmIds; - - @Override - public void init() { - super.init(); - - batchVracPredicate = SpeciesAbleBatchs.newSpeciesAbleBatchCategoryPredicate( - PmfmId.SORTED_UNSORTED.getValue(), - QualitativeValueId.SORTED_VRAC.getValue()); - - // init protected pmfm ids - propertedPmfmIds = Sets.newHashSet( - PmfmId.MULTIRIG_AGGREGATION.getValue(), - PmfmId.MULTIRIG_NUMBER.getValue(), - PmfmId.STATION_NUMBER.getValue(), - PmfmId.RECTILINEAR_OPERATION.getValue(), - PmfmId.HAUL_VALID.getValue(), - PmfmId.TRAWL_DISTANCE.getValue(), - PmfmId.SURVEY_PART.getValue(), - PmfmId.SORTED_UNSORTED.getValue(), - PmfmId.ID_PMFM.getValue() - ); - } - - /** - * @param pmfmId id of pmfm to test - * @return {@code true} if the pmfm should NOT be used for caracteristics lists - * (i.e. because used somewhere when storing some properties into the database) - */ - protected boolean isProtectedCaracteristic(Integer pmfmId) { - return propertedPmfmIds.contains(pmfmId); - } - - //------------------------------------------------------------------------// - //-- ReferentialPersistenceService implentation --// - //------------------------------------------------------------------------// - - @Override - public List<TuttiLocation> getAllProgramZone() { - Iterator<Object[]> list = queryListWithStatus( - "allLocationsByLevelAndClassificiation", - "locationClassificationId", IntegerType.INSTANCE, LocationClassificationId.SECTOR.getValue(), - "locationLevelId", IntegerType.INSTANCE, LocationLevelId.SCIENTIFIC_CRUISE_PROGRAM.getValue()); - - List<TuttiLocation> result = Lists.newArrayList(); - while (list.hasNext()) { - Object[] source = list.next(); - TuttiLocation target = loadLocation(source); - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<TuttiLocation> getAllCountry() { - Iterator<Object[]> list = queryListWithStatus( - "allLocationsByLevelAndClassificiation", - "locationClassificationId", IntegerType.INSTANCE, LocationClassificationId.TERRITORIAL.getValue(), - "locationLevelId", IntegerType.INSTANCE, LocationLevelId.PAYS_ISO3.getValue()); - - List<TuttiLocation> result = Lists.newArrayList(); - while (list.hasNext()) { - Object[] source = list.next(); - TuttiLocation target = loadLocation(source); - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<TuttiLocation> getAllHarbour() { - Iterator<Object[]> list = queryListWithStatus( - "allLocationsByLevelAndClassificiation", - "locationClassificationId", IntegerType.INSTANCE, LocationClassificationId.TERRITORIAL.getValue(), - "locationLevelId", IntegerType.INSTANCE, LocationLevelId.PORT.getValue()); - - List<TuttiLocation> result = Lists.newArrayList(); - while (list.hasNext()) { - Object[] source = list.next(); - TuttiLocation target = loadLocation(source); - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<TuttiLocation> getAllFishingOperationStrata(String zoneId) { - Preconditions.checkNotNull(zoneId); - List<TuttiLocation> result = getFishingOperationLocationsByParent( - LocationLevelId.SCIENTIFIC_CRUISE_STRATA.getValue(), - Integer.valueOf(zoneId), - LocationLevelId.SCIENTIFIC_CRUISE_PROGRAM.getValue()); - return Collections.unmodifiableList(result); - } - - @Override - public List<TuttiLocation> getAllFishingOperationSubStrata(String zoneId, - String strataId) { - - String parentId; - Integer parentLocationLevelId; - - if (strataId != null) { - - // use strata as parent - parentId = strataId; - parentLocationLevelId = LocationLevelId.SCIENTIFIC_CRUISE_STRATA.getValue(); - - } else { - - // use zoneId as parent - parentId = zoneId; - parentLocationLevelId = LocationLevelId.SCIENTIFIC_CRUISE_PROGRAM.getValue(); - } - - Preconditions.checkNotNull(parentId); - List<TuttiLocation> result = getFishingOperationLocationsByParent( - LocationLevelId.SCIENTIFIC_CRUISE_SUB_STRATA.getValue(), - Integer.valueOf(parentId), - parentLocationLevelId); - return Collections.unmodifiableList(result); - } - - @Override - public List<TuttiLocation> getAllFishingOperationLocation(String zoneId, - String strataId, - String subStrataId) { - - String parentId; - Integer parentLocationLevelId; - - if (subStrataId != null) { - - // use substrata as parent - parentId = subStrataId; - parentLocationLevelId = LocationLevelId.SCIENTIFIC_CRUISE_SUB_STRATA.getValue(); - - } else if (strataId != null) { - - // use strata as parent - parentId = strataId; - parentLocationLevelId = LocationLevelId.SCIENTIFIC_CRUISE_STRATA.getValue(); - - } else { - - // use zoneId as parent - parentId = zoneId; - parentLocationLevelId = LocationLevelId.SCIENTIFIC_CRUISE_PROGRAM.getValue(); - } - - Preconditions.checkNotNull(parentId); - List<TuttiLocation> result = getFishingOperationLocationsByParent( - LocationLevelId.SCIENTIFIC_CRUISE_LOCALITE.getValue(), - Integer.valueOf(parentId), - parentLocationLevelId); - return Collections.unmodifiableList(result); - } - - @Override - public TuttiLocation getLocation(String id) { - Object[] source = queryUnique( - "locationById", - "locationId", IntegerType.INSTANCE, Integer.valueOf(id) - ); - if (source == null) { - return null; - } - TuttiLocation target = loadLocation(source); - return target; - } - - @Override - public List<Vessel> getAllScientificVessel() { - - Iterator<Object[]> list = queryListWithStatus( - "allVessels", - "refDate", DateType.INSTANCE, new Date(), - "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.SCIENTIFIC_RESEARCH_VESSEL.getValue()); - - List<Vessel> result = Lists.newArrayList(); - Cache vesselByCodeCache = cacheService.getCache("vesselByCode"); - - while (list.hasNext()) { - Object[] source = list.next(); - Vessel target = loadVessel(source, true); - result.add(target); - // Add to cache - vesselByCodeCache.put(target.getId(), target); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<Vessel> getAllFishingVessel() { - Iterator<Object[]> list = queryListWithStatus( - "allVessels", - "refDate", DateType.INSTANCE, new Date(), - "vesselTypeId", IntegerType.INSTANCE, VesselTypeId.FISHING_VESSEL.getValue() - ); - - List<Vessel> result = Lists.newArrayList(); - Cache vesselByCodeCache = cacheService.getCache("vesselByCode"); - - while (list.hasNext()) { - Object[] source = list.next(); - Vessel target = loadVessel(source, true); - target.setScientificVessel(false); - result.add(target); - - // Add to cache - vesselByCodeCache.put(target.getId(), target); - } - return Collections.unmodifiableList(result); - } - - @Override - public Vessel getVessel(String vesselCode) { - if (log.isDebugEnabled()) { - log.debug("get vessel: " + vesselCode); - } - // Warning : return a list because more than one line could be found, - // but 'order by' assume that the first one in the good row - Iterator<Object[]> source = queryListWithStatus( - "vessel", - "vesselCode", StringType.INSTANCE, vesselCode, - "refDate", DateType.INSTANCE, new Date() - ); - Vessel result; - if (source.hasNext()) - result = loadVessel(source.next(), false); - else - result = null; - return result; - } - - @Override - public List<Gear> getAllScientificGear() { - - Iterator<Object[]> sources = queryListWithStatus( - "allGears", - "gearClassificiationId", IntegerType.INSTANCE, GearClassificationId.SCIENTIFIC_CRUISE.getValue()); - List<Gear> result = Lists.newArrayList(); - while (sources.hasNext()) { - Object[] source = sources.next(); - Gear target = loadGear(source); - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<Gear> getAllFishingGear() { - Iterator<Object[]> sources = queryListWithStatus( - "allGears", - "gearClassificiationId", IntegerType.INSTANCE, GearClassificationId.FAO.getValue()); - List<Gear> result = Lists.newArrayList(); - while (sources.hasNext()) { - Object[] source = sources.next(); - Gear target = loadGear(source); - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<Person> getAllPerson() { - Iterator<Object[]> list = queryListWithStatus( - "allPersons", - "observerProfilId", IntegerType.INSTANCE, UserProfilId.OBSERVER.getValue(), - "projectMemberProfilId", IntegerType.INSTANCE, UserProfilId.PROJECT_MEMBER.getValue(), - "userProfilId", IntegerType.INSTANCE, UserProfilId.USER.getValue(), - "departementPrefixCode", StringType.INSTANCE, "PDG-" //FIXME Use the Departement enum when it will exists in adagio -// "departementPrefixCode", StringType.INSTANCE, enumeration.USER_PROFIL_ID_DEPARTEMENT_PREFIX - ); - - List<Person> result = Lists.newArrayList(); - while (list.hasNext()) { - Object[] source = list.next(); - Person target = loadPerson(source); - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public Person getPerson(Integer personId) { - Object[] source = queryUnique( - "person", - "personId", IntegerType.INSTANCE, personId); - - Person result = source == null ? null : loadPerson(source); - return result; - } - - @Override - public Gear getGear(Integer gearId) { - Object[] source = queryUnique( - "gear", - "gearId", IntegerType.INSTANCE, gearId); - - Gear result = source == null ? null : loadGear(source); - return result; - } - - @Override - public List<Species> getAllSpecies() { - - TaxonRefVO[] sources = taxonNameDao.getAllTaxonNames( - true, TranscribingItemTypeId.TAXON_NAME_REFTAX_CODE.getValue()); - - List<Species> result = Lists.newArrayListWithCapacity(sources.length); - List<Species> referenceTaxonsOnly = Lists.newArrayList(); - Cache referentSpeciesByIdCache = cacheService.getCache("referentSpeciesById"); - for (TaxonRefVO source : sources) { - Species target = loadSpecies(source); - - // FIXME kmorin 20130423 http://forge.codelutin.com/issues/2350 - target.setRefTaxCode(StringUtils.trim(target.getExternalCode())); - - if (target.isReferenceTaxon()) { - - // Add to cache : - referentSpeciesByIdCache.put(target.getReferenceTaxonId(), target); - - referenceTaxonsOnly.add(target); - } - result.add(target); - } - - // Add to cache : - Cache allReferentSpeciesCache = cacheService.getCache("referentSpecies"); - allReferentSpeciesCache.put("", referenceTaxonsOnly); - - return Collections.unmodifiableList(result); - } - - @Override - public List<Species> getAllReferentSpecies() { - - TaxonRefVO[] sources = taxonNameDao.getAllTaxonNames( - false, TranscribingItemTypeId.TAXON_NAME_REFTAX_CODE.getValue()); - List<Species> result = Lists.newArrayListWithCapacity(sources.length); - Cache referentSpeciesByIdCache = cacheService.getCache("referentSpeciesById"); - for (TaxonRefVO source : sources) { - Species target = loadSpecies(source); - - // FIXME kmorin 20130423 http://forge.codelutin.com/issues/2350 - target.setRefTaxCode(StringUtils.trim(target.getExternalCode())); - - // Add to cache : - referentSpeciesByIdCache.put(target.getReferenceTaxonId(), target); - - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public Species getSpeciesByReferenceTaxonId(Integer referenceTaxonId) { - Species result = getSpeciesByReferenceTaxonId( - referenceTaxonId, - TranscribingItemTypeId.TAXON_NAME_REFTAX_CODE.getValue()); - if (result != null) { - result.setRefTaxCode(result.getExternalCode()); - } - return result; - } - - @Override - public Species getSpeciesByReferenceTaxonIdWithVernacularCode(Integer referenceTaxonId) { - Species result = getSpeciesByReferenceTaxonId( - referenceTaxonId, - TranscribingItemTypeId.TAXON_NAME_LOCAL_NAME.getValue()); - if (result != null) { - result.setVernacularCode(result.getExternalCode()); - } - return result; - } - - protected Species getSpeciesByReferenceTaxonId(Integer referenceTaxonId, - Integer transcribingTypeId) { - Species target; - try { - TaxonRefVO source = taxonNameDao.getTaxonNameReferent( - referenceTaxonId, transcribingTypeId); - target = loadSpecies(source); - } catch (DataRetrievalFailureException drfe) { - target = null; - } - return target; - } - - @Override - public List<Caracteristic> getAllCaracteristic() { - return getAllCaracteristics(false); - } - - @Override - public List<Caracteristic> getAllCaracteristicWithProtected() { - return getAllCaracteristics(true); - } - - @Override - public List<Caracteristic> getAllCaracteristicForSampleCategory() { - List<Caracteristic> allCaracteristicWithProtected = thisService.getAllCaracteristicWithProtected(); - List<Caracteristic> result = Lists.newArrayList( - Iterables.filter(allCaracteristicWithProtected, Caracteristics.newSampleCategoryModelPredicate())); - return result; - } - - protected List<Caracteristic> getAllCaracteristics(boolean withProtected) { - Iterator<Object[]> sources = queryListWithStatus( - "allPmfm", - "unitIdNone", IntegerType.INSTANCE, UnitId.NONE.getValue()); - List<Caracteristic> result = Lists.newArrayList(); - Cache pmfmByIdCache = cacheService.getCache("pmfmById"); - while (sources.hasNext()) { - Object[] source = sources.next(); - Integer pmfmId = (Integer) source[0]; - Caracteristic target = loadCaracteristic(source); - // Skip some protected PSFM - if (withProtected || !isProtectedCaracteristic(pmfmId)) { - result.add(target); - } - pmfmByIdCache.put(pmfmId, target); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<ObjectType> getAllObjectType() { - Iterator<Object[]> sources = queryList("allObjectType"); - List<ObjectType> result = Lists.newArrayList(); - Cache cache = cacheService.getCache("objectTypeByCode"); - while (sources.hasNext()) { - Object[] source = sources.next(); - String code = (String) source[0]; - ObjectType target = loadObjectType(source); - cache.put(code, target); - result.add(target); - } - return Collections.unmodifiableList(result); - } - - @Override - public ObjectType getObjectType(String objectTypeCode) { - Object[] source = queryUnique("objectType", - "objectTypeCode", StringType.INSTANCE, objectTypeCode); - ObjectType target = loadObjectType(source); - return target; - } - - @Override - public List<Caracteristic> getAllNumericCaracteristic() { - List<Caracteristic> result = Lists.newArrayList(); - - for (Caracteristic caracteristic : getAllCaracteristic()) { - if (caracteristic.isNumericType()) { - result.add(caracteristic); - } - } - return Collections.unmodifiableList(result); - } - - @Override - public Caracteristic getSizeCategoryCaracteristic() { - Integer pmfmId = PmfmId.SIZE_CATEGORY.getValue(); - Caracteristic result = getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getSexCaracteristic() { - Integer pmfmId = PmfmId.SEX.getValue(); - Caracteristic result = getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getSortedUnsortedCaracteristic() { - Integer pmfmId = PmfmId.SORTED_UNSORTED.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - - // Search the qualitative value to skip - //FIXME-TC How can this works with cache ? result is the cached instance, so we are modifing cache - List<CaracteristicQualitativeValue> qualitativeValue = - Lists.newArrayList(result.getQualitativeValue()); - Iterator<CaracteristicQualitativeValue> iterator = qualitativeValue.iterator(); - while (iterator.hasNext()) { - CaracteristicQualitativeValue qv = iterator.next(); - if (QualitativeValueId.UNSORTED.getValue().equals(Integer.valueOf(qv.getId()))) { - iterator.remove(); - break; - } - } - result.setQualitativeValue(Collections.unmodifiableList(qualitativeValue)); - return result; - } - - @Override - public Caracteristic getMaturityCaracteristic() { - Integer pmfmId = PmfmId.MATURITY.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getAgeCaracteristic() { - Integer pmfmId = PmfmId.AGE.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getMarineLitterCategoryCaracteristic() { - Integer pmfmId = PmfmId.MARINE_LITTER_TYPE.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getMarineLitterSizeCategoryCaracteristic() { - Integer pmfmId = PmfmId.MARINE_LITTER_SIZE_CATEGORY.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getVerticalOpeningCaracteristic() { - Integer pmfmId = PmfmId.VERTICAL_OPENING.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getHorizontalOpeningWingsCaracteristic() { - Integer pmfmId = PmfmId.HORIZONTAL_OPENING_WINGS.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getHorizontalOpeningDoorCaracteristic() { - Integer pmfmId = PmfmId.HORIZONTAL_OPENING_DOOR.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getDeadOrAliveCaracteristic() { - Integer pmfmId = PmfmId.DEAD_OR_ALIVE.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getPmfmIdCaracteristic() { - Integer pmfmId = PmfmId.ID_PMFM.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public Caracteristic getWeightMeasuredCaracteristic() { - Integer pmfmId = PmfmId.WEIGHT_MEASURED.getValue(); - Caracteristic result = thisService.getCaracteristic(pmfmId); - return result; - } - - @Override - public boolean isTemporary(TuttiReferentialEntity entity) { - Preconditions.checkNotNull(entity); - Preconditions.checkNotNull(entity.getId()); - Preconditions.checkNotNull(entity.getStatus()); - - boolean tempId; - if (entity instanceof Vessel) { - tempId = entity.getId() != null && entity.getId().startsWith(TemporaryDataHelper.TEMPORARY_NAME_PREFIX); - } else { - tempId = entity.getIdAsInt() != null && entity.getIdAsInt() < 0; - } - - return StatusCode.TEMPORARY.getValue().equals(entity.getStatus().getId()) && tempId; - } - - @Override - public Caracteristic getCaracteristic(Integer pmfmId) { - Object[] source = queryUniqueWithStatus("pmfmById", - "pmfmId", IntegerType.INSTANCE, pmfmId, - "unitIdNone", IntegerType.INSTANCE, UnitId.NONE.getValue()); - Caracteristic target = loadCaracteristic(source); - return target; - } - - @Override - public boolean isVracBatch(SpeciesAbleBatch speciesBatch) { - return batchVracPredicate.apply(speciesBatch); - } - - @Override - public boolean isHorsVracBatch(SpeciesAbleBatch speciesBatch) { - return !batchVracPredicate.apply(speciesBatch); - } - - @Override - public Predicate<SpeciesAbleBatch> getVracBatchPredicate() { - return batchVracPredicate; - } - - @Override - public List<Species> importTemporarySpecies(List<Species> species) { - List<Species> result = Lists.newArrayList(); - for (Species source : species) { - source = importTemporarySpecies(source); - result.add(source); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<Vessel> importTemporaryVessel(List<Vessel> vessels) { - List<Vessel> result = Lists.newArrayList(); - - fr.ifremer.adagio.core.dao.referential.Status status = - statusDao.load(StatusCode.TEMPORARY.getValue()); - Integer countryLocationId = - locationDao.getLocationIdByLabelAndLocationLevel( - LocationLabel.FRANCE.getValue(), - new Integer[]{LocationLevelId.PAYS_ISO3.getValue()}); - if (countryLocationId == null) { - throw new DataIntegrityViolationException("Default country location not found, with label=" + LocationLabel.FRANCE.getValue()); - } - - for (Vessel source : vessels) { - source = importTemporaryVessel(source, countryLocationId, status); - result.add(source); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<Person> importTemporaryPerson(List<Person> persons) { - List<Person> result = Lists.newArrayList(); - - fr.ifremer.adagio.core.dao.referential.Status status = - statusDao.load(StatusCode.TEMPORARY.getValue()); - for (Person source : persons) { - source = importTemporaryPerson(source, status); - result.add(source); - } - return Collections.unmodifiableList(result); - } - - @Override - public List<Gear> importTemporaryGear(List<Gear> gears) { - List<Gear> result = Lists.newArrayList(); - - fr.ifremer.adagio.core.dao.referential.Status status = - statusDao.load(StatusCode.TEMPORARY.getValue()); - for (Gear source : gears) { - source = importTemporaryGear(source, status); - result.add(source); - } - return Collections.unmodifiableList(result); - } - - @Override - public void replaceGear(Gear source, Gear target, boolean delete) { - - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(target); - Preconditions.checkState(isTemporary(source)); - Preconditions.checkState(!isTemporary(target)); - - Integer sourceId = source.getIdAsInt(); - Integer targetId = target.getIdAsInt(); - - queryUpdate("replaceGearInGearPhysicalFeatures", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - queryUpdate("replaceGearInGearUseFeatures", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - //TODO Check doublon... - - if (delete) { - - deleteTemporaryGear(sourceId, false); - - } - - } - - @Override - public void replacePerson(Person source, Person target, boolean delete) { - - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(target); - Preconditions.checkState(isTemporary(source)); - Preconditions.checkState(!isTemporary(target)); - - Integer sourceId = source.getIdAsInt(); - Integer targetId = target.getIdAsInt(); - - queryUpdate("replaceManagerPersonInScientificCruise", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - queryUpdate("replaceRecorderPersonInScientificCruise", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - queryUpdate("replaceRecorderPersonInFishingTrip", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - queryUpdate("replacePersonInVesselPersonFeatures", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - cacheService.clearAllCaches(); - - //TODO Check doublon... - - if (delete) { - - deleteTemporaryPerson(sourceId, false); - - } - - } - - @Override - public void replaceSpecies(Species source, Species target, boolean delete) { - - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(target); - Preconditions.checkState(isTemporary(source)); - Preconditions.checkState(!isTemporary(target)); - - Integer sourceId = source.getReferenceTaxonId(); - Integer targetId = target.getReferenceTaxonId(); - - queryUpdate("replaceReferenceTaxonInSortingBatch", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - queryUpdate("replaceReferenceTaxonInSample", - "sourceId", IntegerType.INSTANCE, sourceId, - "targetId", IntegerType.INSTANCE, targetId); - - //TODO Check doublon... - - if (delete) { - - deleteTemporarySpecies(sourceId, false); - - } - - } - - @Override - public void replaceVessel(Vessel source, Vessel target, boolean delete) { - - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(target); - Preconditions.checkState(isTemporary(source)); - Preconditions.checkState(!isTemporary(target)); - - String sourceId = source.getId(); - String targetId = target.getId(); - - queryUpdate("replaceVesselInCruise", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInFishingOperation", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInOperationVesselAssociation", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInDailyActivityCalendar", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInLanding", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInFishingtrip", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInVesselUseFeatures", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInGearUseFeatures", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - queryUpdate("replaceVesselInGearPhysicalFeatures", - "sourceId", StringType.INSTANCE, sourceId, - "targetId", StringType.INSTANCE, targetId); - - //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 deleteTemporaryGears(Collection<Integer> ids, boolean checkIfUsed) { - for (Integer id : ids) { - deleteTemporaryGear(id, checkIfUsed); - } - } - - @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 exist", id)); - } - - if (checkIfUsed) { - isTemporarySpeciesUsed(id); - } - - taxonNameDao.remove(id); - - } - - @Override - public void deleteTemporarySpecies(Collection<Integer> ids, boolean checkIfUsed) { - for (Integer id : ids) { - deleteTemporarySpecies(id, checkIfUsed); - } - } - - @Override - public void deleteTemporaryPerson(Integer id, boolean checkIfUsed) { - - Preconditions.checkNotNull(id); - if (id > 0) { - throw new ApplicationBusinessException(String.format("Can't delete a Person with a positive id %d.", id)); - } - Person person = getPerson(id); - if (person == null) { - throw new ApplicationBusinessException(String.format("Person with id %d does not exists", id)); - } - personDao.remove(id); - - } - - @Override - public void deleteTemporaryPersons(Collection<Integer> ids, boolean checkIfUsed) { - for (Integer id : ids) { - deleteTemporaryPerson(id, checkIfUsed); - } - } - - @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); - - } - - @Override - public void deleteTemporaryVessels(Collection<String> codes, boolean checkIfUsed) { - for (String code : codes) { - deleteTemporaryVessel(code, checkIfUsed); - } - } - - @Override - public boolean isTemporaryPersonUsed(Integer id) { - Long count = queryUniqueTyped("countManagerPersonInScientificCruise", "id", IntegerType.INSTANCE, id); - boolean result = count > 0; - - if (!result) { - count = queryUniqueTyped("countRecorderPersonInScientificCruise", "id", IntegerType.INSTANCE, id); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countRecorderPersonInFishingTrip", "id", IntegerType.INSTANCE, id); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countPersonInVesselPersonFeatures", "id", IntegerType.INSTANCE, id); - result = count > 0; - } - - return result; - } - - @Override - public boolean isTemporarySpeciesUsed(Integer id) { - Long count = queryUniqueTyped("countReferenceTaxonInSortingBatch", "id", IntegerType.INSTANCE, id); - boolean result = count > 0; - - if (!result) { - count = queryUniqueTyped("countReferenceTaxonInSample", "id", IntegerType.INSTANCE, id); - result = count > 0; - } - return result; - } - - @Override - public boolean isTemporaryGearUsed(Integer id) { - Long count = queryUniqueTyped("countGearInGearPhysicalFeatures", "id", IntegerType.INSTANCE, id); - boolean result = count > 0; - - if (!result) { - count = queryUniqueTyped("countGearInGearUseFeatures", "id", IntegerType.INSTANCE, id); - result = count > 0; - } - return result; - } - - @Override - public boolean isTemporaryVesselUsed(String code) { - Long count = queryUniqueTyped("countVesselInCruise", "id", StringType.INSTANCE, code); - boolean result = count > 0; - - if (!result) { - count = queryUniqueTyped("countVesselInFishingOperation", "id", StringType.INSTANCE, code); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countVesselInOperationVesselAssociation", "id", StringType.INSTANCE, code); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countVesselInDailyActivityCalendar", "id", StringType.INSTANCE, code); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countVesselInLanding", "id", StringType.INSTANCE, code); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countVesselInFishingtrip", "id", StringType.INSTANCE, code); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countVesselInVesselUseFeatures", "id", StringType.INSTANCE, code); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countVesselInGearUseFeatures", "id", StringType.INSTANCE, code); - result = count > 0; - } - - if (!result) { - count = queryUniqueTyped("countVesselInGearPhysicalFeatures", "id", StringType.INSTANCE, code); - result = count > 0; - } - - return result; - } - - //------------------------------------------------------------------------// - //-- Internal methods --// - //------------------------------------------------------------------------// - - public Vessel importTemporaryVessel(Vessel source, Integer registrationLocationId, fr.ifremer.adagio.core.dao.referential.Status status) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getName()); - Preconditions.checkNotNull(source.getInternationalRegistrationCode()); - - Integer vesselTypeId; - if (source.isScientificVessel()) { - vesselTypeId = VesselTypeId.SCIENTIFIC_RESEARCH_VESSEL.getValue(); - } else { - vesselTypeId = VesselTypeId.FISHING_VESSEL.getValue(); - } - - fr.ifremer.adagio.core.dao.data.vessel.Vessel target = - vesselExtendDao.createAsTemporary( - null, - source.getInternationalRegistrationCode(), - registrationLocationId, source.getName(), - vesselTypeId, - false); - - // Fill the result bean - Vessel result = Vessels.newVessel(); - result.setId(target.getCode()); - result.setName(source.getName()); - result.setRegistrationCode(source.getRegistrationCode()); - result.setInternationalRegistrationCode(source.getInternationalRegistrationCode()); - result.setScientificVessel(source.isScientificVessel()); - setStatus(status, result); - return result; - } - - public Person importTemporaryPerson(Person source, fr.ifremer.adagio.core.dao.referential.Status status) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getFirstName()); - Preconditions.checkNotNull(source.getLastName()); - - Person result; - if (source.getId() != null) { - result = getPerson(source.getIdAsInt()); - - } else { - fr.ifremer.adagio.core.dao.administration.user.Person target = - personDao.createAsTemporary(source.getLastName(), source.getFirstName(), - DepartmentId.UNKNOWN_RECORDER_DEPARTMENT.getValue()); - result = Persons.newPerson(); - result.setId(target.getId()); - } - - // Fill the result bean - result.setLastName(source.getLastName()); - result.setFirstName(source.getFirstName()); - setStatus(status, result); - return result; - } - - protected Species importTemporarySpecies(Species source) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getName()); - Preconditions.checkArgument(source.getIdAsInt() == null || source.getIdAsInt() < 0); - - TaxonRefVO taxonRefVO = null; - if (source.getReferenceTaxonId() != null) { - taxonRefVO = taxonNameDao.getTaxonNameReferent(source.getReferenceTaxonId()); - } - if (taxonRefVO == null) { - taxonRefVO = new TaxonRefVO(); - taxonRefVO.setName(source.getName()); - taxonRefVO = taxonNameDao.createAsTemporary( - taxonRefVO, - "Added by tutti (file import)."); - } else { - TaxonName taxonName = load(TaxonNameImpl.class, taxonRefVO.getTaxonNameId()); - taxonName.setName(source.getName()); - taxonRefVO.setName(source.getName()); - taxonNameDao.update(taxonName); - } - - // update the source - Species result = loadSpecies(taxonRefVO); - result.setRefTaxCode(result.getExternalCode()); - - // Add to cache - Cache cache = cacheService.getCache("referentSpeciesById"); - cache.put(result.getIdAsInt(), result); - - return result; - } - - public Gear importTemporaryGear(Gear source, fr.ifremer.adagio.core.dao.referential.Status status) { - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(source.getLabel()); - Preconditions.checkNotNull(source.getName()); - - Integer gearClassificationId; - if (source.isScientificGear()) { - gearClassificationId = GearClassificationId.SCIENTIFIC_CRUISE.getValue(); - } else { - gearClassificationId = GearClassificationId.FAO.getValue(); - } - - Gear result; - if (source.getId() != null) { - result = getGear(source.getIdAsInt()); - - } else { - fr.ifremer.adagio.core.dao.referential.gear.Gear target = fishingGearDao.createAsTemporary(source.getLabel(), source.getName(), gearClassificationId); - result = Gears.newGear(); - result.setId(target.getId()); - } - - // Fill the result bean - result.setLabel(source.getLabel()); - result.setName(source.getName()); - result.setScientificGear(source.isScientificGear()); - setStatus(status, result); - return result; - } - - protected List<TuttiLocation> getFishingOperationLocationsByParent(Integer locationLevelId, Integer parentId, Integer parentLocationLevelId) { - Iterator<Object[]> sources = queryListWithStatus( - "allFishingOperationLocationByParent", - "parentId", IntegerType.INSTANCE, parentId, - "parentLocationLevelId", IntegerType.INSTANCE, parentLocationLevelId, - "locationClassificationId", IntegerType.INSTANCE, LocationClassificationId.SECTOR.getValue(), - "locationLevelId", IntegerType.INSTANCE, locationLevelId - ); - List<TuttiLocation> result = Lists.newArrayList(); - while (sources.hasNext()) { - Object[] source = sources.next(); - TuttiLocation target = loadLocation(source); - result.add(target); - } - return result; - } - - protected Caracteristic loadCaracteristic(Object[] source) { - - Integer pmfmId = (Integer) source[0]; - - Caracteristic result = Caracteristics.newCaracteristic(); - result.setId(pmfmId); - result.setParameterName((String) source[1]); - result.setMatrixName((String) source[2]); - result.setFractionName((String) source[3]); - result.setMethodName((String) source[4]); - CaracteristicType type = Caracteristics.getType((Boolean) source[5], - (Boolean) source[6]); - result.setCaracteristicType(type); - result.setNumericType(Caracteristics.isNumberCaracteristic(result)); - - result.setSignifFiguresNumber((Integer) source[7]); - result.setMaximumNumberDecimals((Integer) source[8]); - result.setPrecision((Float) source[9]); - result.setUnit((String) source[10]); - setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[11], result); - - if (Caracteristics.isQualitativeCaracteristic(result)) { - - // load qualitative values - - Iterator<Object[]> sources = queryListWithStatus( - "pmfmQualitativeValues", - "pmfmId", IntegerType.INSTANCE, pmfmId); - - List<CaracteristicQualitativeValue> values = Lists.newArrayList(); - while (sources.hasNext()) { - Object[] source2 = sources.next(); - CaracteristicQualitativeValue target2 = CaracteristicQualitativeValues.newCaracteristicQualitativeValue(); - target2.setId(String.valueOf(source2[0])); - target2.setName(String.valueOf(source2[1])); - target2.setDescription(String.valueOf(source2[2])); - setStatus((fr.ifremer.adagio.core.dao.referential.Status) source2[3], target2); - values.add(target2); - } - result.setQualitativeValue(Collections.unmodifiableList(values)); - } - return result; - } - - protected ObjectType loadObjectType(Object[] source) { - ObjectType result = ObjectTypes.newObjectType(); - result.setId((String) source[0]); - result.setName((String) source[1]); - result.setDescription((String) source[2]); - return result; - } - - protected Species loadSpecies(TaxonRefVO source) { - Species target = Speciess.newSpecies(); - target.setId(source.getTaxonNameId()); - target.setName(source.getName()); - target.setExternalCode(source.getExternalCode()); - target.setReferenceTaxonId(source.getReferenceTaxonId()); - target.setReferenceTaxon(source.getIsReference()); - fr.ifremer.adagio.core.dao.referential.Status status = statusDao.load(source.getStatus().getValue()); - setStatus(status, target); - return target; - } - - protected Vessel loadVessel(Object[] source, boolean scientificVessel) { - Vessel target = Vessels.newVessel(); - target.setId((String) source[0]); - target.setRegistrationCode((String) source[1]); - target.setInternationalRegistrationCode((String) source[2]); - target.setName((String) source[3]); - target.setScientificVessel(scientificVessel); - setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[4], target); - return target; - } - - protected Person loadPerson(Object[] source) { - Person target = Persons.newPerson(); - target.setId(String.valueOf(source[0])); - target.setLastName((String) source[1]); - target.setFirstName((String) source[2]); - target.setDepartment((String) source[3]); - setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[4], target); - return target; - } - - protected Gear loadGear(Object[] source) { - Gear result = Gears.newGear(); - result.setId(String.valueOf(source[0])); - result.setLabel((String) source[1]); - result.setName((String) source[2]); - GearClassification classification = (GearClassification) source[3]; - boolean scientific = false; - if (classification != null) { - scientific = classification.getId().equals(GearClassificationId.SCIENTIFIC_CRUISE.getValue()); - } - result.setScientificGear(scientific); - - setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[4], result); - return result; - } - - protected TuttiLocation loadLocation(Object[] source) { - TuttiLocation target = TuttiLocations.newTuttiLocation(); - target.setId((Integer) source[0]); - target.setLabel((String) source[1]); - target.setName((String) source[2]); - setStatus((fr.ifremer.adagio.core.dao.referential.Status) source[3], target); - return target; - } - - protected Iterator<Object[]> queryListWithStatus(String queryName, - Object... params) { - Query query = createQuery(queryName, params); - query.setString("statusValidCode", StatusCode.ENABLE.getValue()); - query.setString("statusTemporaryCode", StatusCode.TEMPORARY.getValue()); - - Iterator<Object[]> result = query.iterate(); - return result; - } - - protected Object[] queryUniqueWithStatus(String queryName, Object... params) { - - Query query = createQuery(queryName, params); - query.setString("statusValidCode", StatusCode.ENABLE.getValue()); - query.setString("statusTemporaryCode", StatusCode.TEMPORARY.getValue()); - - Object result = query.uniqueResult(); - return (Object[]) result; - } - - protected <E extends TuttiReferentialEntity> void setStatus(fr.ifremer.adagio.core.dao.referential.Status status, E entity) { - Status newStatus = Statuss.newStatus(); - newStatus.setId(status.getCode()); - newStatus.setName(status.getName()); - entity.setStatus(newStatus); - } -} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7909_import_generique_id_obsoletes in repository tutti. See http://git.codelutin.com/tutti.git commit fa6349e9037578b41cb222d3714e234c0b824fdd Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Jan 17 18:36:09 2016 +0100 Correction de la requete pour récupérer les navires obsolètes --- tutti-persistence/src/main/resources/queries-failsafe.hbm.xml | 1 - .../src/test/resources/genericFormat/withObsoletes/operation.csv | 2 +- tutti-service/src/test/resources/genericFormat/withObsoletes/survey.csv | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml b/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml index e666615..0a16a0a 100644 --- a/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml +++ b/tutti-persistence/src/main/resources/queries-failsafe.hbm.xml @@ -1344,7 +1344,6 @@ AND v.status.code IN (:statusValidCode, :statusTemporaryCode, :statusDisableCode) AND vrp.vesselRegistrationPeriodPk.startDateTime <= :refDate AND vf.startDateTime <= :refDate - AND coalesce(vf.endDateTime, :refDate) >= :refDate ORDER BY v.code, vf.startDateTime, vrp.vesselRegistrationPeriodPk.startDateTime ]]> <!-- FIXME le navire n'a plus de période ouverte de registre AND coalesce(vrp.endDateTime, :refDate) >= :refDate --> diff --git a/tutti-service/src/test/resources/genericFormat/withObsoletes/operation.csv b/tutti-service/src/test/resources/genericFormat/withObsoletes/operation.csv index 349dc91..8f521ca 100644 --- a/tutti-service/src/test/resources/genericFormat/withObsoletes/operation.csv +++ b/tutti-service/src/test/resources/genericFormat/withObsoletes/operation.csv @@ -1,2 +1,2 @@ Annee;Serie;Serie_Partielle;Code_Station;Id_Operation;Poche;Engin;Rang_Engin;Navire;DateDeb;LatDeb;LongDeb;DateFin;LatFin;LongFin;Duree;Strate;Sous_Strate;Localite;Validite_OP;Rectiligne;Distance;Saisisseur;Navire_Associe;Commentaire;Poids_Total;Poids_Total_Calcule;Poids_Total_Vrac;Poids_Total_Vrac_Calcule;Poids_Total_HorsVrac;Poids_Total_HorsVrac_Calcule;Poids_Total_Non_Trie;Poids_Total_Non_Trie_Calcule;Poids_Total_Tremis;Poids_Total_Tremis_Calcule;Poids_Total_Carroussel;Poids_Total_Car [...] -2015;Campagne EVHOE;1;A;1;1;GOV 36/47;1;868095;27/11/2013 00:00:00;12.0;23.0;27/11/2013 01:00:00;12.0;23.1;60;Strate Cc4;NA;NA;Y;Y;10888;Angelique JADAUD;278970;;582.107;Y;150.1;Y;432.007;Y;0.0;Y;1412.1;N;150.0;N;582.0;Y;-9.0;?;150.0;Y;432.0;Y;0.0;Y;-9.0;?;0.107;Y;0.1;Y;0.1;Y;0.007;Y;0.0;Y;0.0;Y;3.0;Y;CAM-EVHOE;379;100158;136495;868095;63353;;;2158;278970 \ No newline at end of file +2015;Campagne EVHOE;1;A;1;1;GOV 36/47;1;868095;27/11/2013 00:00:00;12.0;23.0;27/11/2013 01:00:00;12.0;23.1;60;Strate Cc4;NA;NA;Y;Y;10888;Angelique JADAUD;278970;;582.107;Y;150.1;Y;432.007;Y;0.0;Y;1412.1;N;150.0;N;582.0;Y;-9.0;?;150.0;Y;432.0;Y;0.0;Y;-9.0;?;0.107;Y;0.1;Y;0.1;Y;0.007;Y;0.0;Y;0.0;Y;3.0;Y;CAM-EVHOE;379;100158;136495;868095;63353;;;2158;278970|267465 \ No newline at end of file diff --git a/tutti-service/src/test/resources/genericFormat/withObsoletes/survey.csv b/tutti-service/src/test/resources/genericFormat/withObsoletes/survey.csv index 9883e35..aefcc8b 100644 --- a/tutti-service/src/test/resources/genericFormat/withObsoletes/survey.csv +++ b/tutti-service/src/test/resources/genericFormat/withObsoletes/survey.csv @@ -1,2 +1,2 @@ Annee;Serie;Serie_Partielle;Navire;Nombre_Poches;Pays;Zone_Etude;Campagne;Id_Sismer;Date_Deb_Campagne;Port_Deb_Campagne;Date_Fin_Campagne;Port_Fin_Campagne;Chef_Mission;Resp_Salle_Tri;Commentaire;Serie_Id;Campagne_Id;Navire_Id;Engin_Id;Port_Deb_Campagne_Id;Port_Fin_Campagne_Id;Chef_Mission_Id;Resp_Salle_Tri_Id -2015;Campagne EVHOE;1;868095;1;FRA;EVHOE - Golfe de Gascogne / Mer Celtique;EVHOE 2015;;17/10/2015 07:00:00;Brest;30/11/2015 20:00:00;Brest;Jean Claude MAHE|Jean-Pierre LEAUTE|Lionel PAWLOWSKI;Erwan DUHAMEL|Francois GARREN|Ludovic BOUCHE;;CAM-EVHOE;100000;267465;379|67|22;515;530;133;128 +2015;Campagne EVHOE;1;868095;1;FRA;EVHOE - Golfe de Gascogne / Mer Celtique;EVHOE 2015;;17/10/2015 07:00:00;Brest;30/11/2015 20:00:00;Brest;Jean Claude MAHE|Jean-Pierre LEAUTE|Lionel PAWLOWSKI;Erwan DUHAMEL|Francois GARREN|Ludovic BOUCHE;;CAM-EVHOE;100000;1003931;379|67|22;515;530;133;128 -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm