This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 52294bf63f828a5df4ed01ea88d3c4d6ed2df7a6 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun May 3 17:21:07 2015 +0200 - suppression de tout code utilisant des transaction du module swing (refs #7017) --- .../src/main/java/fr/ird/observe/DataService.java | 2483 -------------------- .../java/fr/ird/observe/db/DataServiceTest.java | 339 --- .../referentiel/LengthWeightParameterDAOImpl.java | 4 + .../observe/entities/referentiel/SexDAOImpl.java | 7 + .../ird/observe/services/ReplicationService.java | 11 + .../observe/services/ReplicationServiceImpl.java | 11 + .../services/operation/ComputeDataService.java | 18 + .../services/operation/ComputeDataServiceImpl.java | 479 ++-- .../services/operation/GpsImportService.java | 11 + .../services/operation/GpsImportServiceImpl.java | 11 + .../operation/ObsoleteReferenceToReplace.java | 111 + .../services/operation/SynchronizeService.java | 11 + .../services/operation/SynchronizeServiceImpl.java | 11 + .../services/operation/ValidationService.java | 18 + .../services/operation/ValidationServiceImpl.java | 94 + 15 files changed, 540 insertions(+), 3079 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/DataService.java b/observe-business/src/main/java/fr/ird/observe/DataService.java deleted file mode 100644 index aee4dc3..0000000 --- a/observe-business/src/main/java/fr/ird/observe/DataService.java +++ /dev/null @@ -1,2483 +0,0 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; -import fr.ird.observe.db.constants.DataSourceState; -import fr.ird.observe.db.util.TopiaExecutor; -import fr.ird.observe.db.util.TopiaExecutor2; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.LengthWeightParameter; -import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; -import fr.ird.observe.entities.referentiel.Ocean; -import fr.ird.observe.entities.referentiel.ReferenceEntities; -import fr.ird.observe.entities.referentiel.Sex; -import fr.ird.observe.entities.referentiel.Species; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.event.TopiaTransactionEvent; -import org.nuiton.topia.event.TopiaTransactionListener; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.DiffState; -import org.nuiton.topia.persistence.util.EntityOperator; -import org.nuiton.topia.persistence.util.Loador; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeListenerProxy; -import java.beans.PropertyChangeSupport; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.List; - -import static org.nuiton.i18n.I18n.t; - -/** - * Le contrat du service de données. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class DataService { - - /** Logger */ - private static final Log log = LogFactory.getLog(DataService.class); - - String PARENT_BEAN = "parentBean"; - - String BEAN = "bean"; - - protected DecoratorService decoratorService; - - protected DataContext dataContext; - - protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - -// private boolean skipTransactionListener; - - private TopiaTransactionListener transactionListener = new TopiaTransactionListener() { - - public void commit(TopiaTransactionEvent event) { - -// if (skipTransactionListener) { -// return; -// } - - java.util.Set<TopiaEntity> entities = event.getEntities(); - - // pour recenser les referentiels modifies - EnumSet<ObserveEntityEnum> referentiel = - EnumSet.noneOf(ObserveEntityEnum.class); - - // pour referencer les types openables modifies -// boolean touchOpenContext = false; - - // pour referencer les donnees observers modifiees - java.util.Set<TopiaEntity> data = new HashSet<TopiaEntity>(); - - for (TopiaEntity entity : entities) { - if (log.isDebugEnabled()) { - if (event.isLoad(entity)) { - - if (log.isDebugEnabled()) { - log.debug("loaded entity [" + entity.getTopiaId() + "]"); - } - } else if (event.isCreate(entity)) { - if (log.isInfoEnabled()) { - log.info("created entitiy [" + entity.getTopiaId() + "]"); - } - - } else if (event.isUpdate(entity)) { - if (log.isDebugEnabled()) { - log.debug("updated entitiy [" + entity.getTopiaId() + "]"); - } - - } else if (event.isDelete(entity)) { - if (log.isDebugEnabled()) { - log.debug("deleted entitiy [" + entity.getTopiaId() + "]"); - } - } - } - - if (!event.isModification(entity)) { - - // pas de modification, on ne fait rien - continue; - } - - // l'entite a ete modifiee, cree ou supprimee - ObserveEntityEnum constant = - ObserveEntityEnum.valueOf(entity); - - if (constant == null) { - - // non gere (peut-etre une entite technique) - continue; - } - - if (Entities.isReferentielClass(constant)) { - - // c'est un objet du référentiel - referentiel.add(constant); - continue; - } - - // il s'agit d'une donnée utilisateur - data.add(entity); - -// if (OpenableEntities.isOpenable(entity)) { -// touchOpenContext = true; -// } - } - - DataSource source = ObserveServiceHelper.get().getDataSource(); - if (source == null) { - throw new IllegalStateException("No source service registred."); - } - source.checkState(DataSourceState.OPEN); - - if (!referentiel.isEmpty()) { - - // notification de modification de reférentiels - fireReferentielChanged( - source, - referentiel.toArray( - new ObserveEntityEnum[referentiel.size()]) - ); - } - - if (!data.isEmpty()) { - - // notification de modification de reférentiels - fireDataChanged(source, - data.toArray(new TopiaEntity[data.size()]) - ); - } - -// if (touchOpenContext) { -// fireOpenChanged(source); -// } - } - - public void rollback(TopiaTransactionEvent event) { - } - }; - -// protected PropertyChangeListener openListener = new PropertyChangeListener() { -// -// public void propertyChange(PropertyChangeEvent evt) { -// DataService source = (DataService) evt.getSource(); -// DataContext dataContext = source.getDataContext(); -// String[] value = (String[]) evt.getNewValue(); -// if (log.isDebugEnabled()) { -// log.debug("open context changed in data service, will propagate it to " + dataContext); -// log.debug("new open ids : " + Arrays.toString(value)); -// } -// dataContext.populateOpens(value); -// } -// }; - - - public void registerDataSource(DataSource source) { - - ObserveServiceHelper.get().setDataSource(source); - -// addPropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); - } - - - public void unregisterDataSource(DataSource source) { - - ObserveServiceHelper.get().setDataSource(null); - -// removePropertyChangeListener(DataSource.OPEN_PROPERTY_KEY, openListener); - - // remove all listeners for the referentiel - //FIXMe tchemit 2010-11-30 Perharps we should remove all listeners ? - removeReferentielPropertyChangeListeners(); - } - - - public DecoratorService getDecoratorService() { - if (decoratorService == null) { - decoratorService = ObserveServiceHelper.getDecoratorService(); - } - return decoratorService; - } - - - public DataContext getDataContext() { - if (dataContext == null) { - dataContext = ObserveServiceHelper.getDataContext(); - } - return dataContext; - } - - // ------------------------------------------------------------------------ - // -- Méthodes de gestion des transactions - // ------------------------------------------------------------------------ - - - public TopiaContext beginTransaction(DataSource source, - String methodName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - if (log.isDebugEnabled()) { - log.debug("begin tx " + methodName); - } - TopiaContext tx = source.beginTransaction(methodName); - tx.addTopiaTransactionListener(transactionListener); - if (log.isDebugEnabled()) { - log.debug("after begin tx " + methodName); - } - return tx; - } - - - public void rollbackTransaction(DataSource source, - TopiaContext tx, - String txName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - source.rollbackTransaction(tx, txName); - } - - - public void commitTransaction(DataSource source, - TopiaContext tx, - String txName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - if (log.isDebugEnabled()) { - log.debug("commit tx " + txName); - } - source.commitTransaction(tx, txName); - if (log.isDebugEnabled()) { - log.debug("after commit tx " + txName); - } - } - - - public void closeTransaction(DataSource source, - TopiaContext tx, - String txName) throws DataSourceException { - source.checkState(DataSourceState.OPEN); - if (log.isDebugEnabled()) { - log.debug("close tx " + txName); - } - tx.removeTopiaTransactionListener(transactionListener); - source.closeTransaction(tx, txName); - if (log.isDebugEnabled()) { - log.debug("after close tx " + txName); - } - } - - // ------------------------------------------------------------------------ - // -- Méthodes métiers de récupération de données - // ------------------------------------------------------------------------ - - -// public String[] getOpenIds(DataSource source) throws DataSourceException { -// -// String[] result = null; -// TopiaContext tx = beginTransaction(source, "getOpenIds"); -// try { -// -// result = source.getOpenIds(tx); -// } finally { -// closeTransaction(source, tx, "getOpenIds"); -// } -// return result; -// } - - - public <E extends TopiaEntity> List<E> getList(DataSource source, Class<E> klass) throws DataSourceException { - - List<E> list = getList(source, klass, null, null); - return list; - } - -// public <E extends TopiaEntity> List<E> getList(DataSource source, Class<E> klass, Predicate<E> predicate) throws DataSourceException { -// List<E> result = getList(source, klass, predicate, null); -// return result; -// } - - - public <E extends TopiaEntity> List<E> getList(DataSource source, - Class<E> klass, - TopiaEntityBinder<E> loador) throws DataSourceException { - List<E> result = getList(source, klass, null, loador); - return result; - } - - - public <E extends TopiaEntity> List<E> getList(DataSource source, - Class<E> klass, - Predicate<E> predicate, - TopiaEntityBinder<E> loador) throws DataSourceException { - if (Entities.isDataClass(klass)) { - // on verifie que l'on a le droit de lire la donnee - if (!source.canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data, no read credential"); - } - return new ArrayList<E>(); - } - } - - if (Entities.isReferentielClass(klass)) { - // on verifie que l'on a le droit de lire la donnee - if (!source.canReadReferentiel()) { - if (log.isDebugEnabled()) { - log.debug("Can not read referentiel, no read credential"); - } - return new ArrayList<E>(); - } - } - - List<E> result; - try { - - result = getList0(source, klass, predicate, loador); - - //TC-20100208 : on peut modifier la liste (pour supprimer par - // exemple les entites non active), on doit donc toujours travailler - // sur une copie de la liste - return new ArrayList<E>(result); - } catch (Exception e) { - throw new DataSourceException(e, "getList"); - } - } - -// public <E extends TopiaEntity> EntityMap findAllUsages(DataSource source, -// E entity) throws DataSourceException { -// -// String txName = "findAllUsages"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<E> dao; -// dao = source.getDAO(tx, entity); -// -// // always get a fresh version of object -// entity = dao.findByTopiaId(entity.getTopiaId()); -// EntityMap result; -// result = new EntityMap(dao.findAllUsages(entity)); -// if (decoratorService != null) { -// // on charge les entites -// for (Class<? extends TopiaEntity> aClass : result.keySet()) { -// Decorator<? extends TopiaEntity> decorator = -// decoratorService.getDecoratorByType(aClass); -// for (TopiaEntity e : result.get(aClass)) { -// decorator.toString(e); -// } -// } -// } -// return result; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - -// public <E extends OpenableEntity & TopiaEntity> E getOpen(DataSource source, -// Class<E> klass) throws DataSourceException { -// -// if (!source.canReadData()) { -// if (log.isInfoEnabled()) { -// log.info("Can not read data!"); -// } -// return null; -// } -// String txName = "getOpen"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// E result = source.getOpen(tx, klass); -// if (result != null && klass.equals(TripSeine.class)) { -// ((TripSeine) result).getProgram(); -// } -// return result; -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Program> getAllProgramStub(DataSource source) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getAllProgramStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<Program> result = dao.findAllStub(referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public Program getProgramStub(DataSource source, String programId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getProgramStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// Program result = dao.findStubByTopiaId(programId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<TripSeine> getTripSeineStubByProgram(DataSource source, String programId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getTripSeineStubByProgram"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<TripSeine> result = dao.findAllStubByProgramId(programId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public TripSeine getTripSeineStub(DataSource source, String tripId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getTripSeineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// TripSeine result = dao.findStubByTopiaId(tripId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - -// public List<Route> getRouteStubByTrip(DataSource source, String tripSeineId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getRouteStubByTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); -// List<Route> result = dao.findAllStubByTripId(tripSeineId); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public Route getRouteStub(DataSource source, String routeId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getRouteStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// RouteDAO dao = (RouteDAO) source.getDAO(tx, Route.class); -// Route result = dao.findStubByTopiaId(routeId); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<ActivitySeine> getActivitySeineStubByRoute(DataSource source, String routeId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getActivitySeineStubByRoute"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<ActivitySeine> result = dao.findAllStubByRouteId(routeId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public ActivitySeine getActivitySeineStub(DataSource source, String activityId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getActivitySeineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivitySeineDAO dao = (ActivitySeineDAO) source.getDAO(tx, ActivitySeine.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// ActivitySeine result = dao.findStubByTopiaId(activityId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<FloatingObject> getFloatinObjectStubByActivitySeine(DataSource source, String activitySeineId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getFloatinObjectStubByActivitySeine"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<FloatingObject> result = dao.findAllStubByActivityId(activitySeineId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public FloatingObject getFloatinObjectStub(DataSource source, String floatingObjectId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getFloatinObjectStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// FloatingObjectDAO dao = (FloatingObjectDAO) source.getDAO(tx, FloatingObject.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// FloatingObject result = dao.findStubByTopiaId(floatingObjectId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<TripLongline> getTripLonglineStubByProgram(DataSource source, String programId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getTripLonglineStubByProgram"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<TripLongline> result = dao.findAllStubByProgramId(programId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public TripLongline getTripLonglineStub(DataSource source, String tripId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getTripLonglineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// TripLongline result = dao.findStubByTopiaId(tripId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public List<ActivityLongline> getActivityLonglineStubByTrip(DataSource source, String tripId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return Collections.emptyList(); -// } -// -// String txName = "getActivityLonglineStubByTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// List<ActivityLongline> result = dao.findAllStubByTripId(tripId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public ActivityLongline getActivityLonglineStub(DataSource source, String activityId) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "getActivityLonglineStub"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// ActivityLonglineDAO dao = (ActivityLonglineDAO) source.getDAO(tx, ActivityLongline.class); -// ReferenceLocale referentielLocale = getDecoratorService().getReferentielLocale(); -// ActivityLongline result = dao.findStubByTopiaId(activityId, referentielLocale); -// return result; -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public Ocean getTripOcean(DataSource source, String tripId) throws DataSourceException { -// -// String txName = "getTripOcean"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// TripSeine result = dao.findByTopiaId(tripId); -// return result.getOcean(); -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - /** - * Recherche d'un {@link LengthWeightParameter} à partir des paramètres donnés. - * <p/> - * La recherche peut ne peut être aussi exacte que les paramètres donnés : - * <p/> - * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son - * speciesGroup d'espèce. - * <p/> - * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on - * recherche avec un ocean vide. - * <p/> - * Si non trouvé sur le gender (et que le gender n'est pas indéterminé) , alors - * on recherche avec le gender indéterminé (gender=0). - * - * @param tx la transaction en cours d'utilisation - * @param species l'espèce sur lequel on recherche le paramétrage - * @param ocean l'ocean recherché (peut être null) - * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) - * @param date le jour recherché - * @return le paramétrage adéquate - * @throws DataSourceException pour toute erreur - * @since 1.5 - */ - public <P extends LengthWeightParameter> P findLengthWeightParameter( - TopiaContext tx, - Species species, - Ocean ocean, - Sex sex, - Date date) throws DataSourceException { - - try { - - List<P> list = LengthWeightParemeterHelper.findBySpecies( - (TopiaContextImplementor) tx, - species - ); - - if (CollectionUtils.isEmpty(list)) { - - // aucun parametrage pour le type donne - return null; - } - - // filtrage par ocean - list = LengthWeightParemeterHelper.filterByOcean(list, ocean); - - if (CollectionUtils.isEmpty(list) && ocean != null) { - - // filtre par ocean null - list = LengthWeightParemeterHelper.filterByOcean(list, null); - } - - if (CollectionUtils.isEmpty(list)) { - - // pas d'ocean adequate - return null; - } - - // filtrage par sexe - list = LengthWeightParemeterHelper.filterBySexe(list, sex); - - if (CollectionUtils.isEmpty(list)) { - - Sex unkwonSex = ObserveDAOHelper.getSexDAO(tx).findByCode("0"); - - if (unkwonSex.equals(sex)) { - - // filtrage par sexe indetermine - list = LengthWeightParemeterHelper.filterBySexe(list, unkwonSex); - } - - - } - - if (CollectionUtils.isEmpty(list)) { - - // pas de sexe adequate - return null; - } - - // filtrage par startDate de validite - list = LengthWeightParemeterHelper.filterByDateDebutValidite(list, - date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de debut adequate - return null; - } - - // filtrage par endDate de validite - list = LengthWeightParemeterHelper.filterByDateFinValidite(list, - date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de fin adequate - return null; - } - - // au final il ne devrait en rester qu'un - - if (list.size() > 1) { - StringBuilder sb = new StringBuilder("Il existe plusieurs paramétrages possibles pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(getDecoratorService().decorate(species)); - sb.append("\nOcean : "); - sb.append(getDecoratorService().decorate(ocean)); - sb.append("\nSex : "); - sb.append(getDecoratorService().decorate(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrages trouvés : "); - for (P p : list) { - sb.append("\n - ").append(getDecoratorService().decorate(p)); - } - throw new DataSourceException(sb.toString(), "findLengthWeightParameter"); - } - - P result = list.get(0); - if (log.isDebugEnabled()) { - StringBuilder sb = new StringBuilder("Paramétrage trouvé pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(getDecoratorService().decorate(species)); - sb.append("\nOcean : "); - sb.append(getDecoratorService().decorate(ocean)); - sb.append("\nSex : "); - sb.append(getDecoratorService().decorate(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrage: ").append(getDecoratorService().decorate(result)); - log.debug(sb.toString()); - } - return result; - - } catch (Exception e) { - throw new DataSourceException(e, "findLengthWeightParameter"); - } - } - -// protected Sex getUnknownSex(TopiaContext tx) throws TopiaException { -// return ObserveDAOHelper.getSexDAO(tx).findByCode("0"); -// } - -// public int getOpenablePosition(DataSource source, -// String containerId, -// String childId) throws DataSourceException { -// if (childId.startsWith(TripSeine.class.getName())) { -// return getTripSeinePosition(source, containerId, childId); -// } -// if (childId.startsWith(TripLongline.class.getName())) { -// return getTripLonglinePosition(source, containerId, childId); -// } -// if (childId.startsWith(Route.class.getName())) { -// return getRoutePosition(source, containerId, childId); -// } -// if (childId.startsWith(ActivitySeine.class.getName())) { -// return getActivitySeinePosition(source, containerId, childId); -// } -// if (childId.startsWith(ActivityLongline.class.getName())) { -// return getActivityLonglinePosition(source, containerId, childId); -// } -// throw new IllegalStateException("Can not come here!"); -// } - -// protected int getTripSeinePosition(DataSource source, -// String programId, -// String tripId) throws DataSourceException { -// -// String txName = "getTripSeinePosition [" + tripId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// int pos = dao.findPositionByProgramId(programId, tripId); -// return pos; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getTripLonglinePosition(DataSource source, -// String programId, -// String tripId) throws DataSourceException { -// -// String txName = "getTripLonglinePosition [" + tripId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// int pos = dao.findPositionByProgramId(programId, tripId); -// return pos; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getRoutePosition(DataSource source, -// String tripId, -// String routeId) throws DataSourceException { -// -// String txName = "getRoutePosition [" + tripId + "/" + routeId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripSeine maree = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); -// Route route = maree.getRouteByTopiaId(routeId); -// List<Route> routes = maree.getRoute(); -// Routes.sort(routes); -// return routes.indexOf(route); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getActivitySeinePosition(DataSource source, -// String routeId, -// String activityId) throws DataSourceException { -// -// String txName = "getActivitySeinePosition [" + routeId + "/" + activityId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// Route route = source.getDAO(tx, Route.class).findByTopiaId(routeId); -// ActivitySeine activitySeine = route.getActivitySeineByTopiaId(activityId); -// List<ActivitySeine> activitySeines = route.getActivitySeine(); -// ActivitySeines.sort(activitySeines); -// return activitySeines.indexOf(activitySeine); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// protected int getActivityLonglinePosition(DataSource source, -// String tripId, -// String activityId) throws DataSourceException { -// -// String txName = "getActivityLonglinePosition [" + tripId + "/" + activityId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TripLongline trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); -// ActivityLongline activity = trip.getActivityLonglineByTopiaId(activityId); -// List<ActivityLongline> activities = trip.getActivityLongline(); -// ActivityLonglines.sort(activities); -// return activities.indexOf(activity); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public String getTargetSampleId(DataSource source, -// String setId, -// boolean discarded) throws DataSourceException { -// -// String txName = "getTargetSampleId [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// List<TargetSample> list = set.getTargetSample(); -// if (list == null || list.isEmpty()) { -// return null; -// } -// for (TargetSample targetSample : list) { -// if (discarded) { -// if (targetSample.getDiscarded() != null && -// targetSample.getDiscarded()) { -// return targetSample.getTopiaId(); -// } -// } else if (targetSample.getDiscarded() == null || -// !targetSample.getDiscarded()) { -// return targetSample.getTopiaId(); -// } -// } -// return null; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public String getNonTargetSampleId(DataSource source, -// String setId) throws DataSourceException { -// -// String txName = "getNonTargetSampleId [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// List<NonTargetSample> list = set.getNonTargetSample(); -// if (list == null || list.isEmpty()) { -// return null; -// } -// return list.get(0).getTopiaId(); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Species> getAvailableEspeceForTargetSample(DataSource source, -// String setId, -// boolean discarded) throws DataSourceException { -// -// String txName = "getAvailableEspeceForTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// List<Species> speciess = new ArrayList<Species>(); -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// // on recupere la liste des species thon utilisees dans le rejet -// Collection<TargetCatch> discardeds = set.getTargetCatch(); -// -// // on filtre sur les speciess monté sur le pont et rejetée -// -// if (discardeds != null) { -// for (TargetCatch discardedt : discardeds) { -// boolean keep; -// -// if (discarded) { -// -// // on ne conserve que les speciess des discardeds montees sur le pont et discardedes -// keep = discardedt.isDiscarded() && discardedt.getBroughtOnDeck(); -// -// } else { -// -// // on ne conserve que les species des discardeds -// keep = !discardedt.isDiscarded(); -// } -// -// if (keep && -// !speciess.contains(discardedt.getWeightCategory().getSpecies())) { -// speciess.add(discardedt.getWeightCategory().getSpecies()); -// } -// } -// } -// return speciess; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Species> getAvailableEspeceForNonTargetSample(DataSource source, -// String setId) throws DataSourceException { -// -// String txName = "getAvailableEspeceForNonTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// List<Species> speciess = new ArrayList<Species>(); -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// // on recupere la liste des species faune utilisees dans le rejet -// Collection<NonTargetCatch> discardeds = set.getNonTargetCatch(); -// -// if (discardeds != null) { -// for (NonTargetCatch discarded : discardeds) { -// // on retient toute les speciess (capturées ou rejetées) -// if (!speciess.contains(discarded.getSpecies())) { -// speciess.add(discarded.getSpecies()); -// } -// } -// } -// -// return speciess; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Section> getSections(DataSource source, String setLonglineId) throws DataSourceException { -// String txName = "getSections [" + setLonglineId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<Section> dao = source.getDAO(tx, Section.class); -// -// List<Section> sections = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); -// -// if (!sections.isEmpty()) { -// -// Decorator<Section> sectionDecorator = getDecoratorService().getDecoratorByType(Section.class); -// Decorator<Basket> basketDecorator = getDecoratorService().getDecoratorByType(Basket.class); -// Decorator<Branchline> branchlineDecorator = getDecoratorService().getDecoratorByType(Branchline.class); -// -// for (Section section : sections) { -// -// sectionDecorator.toString(section); -// -// if (!section.isBasketEmpty()) { -// -// for (Basket basket : section.getBasket()) { -// -// basketDecorator.toString(basket); -// -// if (!basket.isBranchlineEmpty()) { -// -// for (Branchline branchline : basket.getBranchline()) { -// -// branchlineDecorator.toString(branchline); -// -// } -// } -// -// } -// } -// } -// } -// -// return sections; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public List<Species> loadDecoratedSpecies(DataSource source, String speciesListCode) throws DataSourceException { -// String txName = "loadDecoratedSpecies [" + speciesListCode + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// List<Species> speciess = new ArrayList<Species>(); -// -// SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); -// SpeciesList speciesList = dao.findByTopiaId(speciesListCode); -// -// speciess.addAll(speciesList.getSpecies()); -// -// Decorator<Species> decorator = getDecoratorService().getDecoratorByType(Species.class); -// -// for (Species species : speciess) { -// decorator.toString(species); -// } -// -// return speciess; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - -// public java.util.Set<String> getSpeciesListSpeciesIds(DataSource source, String speciesListId) throws DataSourceException { -// String txName = "getSpeciesListSpeciesIds [" + speciesListId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// -// SpeciesListDAO dao = (SpeciesListDAO) source.getDAO(tx, SpeciesList.class); -// SpeciesList speciesList = dao.findByTopiaId(speciesListId); -// -// java.util.Set<String> ids = -// Sets.newHashSet( -// TopiaEntityHelper.getTopiaIdList( -// speciesList.getSpecies())); -// -// return ids; -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public boolean canUseNonTargetSample(DataSource source, -// String setId) throws DataSourceException { -// -// String txName = "canUseNonTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// return set.canUseNonTargetSample(); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public boolean canUseTargetSample(DataSource source, -// String setId, -// boolean discarded) throws DataSourceException { -// -// String txName = "canUseTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// return set.canUseTargetSample(discarded); -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public void getObsoleteEspeceForNonTargetSample(DataSource source, -// String setId, -// List<Species> speciessUsed, -// Collection<Species> speciessToDelete, -// List<NonTargetLength> tailleToDelete) throws DataSourceException { -// -// String txName = "getObsoleteEspeceForNonTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// -// if (set.isNonTargetSampleEmpty()) { -// return; -// } -// -// NonTargetSample echantillon = set.getNonTargetSample().get(0); -// -// if (echantillon.isNonTargetLengthEmpty()) { -// return; -// } -// -// for (NonTargetLength taille : echantillon.getNonTargetLength()) { -// Species tailleEspece = taille.getSpecies(); -// if (!speciessUsed.contains(tailleEspece)) { -// // l'species n'existe plus dans les rejet faune, -// // on doit le supprimer -// tailleToDelete.add(taille); -// speciessToDelete.add(tailleEspece); -// if (log.isDebugEnabled()) { -// log.debug("remove obsolote echantillon " + taille + -// " for species " + tailleEspece); -// } -// } -// } -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public void getObsoleteEspeceForTargetSample(DataSource source, -// String setId, -// Collection<Species> speciessUsed, -// Collection<Species> speciessToDelete, -// List<TargetLength> tailleToDelete, boolean discarded) throws DataSourceException { -// -// String txName = "getObsoleteEspeceForTargetSample [" + setId + "]"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<SetSeine> dao = source.getDAO(tx, SetSeine.class); -// SetSeine set = dao.findByTopiaId(setId); -// -// if (set.isTargetSampleEmpty()) { -// return; -// } -// -// TargetSample echantillon = set.getTargetSample(discarded); -// -// if (echantillon == null || echantillon.isTargetLengthEmpty()) { -// return; -// } -// -// for (TargetLength taille : echantillon.getTargetLength()) { -// Species tailleEspece = taille.getSpecies(); -// if (!speciessUsed.contains(tailleEspece)) { -// // l'species n'existe plus dans les rejet faune, -// // on doit le supprimer -// tailleToDelete.add(taille); -// speciessToDelete.add(tailleEspece); -// if (log.isDebugEnabled()) { -// log.debug("remove obsolote echantillon " + taille + -// " for species " + tailleEspece); -// } -// } -// } -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<Program> getPossibleProgramsForTrip(DataSource source, String tripId) throws DataSourceException { -// -// final GearType gearType; -// -// String txName = "getPossibleProgramsForTrip : " + tripId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// Trip trip; -// -// if (tripId.contains(TripSeine.class.getSimpleName())) { -// trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); -// } else { -// trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); -// } -// -// gearType = trip.getProgram().getGearType(); -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// -// List<Program> programs = dao.findAllByGearType(gearType); -// -// for (Program program : programs) { -// decoratorService.decorate(program); -// } -// -// return programs; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public void moveTripToProgram(DataSource source, String tripId, String programId) throws DataSourceException { -// -// String txName = "moveTripToProgram : " + tripId + " :: " + programId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// Trip trip; -// -// if (tripId.contains(TripSeine.class.getSimpleName())) { -// trip = source.getDAO(tx, TripSeine.class).findByTopiaId(tripId); -// } else { -// trip = source.getDAO(tx, TripLongline.class).findByTopiaId(tripId); -// } -// -// ProgramDAO dao = (ProgramDAO) source.getDAO(tx, Program.class); -// -// Program program = dao.findByTopiaId(programId); -// -// trip.setProgram(program); -// -// tx.commitTransaction(); -// -// if (trip.isOpen()) { -// -// // refresh the dataContext -// dataContext.setOpenProgramId(programId); -// -// } -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } - -// public List<SizeMeasure> getCatchLonglineSizeMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<SizeMeasure> binder) throws DataSourceException { -// -// String txName = "getSections : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); -// CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); -// List<SizeMeasure> result = new ArrayList<SizeMeasure>(); -// for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { -// SizeMeasure target = new SizeMeasureImpl(); -// binder.load(sizeSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } -// -// public List<WeightMeasure> getCatchLonglineWeightMeasures(DataSource source, CatchLongline bean, final TopiaEntityBinder<WeightMeasure> binder) throws DataSourceException { -// -// String txName = "getSections : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<CatchLongline> dao = source.getDAO(tx, CatchLongline.class); -// CatchLongline catchLongline = dao.findByTopiaId(bean.getTopiaId()); -// List<WeightMeasure> result = new ArrayList<WeightMeasure>(); -// for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { -// WeightMeasure target = new WeightMeasureImpl(); -// binder.load(weightSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(DataSource source, String gearId) throws DataSourceException { -// -// String txName = "getDefaultGearUseFeaturesMeasurementSeine : " + gearId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); -// Gear gear = gearDao.findByTopiaId(gearId); -// -// Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); -// List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); -// for (GearCaracteristic caracteristic : gearCaracteristic) { -// GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); -// target.setGearCaracteristic(caracteristic); -// result.add(target); -// } -// -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementSeine> getGearUseFeaturesMeasurementSeine(DataSource source, GearUseFeaturesSeine bean, final TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder) throws DataSourceException { -// -// String txName = "getGearUseFeaturesMeasurementSeine : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<GearUseFeaturesSeine> dao = source.getDAO(tx, GearUseFeaturesSeine.class); -// GearUseFeaturesSeine gearUseFeaturesSeine = dao.findByTopiaId(bean.getTopiaId()); -// List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); -// for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { -// GearUseFeaturesMeasurementSeine target = new GearUseFeaturesMeasurementSeineImpl(); -// measurementSource.getGearCaracteristic().getGearCaracteristicType(); -// binder.load(measurementSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(DataSource source, String gearId) throws DataSourceException { -// -// String txName = "getDefaultGearUseFeaturesMeasurementLongline : " + gearId; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// TopiaDAO<Gear> gearDao = source.getDAO(tx, Gear.class); -// Gear gear = gearDao.findByTopiaId(gearId); -// -// Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); -// List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); -// for (GearCaracteristic caracteristic : gearCaracteristic) { -// GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); -// target.setGearCaracteristic(caracteristic); -// result.add(target); -// } -// -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - -// public List<GearUseFeaturesMeasurementLongline> getGearUseFeaturesMeasurementLongline(DataSource source, GearUseFeaturesLongline bean, final TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder) throws DataSourceException { -// -// String txName = "getGearUseFeaturesMeasurementLongline : " + bean.getTopiaId(); -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaDAO<GearUseFeaturesLongline> dao = source.getDAO(tx, GearUseFeaturesLongline.class); -// GearUseFeaturesLongline gearUseFeaturesLongline = dao.findByTopiaId(bean.getTopiaId()); -// List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); -// for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { -// GearUseFeaturesMeasurementLongline target = new GearUseFeaturesMeasurementLonglineImpl(); -// measurementSource.getGearCaracteristic().getGearCaracteristicType(); -// binder.load(measurementSource, target, true); -// result.add(target); -// } -// return result; -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - public <E extends TopiaEntity> List<String> getEntityIds(DataSource source, Class<E> refClass) - throws DataSourceException { - - String txName = "getEntityIds : " + refClass; - TopiaContext tx = beginTransaction(source, txName); - try { - TopiaDAO<E> dao = source.getDAO(tx, refClass); - List<String> result = dao.findAllIds(); - return result; - } catch (TopiaException e) { - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - -// public List<TripMapPoint> loadTripMapActivityPoints(DataSource source, String id) throws DataSourceException { -// if (!source.canReadData()) { -// if (log.isDebugEnabled()) { -// log.debug("Can not read data!"); -// } -// return null; -// } -// -// String txName = "loadTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// -// List<TripMapPoint> tripMapPoints; -// -// try { -// if (Entities.isSeineId(id)) { -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// -// tripMapPoints = dao.extractTripMapActivityPoints(id); -// -// } else if (Entities.isLonglineId(id)) { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// -// tripMapPoints = dao.extractTripMapActivityPoints(id); -// -// } else { -// throw new ObserveTechnicalException(String.format("id '%s' is not seine id or longe line id", id)); -// } -// -// } catch (TopiaException e) { -// throw new DataSourceException(e, txName); -// } finally{ -// closeTransaction(source, tx, txName); -// } -// return tripMapPoints; -// } - - - // ------------------------------------------------------------------------ - // -- Méthodes de chargement de données - // ------------------------------------------------------------------------ - - -// public TopiaEntity loadEntity(DataSource source, -// String id, -// boolean decorate) throws DataSourceException { -// -// String txName = "loadEntity : " + id; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// TopiaEntity result = tx.findByTopiaId(id); -// //FIXME Find a better way to do this... -// if (result instanceof ActivitySeine) { -// -// // on charge toujours sa calée -// ((ActivitySeine) result).getSetSeine(); -// } -// if (result instanceof ActivityLongline) { -// -// // on charge toujours sa calée -// ((ActivityLongline) result).getSetLongline(); -// } -// if (decorate) { -// Decorator<TopiaEntity> decorator = -// getDecoratorService().getDecorator(result); -// if (decorator == null) { -// if (log.isWarnEnabled()) { -// log.warn("Decorateur non trouvé pour l'objet " + result); -// } -// } else { -// decorator.toString(result); -// } -// } -// return result; -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - - public <E extends TopiaEntity> void loadEditEntity(DataSource source, - String entityId, - TopiaExecutor<E> updator) throws DataSourceException { - - String txName = "loadEditEntity :: " + entityId; - TopiaContext tx = beginTransaction(source, txName); - try { - E bean = source.findByTopiaId(tx, entityId); - updator.execute(tx, bean); - } catch (Exception e) { - throw new DataSourceException("Can not load edit entity " + entityId, e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - -// public <E extends TopiaEntity> List<E> loadEntityAssociation(DataSource source, -// Class<E> entityClass, -// String property, -// String parentId) throws DataSourceException { -// -// TopiaContext tx = beginTransaction(source, "loadEntitiesWithProperties"); -// try { -// -// Class<TopiaEntity> parentclass = TopiaId.getClassName(parentId); -// -// TopiaDAO<?> parentDao = source.getDAO(tx, parentclass); -// -// // get parent entity -// TopiaEntity parent = parentDao.findByTopiaId(parentId); -// -// // get parent operator -// EntityOperator<TopiaEntity> operator = -// ObserveDAOHelper.getOperator(parentclass); -// -// // get property from parent -// List<E> result = (List<E>) operator.get(property, parent); -// -// DecoratorService decoratorService = getDecoratorService(); -// -// if (decoratorService != null) { -// -// // chargement des rendus -// Decorator<E> decorator = -// decoratorService.getDecoratorByType(entityClass); -// for (E e : result) { -// decorator.toString(e); -// } -// } -// return result; -// } catch (TopiaException e) { -// throw new DataSourceException( -// "Can not obtain topiaentity " + -// parentId, e, "loadEntitiesWithProperties"); -// } finally { -// closeTransaction(source, tx, "loadEntitiesWithProperties"); -// } -// } - - public <E extends TopiaEntity, C extends TopiaEntity> void copyAssociation(Class<E> entityType, - Class<C> childEntityType, - String propertyName, - E source, - E target, - TopiaContext targetTx) throws TopiaException { - - EntityOperator<E> operator = ObserveDAOHelper.getOperator(entityType); - - Collection<C> sourceList = (Collection<C>) operator.get(propertyName, source); - - TopiaDAO<C> dao = ObserveDAOHelper.getDAO(targetTx, childEntityType); - - List<C> targetList = Lists.newArrayListWithCapacity(sourceList.size()); - for (C sourceC : sourceList) { - - C targetC = dao.findByTopiaId(sourceC.getTopiaId()); - targetList.add(targetC); - } - operator.set(propertyName, target, targetList); - - } - -// public String getSensorUsedDataFilename(DataSource source, SensorUsed sensorUSed) throws DataSourceException { -// -// String txName = "getSensorUsedDataFilename"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLongline tripLongline = source.getOpen(tx, TripLongline.class); -// -// StringBuilder filenameBuilder = new StringBuilder("sensorData"); -// String code = tripLongline.getVessel().getCode(); -// filenameBuilder.append("-").append(code); -// -// Date startDate = tripLongline.getStartDate(); -// filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); -// -// SensorType sensorType = sensorUSed.getSensorType(); -// if (sensorType != null && sensorType.getCode() != null) { -// filenameBuilder.append("-").append(sensorType.getCode()); -// } -// -// String sensorSerialNo = sensorUSed.getSensorSerialNo(); -// if (sensorSerialNo != null) { -// filenameBuilder.append("-").append(sensorSerialNo); -// } -// filenameBuilder.append("-").append(sensorUSed.getDataFilename()); -// -// String filename = filenameBuilder.toString(); -// return filename; -// -// } finally { -// -// closeTransaction(source, tx, txName); -// -// } -// -// } - -// public String getTdrDataFilename(DataSource source, Tdr tdr) throws DataSourceException { -// -// String txName = "getTdrDataFilename"; -// TopiaContext tx = beginTransaction(source, txName); -// -// try { -// -// TripLongline tripLongline = source.getOpen(tx, TripLongline.class); -// -// StringBuilder filenameBuilder = new StringBuilder("tdr"); -// String code = tripLongline.getVessel().getCode(); -// filenameBuilder.append("-").append(code); -// -// Date startDate = tripLongline.getStartDate(); -// filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); -// -// String homeId = tdr.getHomeId(); -// if (homeId != null) { -// filenameBuilder.append("-").append(homeId); -// } -// -// String serialNo = tdr.getSerialNo(); -// if (serialNo != null) { -// filenameBuilder.append("-").append(serialNo); -// } -// filenameBuilder.append("-").append(tdr.getDataFilename()); -// -// String filename = filenameBuilder.toString(); -// return filename; -// -// } finally { -// -// closeTransaction(source, tx, txName); -// -// } -// -// } - -// public <E extends TopiaEntity> List<E> loadDecoratedEntities(DataSource source, -// Class<E> entityClass) throws DataSourceException { -// -// String txName = "loadEntities :: " + entityClass.getName(); -// TopiaContext tx = beginTransaction(source, txName); -// Decorator<E> decorator = getDecoratorService().getDecoratorByType(entityClass); -// try { -// List<E> result = -// source.loadDecoratedEntities(tx, entityClass, decorator); -// return result; -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - - public <E extends TopiaEntity> List<E> loadDecoratedEntities(DataSource source, - Class<E> entityClass, - TopiaExecutor<E> loador) throws DataSourceException { - - String txName = "loadDecoratedEntities :: " + entityClass.getName(); - TopiaContext tx = beginTransaction(source, txName); - Decorator<E> decorator = getDecoratorService().getDecoratorByType(entityClass); - try { - List<E> result = - source.loadDecoratedEntities(tx, entityClass, decorator); - - if (CollectionUtils.isNotEmpty(result)) { - for (E e : result) { - try { - loador.execute(tx, e); - } catch (TopiaException e1) { - throw new DataSourceException( - "Can not obtain load entity " + e.getTopiaId(), e1, txName); - } - } - } - return result; - } finally { - closeTransaction(source, tx, txName); - } - } - - // ------------------------------------------------------------------------ - // -- Méthodes de création - mise à jour - suppression de données - // ------------------------------------------------------------------------ - - - public <E extends TopiaEntity, P extends TopiaEntity> E preCreate(DataSource source, - String parentBeanId, - E bean, - Loador<E> binder, - TopiaExecutor2<P, E> creator) throws DataSourceException { - - String txName = "preCreate"; - TopiaContext tx = beginTransaction(source, txName); - try { - P parentBean = null; - - if (parentBeanId != null) { - - // il y a un parent a recuperer - try { - parentBean = source.<P>findByTopiaId(tx, parentBeanId); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(PARENT_BEAN, parentBean); - } - - // on charge le bean - binder.load(null, bean, true); - - checkNotNullAndNoneExistingEntity(BEAN, bean); - - E result; - if (creator == null) { - result = bean; - } else { - try { - result = creator.execute(tx, parentBean, bean); - } catch (TopiaException ex) { - throw new DataSourceException(ex, txName); - } - } - return result; - } finally { - closeTransaction(source, tx, txName); - } - } - - - public <E extends TopiaEntity, P extends TopiaEntity> E create(DataSource source, - String parentBeanId, - E bean, - Loador<E> binder, - TopiaExecutor2<P, E> creator) throws DataSourceException { - - checkNotNullAndNoneExistingEntity("bean", bean); - - String txName = "create"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - P parentBean = null; - - if (parentBeanId != null) { - - // il y a un parent a recuperer - try { - parentBean = source.<P>findByTopiaId(tx, parentBeanId); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(PARENT_BEAN, parentBean); - } - - E beanToSave = creator.execute(tx, parentBean, bean); - - if (binder != null) { - binder.load(bean, beanToSave, false); - } - - if (parentBean == null) { - - // sauvegarde de l'entité autolastNamee - TopiaDAO<E> dao = source.getDAO(tx, beanToSave); - dao.update(beanToSave); - } else { - - // sauvegarde du père de l'entité - TopiaDAO<P> dao = source.getDAO(tx, parentBean); - dao.update(parentBean); - } - - commitTransaction(source, tx, txName); - return beanToSave; - } catch (Exception e) { - rollbackTransaction(source, tx, txName); - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - - public <E extends TopiaEntity, P extends TopiaEntity> E update(DataSource source, - String parentBeanId, - E bean, - TopiaExecutor2<P, E> updator) throws DataSourceException { - - checkNotNullAndExistingEntity("bean", bean); - - String txName = "update"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - P parentBean = null; - - if (parentBeanId != null) { - - // il y a un parent a recuperer - try { - parentBean = source.<P>findByTopiaId(tx, parentBeanId); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(PARENT_BEAN, parentBean); - } - - E beanToSave; - - try { - beanToSave = source.<E>findByTopiaId(tx, bean.getTopiaId()); - } catch (TopiaException e) { - - // pas possible de recuperer le parent - throw new DataSourceException(e, txName); - } - - checkNotNullAndExistingEntity(BEAN, beanToSave); - - beanToSave = updator.execute(tx, parentBean, beanToSave); - - if (parentBean == null) { - - // sauvegarde de l'entité autolastNamee - TopiaDAO<E> dao = source.getDAO(tx, beanToSave); - dao.update(beanToSave); - } else { - - // sauvegarde du père de l'entité - TopiaDAO<P> dao = source.getDAO(tx, parentBean); - dao.update(parentBean); - } - - commitTransaction(source, tx, txName); - return beanToSave; - } catch (Exception e) { - rollbackTransaction(source, tx, txName); - throw new DataSourceException(e, txName); - } finally { - closeTransaction(source, tx, txName); - } - } - - -// public void updateOpenProperty(DataSource source, -// String id, -// boolean newValue) throws DataSourceException { -// -// if (!source.canWriteData()) { -// -// // pas autorisé à écrire des données observer -// return; -// } -// -// String txName = "updateOpenProperty :: " + id + " - " + newValue; -// TopiaContext tx = null; -// try { -// tx = beginTransaction(source, txName); -// OpenableEntity beanToSave = source.findByTopiaId(tx, id); -// beanToSave.setOpen(newValue); -// commitTransaction(source, tx, txName); -// } catch (TopiaException e) { -// throw new DataSourceException( -// "Can not update open state for " + id, e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// } - - - @SuppressWarnings({"unchecked"}) - public <P extends TopiaEntity, E extends TopiaEntity> void delete(DataSource source, - String parentBeanId, - E bean, - TopiaExecutor2<P, E> deletor) throws DataSourceException { - - checkNotNullAndExistingEntity("bean", bean); - - String txName = "delete"; - TopiaContext tx = beginTransaction(source, txName); - - try { - - P parentBean = null; - - TopiaDAO<TopiaEntity> parentDao = null; - - if (parentBeanId != null) { - parentBean = (P) tx.findByTopiaId(parentBeanId); - - checkNotNullAndExistingEntity("parentBean", parentBean); - - parentDao = source.getDAO(tx, (TopiaEntity) parentBean); - } - - E beanToDelete = (E) tx.findByTopiaId(bean.getTopiaId()); - - deletor.execute(tx, parentBean, beanToDelete); - - if (parentBeanId != null) { - - parentDao.update(parentBean); - } - - commitTransaction(source, tx, txName); - } catch (Exception e) { - rollbackTransaction(source, tx, "create"); - if (e instanceof DataSourceException) { - throw (DataSourceException) e; - } - throw new DataSourceException(e, txName); - } - } - - - public void close() { - decoratorService = null; - dataContext = null; - } - - - public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { - TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); - } - - - public <E extends TopiaEntity> void checkNotNullAndExistingEntity(String variableName, E entity) { - TopiaEntityHelper.checkNotNullAndExistingEntity(variableName, entity); - } - - - public DiffState.DiffStateMap buildReferentielDifferentiel(final DataSource srcService, - final DataSource dstService, - final SendMessageAble messanger) - throws DataSourceException { - try { - final DiffState.DiffStateMap result = DiffState.newMap(); - ReferenceEntities.walk(new ReferenceEntities.ReferentielWalker() { - - - public <E extends TopiaEntity> void walk( - Class<E> contractClass) throws Exception { - - String s = t(DecoratorService.getEntityLabel(contractClass)); - String message = - t("observe.service.build.synchro.referentiel", s); - if (messanger != null) { - messanger.sendMessage(message); - } - if (log.isInfoEnabled()) { - log.info(message); - } - List<E> list = getList(srcService, contractClass); - List<E> list2 = getList(dstService, contractClass); - DiffState.DiffStateMap tmp; - // recuperation du differentiel pour le type d'entitétmp = - tmp = TopiaEntityHelper.buildDifferentiel(list, list2); - // ajout au resultat - DiffState.addAll(result, tmp); - // on nettoie - DiffState.clear(tmp); - } - }); - DiffState.removeEmptyStates(result); - return result; - } catch (DataSourceException ex) { - throw ex; - } catch (Exception ex) { - throw new DataSourceException(ex, "buildReferentielDifferentiel"); - } - } - - protected <E extends TopiaEntity> List<E> getList0(DataSource source, - Class<E> klass, - Predicate<E> predicate, - TopiaEntityBinder<E> loador) throws Exception { - - TopiaContext tx = beginTransaction(source, "getList0 : " + klass); - try { - TopiaDAO<E> dao = source.getDAO(tx, klass); - List<E> result = dao.findAll(); - - if (predicate != null) { - - // use a filter - result = Lists.newArrayList(Iterables.filter(result, predicate)); - - } - if (loador != null) { - for (E e : result) { - loador.obtainProperties(e); - } - } - return result; - } finally { - closeTransaction(source, tx, "getList0 : " + klass); - } - } - - // ------------------------------------------------------------------------ - // -- Property change support - // ------------------------------------------------------------------------ - - - public void addPropertyChangeListener(PropertyChangeListener listener) { - pcs.addPropertyChangeListener(listener); - } - - public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.addPropertyChangeListener(propertyName, listener); - } - - public void removePropertyChangeListener(PropertyChangeListener listener) { - pcs.removePropertyChangeListener(listener); - } - - public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { - pcs.removePropertyChangeListener(propertyName, listener); - } - -// public void removePropertyChangeListeners() { -// for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) { -// removePropertyChangeListener(listener); -// } -// } - - public <E extends TopiaEntity> void addReferentielPropertyChangeListener(Class<E> entitClass, PropertyChangeListener listener) { - ObserveEntityEnum constant = ObserveEntityEnum.valueOf(entitClass); - String propertyName = getReferentielPropertyName(constant); - log.info(propertyName + " :" + listener); - addPropertyChangeListener(propertyName, listener); - } - -// public <E extends TopiaEntity> void addDataPropertyChangeListener(Class<E> entitClass, PropertyChangeListener listener) { -// ObserveEntityEnum constant = ObserveEntityEnum.valueOf(entitClass); -// String propertyName = getDataPropertyName(constant); -// addPropertyChangeListener(propertyName, listener); -// } - - public void removeReferentielPropertyChangeListeners() { - for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { - String propertyName = getReferentielPropertyName(constant); - PropertyChangeListener[] changeListeners = pcs.getPropertyChangeListeners(propertyName); - if (log.isDebugEnabled()) { - log.debug(propertyName + " :" + changeListeners.length); - } - for (PropertyChangeListener listener : - changeListeners) { - if (log.isDebugEnabled()) { - log.debug(propertyName + " :" + listener); - } - removePropertyChangeListener(propertyName, listener); - } - } - } - - protected String getReferentielPropertyName(ObserveEntityEnum constant) { - return DataSource.REFERENTIEL_PROPERTY_KEY + "#" + constant.name(); - } - - protected String getDataPropertyName(ObserveEntityEnum constant) { - return DataSource.DATA_PROPERTY_KEY + "#" + constant.name(); - } - - protected void firePropertyChangedEvent(PropertyChangeEvent event, - String message, - PropertyChangeListener... listeners) { - for (PropertyChangeListener listener : listeners) { - if (log.isInfoEnabled()) { - log.info(message + ", notifiy listener " + listener); - } - listener.propertyChange(event); - } - } - - protected PropertyChangeListener[] getPropertyChangeListener(String propertyName) { - List<PropertyChangeListener> result = new ArrayList<PropertyChangeListener>(); - for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) { - if (listener instanceof PropertyChangeListenerProxy) { - PropertyChangeListenerProxy proxy = - (PropertyChangeListenerProxy) listener; - if (!propertyName.equals(proxy.getPropertyName())) { - continue; - } - } - result.add(listener); - } - return result.toArray(new PropertyChangeListener[result.size()]); - } - -// public void fireOpenChanged(DataSource source) { -// -// String propertyName = DataSource.OPEN_PROPERTY_KEY; -// -// if (log.isInfoEnabled()) { -// log.info("Open context changed, will notifiy listeners [" + propertyName + "]..."); -// } -// -// // obtain all opens ids -// try { -// -// String[] ids = getOpenIds(source); -// -// String message = Arrays.toString(ids); -// -// PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); -// if (listeners.length == 0) { -// // pas de listener, on ne fait rien -// -// -// if (log.isInfoEnabled()) { -// log.info("Open context " + message + ", No listener, skip"); -// } -// return; -// } -// -// PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, ids); -// firePropertyChangedEvent(event, "Open context " + message + " changed", listeners); -// -// } catch (DataSourceException e) { -// if (log.isErrorEnabled()) { -// log.error("Could not fire open changed", e); -// } -// } -// } - - protected void fireReferentielChanged(DataSource source, ObserveEntityEnum... types) { - for (ObserveEntityEnum constant : types) { - try { - String propertyName = getReferentielPropertyName(constant); - if (log.isInfoEnabled()) { - log.info("Referentiel [" + constant + "] changed, will notifiy listeners [" + propertyName + "]..."); - } - - PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); - if (listeners.length == 0) { - // pas de listener, on ne fait rien - - if (log.isInfoEnabled()) { - log.info("Referentiel [" + constant + "] No listener, skip"); - } - return; - } - - List<? extends TopiaEntity> entities = getList(source, constant.getContract()); - if (log.isInfoEnabled()) { - log.info("Referentiel [" + constant + "] new size " + entities.size()); - } - - PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, entities); - firePropertyChangedEvent(event, "Referentiel [" + constant + "] changed", listeners); - } catch (DataSourceException e) { - if (log.isErrorEnabled()) { - log.error("Could not fire referentiel [" + constant + "] changed"); - } - } - } - } - - protected void fireDataChanged(DataSource source, TopiaEntity... types) { - for (TopiaEntity entity : types) { - - ObserveEntityEnum constant = - ObserveEntityEnum.valueOf(entity); - - // une entite donnee observer a ete modifiee, supprimer ou cree - // on notifie tous les écouteurs des données observer - - String propertyName = getDataPropertyName(constant); - if (log.isInfoEnabled()) { - log.info("Data [" + entity.getTopiaId() + "] changed, will notifiy listeners [" + propertyName + "]..."); - } - - PropertyChangeListener[] listeners = getPropertyChangeListener(propertyName); - if (listeners.length == 0) { - // pas de listener, on ne fait rien - - if (log.isDebugEnabled()) { - log.debug("Data [" + entity.getTopiaId() + "] No listener, skip"); - } - return; - } - - PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, null, entity); - firePropertyChangedEvent(event, "Data [" + entity + "] changed", listeners); - } - } - -// public void deleteTrip(DataSource source, String tripId) throws DataSourceException { -// -// String txName = "deleteTrip"; -// TopiaContext tx = beginTransaction(source, txName); -// try { -// -// if (Entities.isSeineId(tripId)) { -// -// TripSeineDAO dao = (TripSeineDAO) source.getDAO(tx, TripSeine.class); -// TripSeine result = dao.findByTopiaId(tripId); -// dao.delete(result); -// -// } else { -// -// TripLonglineDAO dao = (TripLonglineDAO) source.getDAO(tx, TripLongline.class); -// TripLongline result = dao.findByTopiaId(tripId); -// dao.delete(result); -// -// } -// -// skipTransactionListener = true; -// try { -// -// commitTransaction(source, tx, txName); -// -// } finally { -// skipTransactionListener = false; -// } -// -// } catch (Exception e) { -// throw new DataSourceException(e, txName); -// } finally { -// closeTransaction(source, tx, txName); -// } -// -// } -} diff --git a/observe-business/src/test/java/fr/ird/observe/db/DataServiceTest.java b/observe-business/src/test/java/fr/ird/observe/db/DataServiceTest.java deleted file mode 100644 index d720a02..0000000 --- a/observe-business/src/test/java/fr/ird/observe/db/DataServiceTest.java +++ /dev/null @@ -1,339 +0,0 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe.db; - -import fr.ird.observe.DataService; -import fr.ird.observe.IObserveConfig; -import fr.ird.observe.db.impl.H2DataSourceConfig; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.test.TestHelper; -import fr.ird.observe.util.Scripts; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.event.TopiaEntityEvent; -import org.nuiton.topia.event.TopiaEntityListener; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; - -/** - * Tests the {@link DataService}. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.4 - */ -public class DataServiceTest { - - - /** Logger */ - private static final Log log = - LogFactory.getLog(DataServiceTest.class); - - - @BeforeClass - public static void init() throws Exception { - - TestHelper.initTest(DataServiceTest.class); - - TestHelper.createApplicationContext(); - - TestHelper.setConfig(IObserveConfig.DB_VERSION, - Scripts.V_LAST.toString()); - } - - @Before - public void setUp() { - hits = 0; - } - - @After - public void tearDown() throws Exception { - DataSourceFactory.dispose(); - } - - @Test - public void testSetDataSource2() throws Exception { - - DataService service = new DataService(); - - service.addReferentielPropertyChangeListener(Program.class, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - increment(); - } - }); - - File dir = TestHelper.newLocalDB("testSetDataSource2"); - - H2DataSourceConfig config = DataSourceFactory.newH2ConfigEmpty( - "testSetDataSource2", - dir, - TestHelper.TEST_H2_LOGIN, - TestHelper.TEST_H2_PASSWORD - ); - - Assert.assertNotNull(config); - - DataSource dataSource = DataSourceFactory.newService(config); - - dataSource.doOpen(); - - Assert.assertTrue(dataSource.isOpen()); - - DBTestHelper.assertSchemaCreated( - dataSource, - true - ); - - service.registerDataSource(dataSource); - -// Assert.assertTrue(service.isEnabled()); - - dataSource.getRootCtxt().addTopiaEntityListener(listener); - - Assert.assertEquals(0, hits); - - Program program; - TopiaContext tx = service.beginTransaction(dataSource, "createProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.create(Program.PROPERTY_CODE, "1", Program.PROPERTY_LABEL1, "label1", Program.PROPERTY_LABEL2, "label2"); - - service.commitTransaction(dataSource, tx, "createProgram"); - } finally { - service.closeTransaction(dataSource, tx, "createProgram"); - } - - // un hit de creation - Assert.assertEquals(1, hits); - - tx = service.beginTransaction(dataSource, "loadProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - - } finally { - service.closeTransaction(dataSource, tx, "loadProgram"); - } - - // pas de hit de load - Assert.assertEquals(1, hits); - - - tx = service.beginTransaction(dataSource, "updateProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.findByTopiaId(program.getTopiaId()); - - program.setLabel3("label3"); - dao.update(program); - - service.commitTransaction(dataSource, tx, "updateProgram"); - } finally { - service.closeTransaction(dataSource, tx, "updateProgram"); - } - - // un hit de update - Assert.assertEquals(2, hits); - - tx = service.beginTransaction(dataSource, "deleteProgram"); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - dao.delete(program); - - service.commitTransaction(dataSource, tx, "deleteProgram"); - } finally { - service.closeTransaction(dataSource, tx, "deleteProgram"); - } - - - // un hit de delete - Assert.assertEquals(3, hits); - - } - - @Test - public void testSetDataSource() throws Exception { - - DataService service = new DataService(); - - File dir = TestHelper.newLocalDB("testSetDataSource"); - - H2DataSourceConfig config = DataSourceFactory.newH2ConfigEmpty( - "testCreateH2ConfigEmpty", - dir, - TestHelper.TEST_H2_LOGIN, - TestHelper.TEST_H2_PASSWORD - ); - - Assert.assertNotNull(config); - - DataSource dataSource = DataSourceFactory.newService(config); - - dataSource.doOpen(); - - Assert.assertTrue(dataSource.isOpen()); - - DBTestHelper.assertSchemaCreated( - dataSource, - true - ); - - service.registerDataSource(dataSource); - -// Assert.assertTrue(service.isEnabled()); - - dataSource.getRootCtxt().addTopiaEntityListener(listener); - - Assert.assertEquals(0, hits); - Program program; - TopiaContext tx = service.beginTransaction(dataSource, "createProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.create(Program.PROPERTY_CODE, "1", Program.PROPERTY_LABEL1, "label1", Program.PROPERTY_LABEL2, "label2"); - - service.commitTransaction(dataSource, tx, "createProgram"); - } finally { - service.closeTransaction(dataSource, tx, "createProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de creation - Assert.assertEquals(1, hits); - - tx = service.beginTransaction(dataSource, "loadProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - - } finally { - service.closeTransaction(dataSource, tx, "loadProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de load -// Assert.assertEquals(1, hits); - Assert.assertEquals(2, hits); - - - tx = service.beginTransaction(dataSource, "updateProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - - program = dao.findByTopiaId(program.getTopiaId()); - - program.setLabel3("label3"); - dao.update(program); - - service.commitTransaction(dataSource, tx, "updateProgram"); - } finally { - service.closeTransaction(dataSource, tx, "updateProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de load + update -// Assert.assertEquals(2, hits); - Assert.assertEquals(4, hits); - - tx = service.beginTransaction(dataSource, "deleteProgram"); - tx.addTopiaEntityListener(listener); - try { - TopiaDAO<Program> dao = dataSource.getDAO(tx, Program.class); - - program = dao.findByTopiaId(program.getTopiaId()); - dao.delete(program); - - service.commitTransaction(dataSource, tx, "deleteProgram"); - } finally { - service.closeTransaction(dataSource, tx, "deleteProgram"); - tx.removeTopiaEntityListener(listener); - } - - // un hit de load + delete -// Assert.assertEquals(3, hits); - Assert.assertEquals(6, hits); - - } - - protected int hits; - - public void increment() { - hits++; - } - - final TopiaEntityListener listener = new TopiaEntityListener() { - - @Override - public void create(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - - @Override - public void load(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - - @Override - public void update(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - - @Override - public void delete(TopiaEntityEvent event) { - if (log.isInfoEnabled()) { - log.info(event.getEntity().getTopiaId()); - } - increment(); - } - }; -} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java new file mode 100644 index 0000000..d079a72 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/LengthWeightParameterDAOImpl.java @@ -0,0 +1,4 @@ +package fr.ird.observe.entities.referentiel; + +public class LengthWeightParameterDAOImpl<E extends LengthWeightParameter> extends LengthWeightParameterDAOAbstract<E> { +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java new file mode 100644 index 0000000..97f220e --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/SexDAOImpl.java @@ -0,0 +1,7 @@ +package fr.ird.observe.entities.referentiel; + +import javax.annotation.Generated; + +@Generated(value = "org.nuiton.topia.generator.EntityDAOTransformer", date = "Sat May 02 12:01:39 CEST 2015") +public class SexDAOImpl<E extends Sex> extends SexDAOAbstract<E> { +} //SexDAOImpl<E extends Sex> diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java new file mode 100644 index 0000000..865a5c5 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/ReplicationService.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public interface ReplicationService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java new file mode 100644 index 0000000..dcac5bc --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/ReplicationServiceImpl.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class ReplicationServiceImpl implements ReplicationService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java new file mode 100644 index 0000000..9b58b2e --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataService.java @@ -0,0 +1,18 @@ +package fr.ird.observe.services.operation; + +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.services.ObserveService; + +import java.util.Set; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ComputeDataService extends ObserveService{ + + void consolidateTrips(SendMessageAble messager, Set<String> tripIds); + +} diff --git a/observe-business/src/main/java/fr/ird/observe/ConsolidateDataService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java similarity index 80% rename from observe-business/src/main/java/fr/ird/observe/ConsolidateDataService.java rename to observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java index ef0999e..e56a919 100644 --- a/observe-business/src/main/java/fr/ird/observe/ConsolidateDataService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ComputeDataServiceImpl.java @@ -1,32 +1,14 @@ -/* - * #%L - * ObServe :: Business - * %% - * Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit - * %% - * 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% - */ -package fr.ird.observe; +package fr.ird.observe.services.operation; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; -import fr.ird.observe.db.DataSourceException; +import fr.ird.observe.DecoratorService; +import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.LengthWeightComputable; import fr.ird.observe.entities.constants.seine.NonTargetCatchComputedValueSource; import fr.ird.observe.entities.constants.seine.SchoolType; @@ -43,11 +25,12 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.referential.ReferentialService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.topia.persistence.util.TopiaEntityRef; @@ -58,25 +41,24 @@ import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.SortedMap; import static org.nuiton.i18n.I18n.t; /** - * Le service pour consolider les données observers. - * <p/> - * Il s'agit de pouvoir calculer le type de banc d'une activité et de calculer - * les données déductibles des données observées (sur les discardeds faune et les - * échantillons via les relations taille-weight et autres...). + * FIXME A revoir, utiliser un context pour ne pas avoir d'état dans le service + on ne peut plus utiliser de messager + * On retounera un objet de type result. + * + * Created on 5/3/15. * * @author Tony Chemit - chemit@codelutin.com - * @since 1.8 + * @since 4.0 */ -public class ConsolidateDataService { +public class ComputeDataServiceImpl extends AbstractObserveService implements ComputeDataService { - /** Logger */ - private static final Log log = - LogFactory.getLog(ConsolidateDataService.class); + /** Logger. */ + private static final Log log = LogFactory.getLog(ComputeDataServiceImpl.class); private static final String MESSAGE_FORMAT_3 = "[%1$s] %2$s calculé : %3$s (%4$s:%5$s, %6$s:%7$s)"; @@ -87,7 +69,7 @@ public class ConsolidateDataService { TargetLength.PROPERTY_WEIGHT, TargetLength.PROPERTY_WEIGHT_SOURCE); - protected final BeanMonitor nonTargetSampleMonitor = new BeanMonitor( + protected final BeanMonitor nonTargetLengthMonitor = new BeanMonitor( NonTargetLength.PROPERTY_LENGTH, NonTargetLength.PROPERTY_LENGTH_SOURCE, NonTargetLength.PROPERTY_WEIGHT, @@ -104,40 +86,27 @@ public class ConsolidateDataService { NonTargetCatch.PROPERTY_TOTAL_COUNT_COMPUTED_SOURCE ); - protected final BeanMonitor speciesMonitor = new BeanMonitor( - NonTargetLength.PROPERTY_LENGTH_SOURCE, - NonTargetLength.PROPERTY_WEIGHT, - NonTargetLength.PROPERTY_WEIGHT_SOURCE); - - protected Decorator<TripSeine> mareeDecorator; - - protected Decorator<Species> speciesDecorator; - - protected Decorator<ActivitySeine> activityDecorator; - protected String nonTargetCatcheLabel; protected String speciesLabel; - protected String speciesThonLabel; + protected ReferentialService referentialService; - protected final SendMessageAble LOG_ESSAGER = new SendMessageAble() { - @Override - public void sendMessage(String message) { - if (log.isInfoEnabled()) { - log.info(message); - } + protected ReferentialService getReferentialService() { + if (referentialService == null) { + referentialService = newService(ReferentialService.class); } - }; + return referentialService; + } - public String getNonTargetCatcheLabel() { + protected String getNonTargetCatcheLabel() { if (nonTargetCatcheLabel == null) { nonTargetCatcheLabel = t(DecoratorService.getEntityLabel(NonTargetCatch.class)); } return nonTargetCatcheLabel; } - public String getSpeciesLabel() { + protected String getSpeciesLabel() { if (speciesLabel == null) { speciesLabel = t(DecoratorService.getEntityLabel(Species.class)); } @@ -145,45 +114,77 @@ public class ConsolidateDataService { } - public String decorate(TripSeine maree) { - if (mareeDecorator == null) { - mareeDecorator = getDecoratorService().getDecoratorByType(TripSeine.class); - } - return mareeDecorator.toString(maree); + protected void clear() { + + nonTargetLengthMonitor.setBean(null); + targetLengthMonitor.setBean(null); + nonTargetCatchMonitor.setBean(null); + nonTargetCatcheLabel = null; + speciesLabel = null; + } - public String decorate(Species species) { - if (speciesDecorator == null) { - speciesDecorator = - getDecoratorService().getDecoratorByType(Species.class); + @Override + public void consolidateTrips(SendMessageAble messager, Set<String> tripIds) { + + if (messager==null) { + + messager = new SendMessageAble() { + + @Override + public void sendMessage(String message) { + if (log.isInfoEnabled()) { + log.info(message); + } + } + }; + } - return speciesDecorator.toString(species); - } -// public String decorate(Species species) { -// if (speciesThonDecorator == null) { -// speciesThonDecorator = -// getDecoratorService().getDecoratorByType(Species.class); -// } -// return speciesThonDecorator.toString(species); -// } + TopiaDAO<TripSeine> dao = getDao(TripSeine.class); + + List<TripSeine> toUpdate = new ArrayList<TripSeine>(tripIds.size()); + + for (String tripId : tripIds) { + + if (Entities.isSeineId(tripId)) { + + TripSeine trip = dao.findByTopiaId(tripId); + + boolean needUpdate = consolidateTripSeine(messager, trip); + if (needUpdate) { + + // on met a jour la maree en base + dao.update(trip); + + // on conserve une reference sur la maree mise à jour + toUpdate.add(trip); + + } + + } + + } + + // on commite si quelque chose a ete mise a jour + boolean needCommit = !toUpdate.isEmpty(); + + if (needCommit) { + + messager.sendMessage(t("observe.message.consolidate.save.changes", toUpdate.size())); + getTransaction().commitTransaction(); - public String decorate(ActivitySeine activitySeine) { - if (activityDecorator == null) { - activityDecorator = - getDecoratorService().getDecoratorByType(ActivitySeine.class); } - return activityDecorator.toString(activitySeine); + } - public boolean consolidateTrip(SendMessageAble messager, - TopiaContext tx, - TripSeine maree) throws Exception { - String mareeStr = decorate(maree); + protected boolean consolidateTripSeine(SendMessageAble messager, TripSeine maree) { + + clear(); - SendMessageAble messager1 = getMessager(messager); - messager1.sendMessage( - t("observe.message.consolidate.start.maree", mareeStr)); + String mareeStr = decorateEntity(maree); + + messager.sendMessage(t("observe.message.consolidate.start.maree", mareeStr)); // recuperation des ids des sets de la maree String[] activityIds = getActivityIds(maree); @@ -191,9 +192,7 @@ public class ConsolidateDataService { if (activityIds.length == 0) { // pas de set dans cette maree, donc rien a sauvegarder - messager1.sendMessage( - t("observe.message.consolidate.no.activity.from.maree", - mareeStr)); + messager.sendMessage(t("observe.message.consolidate.no.activity.from.maree", mareeStr)); return false; } @@ -212,7 +211,6 @@ public class ConsolidateDataService { TopiaEntity[] path = ref.getPath(); Route route = (Route) path[path.length - 2]; boolean needUpdate = consolidateActivity(messager, - tx, maree, route, activitySeine @@ -224,38 +222,24 @@ public class ConsolidateDataService { if (toUpdate.isEmpty()) { // rien n'a ete modifie - messager1.sendMessage(t("observe.message.consolidate.nothing.to.save.for.maree", - mareeStr)); + messager.sendMessage(t("observe.message.consolidate.nothing.to.save.for.maree", mareeStr)); return false; + } // on devra mettre a jour en base la maree - messager1.sendMessage(t("observe.message.consolidate.maree.need.update", - mareeStr)); - return true; - } + messager.sendMessage(t("observe.message.consolidate.maree.need.update", mareeStr)); - public void clear() { + return true; - nonTargetSampleMonitor.setBean(null); - targetLengthMonitor.setBean(null); - nonTargetCatchMonitor.setBean(null); - mareeDecorator = null; - activityDecorator = null; - speciesDecorator = null; - nonTargetCatcheLabel = null; - speciesLabel = null; - speciesThonLabel = null; } protected boolean consolidateActivity(SendMessageAble messager, - TopiaContext tx, TripSeine maree, Route route, - ActivitySeine activity) throws Exception { + ActivitySeine activity) { - getMessager(messager).sendMessage(t("observe.message.consolidate.start.activity", - decorate(activity))); + messager.sendMessage(t("observe.message.consolidate.start.activity", decorateEntity(activity))); boolean needUpdate = false; SetSeine set = activity.getSetSeine(); @@ -279,7 +263,6 @@ public class ConsolidateDataService { targetLengthMonitor.setBean(targetLength); updateLengthWeightAble( - tx, maree, route.getDate(), targetLength.getSpecies(), @@ -305,17 +288,16 @@ public class ConsolidateDataService { for (NonTargetLength nonTargetLength : nonTargetSample.getNonTargetLength()) { - nonTargetSampleMonitor.setBean(nonTargetLength); + nonTargetLengthMonitor.setBean(nonTargetLength); updateLengthWeightAble( - tx, maree, route.getDate(), nonTargetLength.getSpecies(), nonTargetLength.getSex(), nonTargetLength ); - if (nonTargetSampleMonitor.wasModified()) { + if (nonTargetLengthMonitor.wasModified()) { needUpdate = true; } } @@ -353,7 +335,6 @@ public class ConsolidateDataService { } updateNonTargetCatch( - tx, maree, set, route.getDate(), @@ -368,30 +349,18 @@ public class ConsolidateDataService { return needUpdate; } - protected boolean allNonTargetCatchDataFilled(NonTargetCatch nonTargetCatch) { - return Iterables.all( - Sets.newHashSet(nonTargetCatch.getCatchWeight(), - nonTargetCatch.getTotalCount(), - nonTargetCatch.getMeanWeight(), - nonTargetCatch.getMeanLength()), - Predicates.notNull()); - } - - protected void updateNonTargetCatch(TopiaContext tx, - TripSeine maree, + protected void updateNonTargetCatch(TripSeine maree, SetSeine set, Date jour, - NonTargetCatch nonTargetCatch) throws DataSourceException { + NonTargetCatch nonTargetCatch) { final Species species = nonTargetCatch.getSpecies(); // récupération du référentiel - LengthWeightParameter parametrage = - getDataService().findLengthWeightParameter(tx, - species, - maree.getOcean(), - null, // pas de sexe spécifié - jour); + LengthWeightParameter parametrage = getReferentialService().findLengthWeightParameter(species, + maree.getOcean(), + null, // pas de sexe spécifié + jour); // -- Cas n°1 (calcul uniquement à partir des relations taille - poids) updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); @@ -408,6 +377,7 @@ public class ConsolidateDataService { if (!set.isNonTargetSampleEmpty()) { samples = Collections2.filter(set.getNonTargetSample().iterator().next().getNonTargetLength(), new Predicate<NonTargetLength>() { + @Override public boolean apply(NonTargetLength input) { return species.equals(input.getSpecies()); @@ -448,7 +418,7 @@ public class ConsolidateDataService { } protected void updateNonTargetCatchByLengthWeightRelation(NonTargetCatch nonTargetCatch, - LengthWeightParameter parametrage) throws DataSourceException { + LengthWeightParameter parametrage) { // calcul via le paramétrage taille - poids updateLengthWeightAble( @@ -470,109 +440,7 @@ public class ConsolidateDataService { ); } - protected void computeNonTargetCatchTailleMoyenne(NonTargetCatch nonTargetCatch, - Collection<NonTargetLength> samples, - LengthWeightParameter parametrage) throws DataSourceException { - - Float meanLength = null; - NonTargetCatchComputedValueSource computedSource = null; - - if (CollectionUtils.isNotEmpty(samples)) { - - // on calcul la taille moyenne à partir des échantillons - float totalTaille = 0f; - int nbIndividus = 0; - for (NonTargetLength sample : samples) { - - Integer count = sample.getCount(); - Float length = sample.getLength(); - - if (count != null && length != null) { - nbIndividus += count; - totalTaille += length * count; - } - } - - if (nbIndividus != 0) { - - meanLength = totalTaille / nbIndividus; - - computedSource = NonTargetCatchComputedValueSource.FROM_SAMPLE; - } - } - - if (meanLength == null && parametrage != null) { - - // on prend directement la valeur fournie par le référentiel - - meanLength = parametrage.getMeanLength(); - computedSource = NonTargetCatchComputedValueSource.FROM_REFERENTIEL; - } - - if (meanLength != null) { - - // la taille moyenne a pu etre calculee, on la pousse alors - nonTargetCatch.setMeanLength(meanLength); - nonTargetCatch.setMeanLengthComputedSource(computedSource); - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - - } - - private void computeNonTargetCatchNombreEstime(NonTargetCatch nonTargetCatch, - Collection<NonTargetLength> samples, - LengthWeightParameter parametrage) throws DataSourceException { - - - if (CollectionUtils.isNotEmpty(samples)) { - - // on calcul la taille moyenne à partir des échantillons - int nbIndividus = 0; - for (NonTargetLength sample : samples) { - - Integer count = sample.getCount(); - - if (count != null) { - nbIndividus += count; - } - } - - if (nbIndividus != 0) { - - nonTargetCatch.setTotalCount(nbIndividus); - nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_SAMPLE); - - if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - } - } - } - - private void computeNonTargetCatchMeanValues(NonTargetCatch nonTargetCatch, - LengthWeightParameter parametrage) throws DataSourceException { - - if (parametrage != null) { - - nonTargetCatch.setMeanLength(parametrage.getMeanLength()); - nonTargetCatch.setMeanLengthComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); - - nonTargetCatch.setMeanWeight(parametrage.getMeanWeight()); - nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); - - if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - } - } - - protected void updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(NonTargetCatch nonTargetCatch) throws DataSourceException { + protected void updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(NonTargetCatch nonTargetCatch) { Float meanWeight = nonTargetCatch.getMeanWeight(); Float catchWeight = nonTargetCatch.getCatchWeight(); @@ -641,12 +509,11 @@ public class ConsolidateDataService { } } - protected void updateLengthWeightAble(TopiaContext tx, - TripSeine maree, + protected void updateLengthWeightAble(TripSeine maree, Date jour, Species species, Sex sex, - LengthWeightComputable e) throws DataSourceException { + LengthWeightComputable e) { Ocean ocean = maree.getOcean(); @@ -677,8 +544,7 @@ public class ConsolidateDataService { // recherche du parametrage adequate LengthWeightParameter parametrage = - getDataService().findLengthWeightParameter( - tx, + getReferentialService().findLengthWeightParameter( species, ocean, sex, @@ -691,7 +557,7 @@ public class ConsolidateDataService { String message = t("observe.message.consolidate.no.parametrage.found", t(entityLabel), - decorate(species) + decorateEntity(species) ); if (log.isWarnEnabled()) { log.warn(message); @@ -746,7 +612,7 @@ public class ConsolidateDataService { protected void updateLengthWeightAble(Species species, LengthWeightComputable e, - LengthWeightParameter parametrage) throws DataSourceException { + LengthWeightParameter parametrage) { String entityLabel = getSpeciesLabel(); @@ -779,7 +645,7 @@ public class ConsolidateDataService { String message = t("observe.message.consolidate.no.parametrage.found", t(entityLabel), - decorate(species) + decorateEntity(species) ); if (log.isWarnEnabled()) { log.warn(message); @@ -832,6 +698,109 @@ public class ConsolidateDataService { } } + protected void computeNonTargetCatchTailleMoyenne(NonTargetCatch nonTargetCatch, + Collection<NonTargetLength> samples, + LengthWeightParameter parametrage) { + + Float meanLength = null; + NonTargetCatchComputedValueSource computedSource = null; + + if (CollectionUtils.isNotEmpty(samples)) { + + // on calcul la taille moyenne à partir des échantillons + float totalTaille = 0f; + int nbIndividus = 0; + for (NonTargetLength sample : samples) { + + Integer count = sample.getCount(); + Float length = sample.getLength(); + + if (count != null && length != null) { + nbIndividus += count; + totalTaille += length * count; + } + } + + if (nbIndividus != 0) { + + meanLength = totalTaille / nbIndividus; + + computedSource = NonTargetCatchComputedValueSource.FROM_SAMPLE; + } + } + + if (meanLength == null && parametrage != null) { + + // on prend directement la valeur fournie par le référentiel + + meanLength = parametrage.getMeanLength(); + computedSource = NonTargetCatchComputedValueSource.FROM_REFERENTIEL; + } + + if (meanLength != null) { + + // la taille moyenne a pu etre calculee, on la pousse alors + nonTargetCatch.setMeanLength(meanLength); + nonTargetCatch.setMeanLengthComputedSource(computedSource); + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); + } + + } + + private void computeNonTargetCatchNombreEstime(NonTargetCatch nonTargetCatch, + Collection<NonTargetLength> samples, + LengthWeightParameter parametrage) { + + + if (CollectionUtils.isNotEmpty(samples)) { + + // on calcul la taille moyenne à partir des échantillons + int nbIndividus = 0; + for (NonTargetLength sample : samples) { + + Integer count = sample.getCount(); + + if (count != null) { + nbIndividus += count; + } + } + + if (nbIndividus != 0) { + + nonTargetCatch.setTotalCount(nbIndividus); + nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_SAMPLE); + + if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); + } + } + } + } + + private void computeNonTargetCatchMeanValues(NonTargetCatch nonTargetCatch, + LengthWeightParameter parametrage) { + + if (parametrage != null) { + + nonTargetCatch.setMeanLength(parametrage.getMeanLength()); + nonTargetCatch.setMeanLengthComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); + + nonTargetCatch.setMeanWeight(parametrage.getMeanWeight()); + nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); + + if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { + + // on peut aussi relancer la calcul du cas n°1 + updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); + } + } + } + + //FIXME Use a simple sql query protected String[] getActivityIds(TripSeine maree) { List<String> tmpIds = new ArrayList<String>(); if (!maree.isRouteEmpty()) { @@ -851,17 +820,13 @@ public class ConsolidateDataService { return result; } - protected DataService getDataService() { - DataService service = ObserveServiceHelper.getDataService(); - return service; - } - - protected DecoratorService getDecoratorService() { - DecoratorService service = ObserveServiceHelper.getDecoratorService(); - return service; + protected boolean allNonTargetCatchDataFilled(NonTargetCatch nonTargetCatch) { + return Iterables.all( + Sets.newHashSet(nonTargetCatch.getCatchWeight(), + nonTargetCatch.getTotalCount(), + nonTargetCatch.getMeanWeight(), + nonTargetCatch.getMeanLength()), + Predicates.notNull()); } - protected SendMessageAble getMessager(SendMessageAble messager) { - return messager == null ? LOG_ESSAGER : messager; - } } diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java new file mode 100644 index 0000000..57770f9 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportService.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class GpsImportService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java new file mode 100644 index 0000000..5390ca1 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/GpsImportServiceImpl.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class GpsImportServiceImpl implements GpsImportService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java new file mode 100644 index 0000000..08234a6 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ObsoleteReferenceToReplace.java @@ -0,0 +1,111 @@ +package fr.ird.observe.services.operation; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.util.TopiaEntityRef; + +import java.util.List; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ObsoleteReferenceToReplace { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ObsoleteReferenceToReplace.class); + + /** l'id de l'entité à remplacer */ + String obsoleteId; + + /** l'id de l'entité de remplacement */ + String safeId; + + /** la liste des références à traiter */ + TopiaEntityRef[] refs; + + public String getSafeId() { + return safeId; + } + + public TopiaEntityRef[] getRefs() { + return refs; + } + + public ObsoleteReferenceToReplace(String obsoleteId, String safeId, List<TopiaEntityRef> refs) { + this.obsoleteId = obsoleteId; + this.refs = refs.toArray(new TopiaEntityRef[refs.size()]); + this.safeId = safeId; + } + + public String getObsoleteId() { + return obsoleteId; + } + +// public void doAction(TopiaContext tx) throws TopiaException { +// +// if (log.isInfoEnabled()) { +// log.info("load obsolete object " + obsoleteId); +// } +// +// if (log.isInfoEnabled()) { +// log.info("load safe object " + safeId); +// } +// +// TopiaEntity safeRef = tx.findByTopiaId(safeId); +// +// // on remplace les references +// for (TopiaEntityRef ref : refs) { +// TopiaEntity invoker = ref.getInvoker(); +// +// if (invoker == null) { +// throw new NullPointerException( +// "can not have a null invoker in " + ref); +// } +// +// if (log.isInfoEnabled()) { +// log.info("load invoker object " + invoker.getTopiaId()); +// } +// +// invoker = tx.findByTopiaId(invoker.getTopiaId()); +// +// // switch entity +// +// String path = ref.getInvokerProperty(); +// +// JXPathContext jxcontext = JXPathContext.newContext(invoker); +// +// TopiaEntity oldValue = (TopiaEntity) jxcontext.getValue(path); +// +// if (log.isDebugEnabled()) { +// log.debug("property to switch " + path + " old : " + +// oldValue); +// } +// +// if (log.isInfoEnabled()) { +// log.info("change path : " + path); +// log.info("old value : " + oldValue.getTopiaId()); +// } +// +// jxcontext.setValue(path, safeRef); +// +// TopiaEntity newValue = (TopiaEntity) jxcontext.getValue(path); +// +// if (log.isInfoEnabled()) { +// log.info("new value : " + newValue.getTopiaId()); +// } +// if (log.isDebugEnabled()) { +// log.debug("property to switch " + path + " new : " + +// safeRef); +// log.debug("property to switch " + path + " new Check : " + +// newValue); +// } +// TopiaDAO<TopiaEntity> dao = getDAO(tx, invoker); +// +// dao.update(invoker); +// } +// } + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java new file mode 100644 index 0000000..8051a13 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeService.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public interface SynchronizeService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java new file mode 100644 index 0000000..ecba6db --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/SynchronizeServiceImpl.java @@ -0,0 +1,11 @@ +package fr.ird.observe.services.operation; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since XXX + */ +public class SynchronizeServiceImpl implements SynchronizeService { + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java new file mode 100644 index 0000000..76f84b5 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationService.java @@ -0,0 +1,18 @@ +package fr.ird.observe.services.operation; + +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.services.ObserveService; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.validation.ValidationMessageDetector; + +/** + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public interface ValidationService extends ObserveService { + + void validate(SendMessageAble messager, ValidationMessageDetector detector, DataSelectionModel dataModel); + +} diff --git a/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java new file mode 100644 index 0000000..6fe70a6 --- /dev/null +++ b/observe-services/src/main/java/fr/ird/observe/services/operation/ValidationServiceImpl.java @@ -0,0 +1,94 @@ +package fr.ird.observe.services.operation; + +import fr.ird.observe.DecoratorService; +import fr.ird.observe.SendMessageAble; +import fr.ird.observe.entities.Trip; +import fr.ird.observe.entities.referentiel.Program; +import fr.ird.observe.services.AbstractObserveService; +import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.model.DataSelectionModel; +import fr.ird.observe.validation.ValidationMessageDetector; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; + +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n.t; + +/** + * //FIXME A revoir, on doit utiliser un pattern de Request, Context et Result + * //FIXME Le detector doit être interne + * Created on 5/3/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 4.0 + */ +public class ValidationServiceImpl extends AbstractObserveService implements ValidationService { + + @Override + public void validate(SendMessageAble messager, ValidationMessageDetector detector, DataSelectionModel dataModel) { + + if (dataModel.isUseReferentiel()) { + + // validation des referentiels selectionnes + + validateReferentiel(messager, detector, dataModel); + } + + if (dataModel.isUseData()) { + + // validation des donnees observateur selectionnee + + validateData(messager, detector, dataModel); + } + + } + + protected void validateData(SendMessageAble messager, + ValidationMessageDetector detector, + DataSelectionModel dataModel) { + + Set<String> tripIds = dataModel.getSelectedData(); + + TripService tripService = newService(TripService.class); + + for (String tripId : tripIds) { + + Trip trip = tripService.getTrip(tripId); + Program program = trip.getProgram(); + + messager.sendMessage(t("observe.message.validation.start.maree", decorateEntity(trip), decorateEntity(program))); + detector.detectMessages(trip); + + } + + } + + protected void validateReferentiel(SendMessageAble messager, + ValidationMessageDetector detector, + DataSelectionModel dataModel) { + + Set<Class<?>> classes = dataModel.getSelectedReferentiel(); + + for (Class<?> klass : classes) { + + Class<? extends TopiaEntity> refClass = (Class<? extends TopiaEntity>) klass; + TopiaDAO<? extends TopiaEntity> dao = getDao(refClass); + + List<String> ids = dao.findAllIds(); + String entityLabel = t(DecoratorService.getEntityLabel(klass)); + messager.sendMessage(t("observe.message.validation.start.referentiel", entityLabel, ids.size())); + + for (String id : ids) { + TopiaEntity entity = dao.findByTopiaId(id); + detector.detectMessages(entity); + } + + ids.clear(); + + } + + } + +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.