This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See http://git.codelutin.com/observe.git commit e6018f0169184bf73f2b234398f3ca4b52cfaa47 Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Apr 9 08:32:54 2015 +0200 refs #6914 ajouts de méthodes de récupération des entitiés pour la décoration de l'arbre et des listes --- .../src/main/java/fr/ird/observe/DataService.java | 397 ++++++++++++++++----- .../ird/observe/entities/constants/GearType.java | 11 + .../entities/constants/ReferenceLocale.java | 34 ++ .../entities/longline/ActivityLonglineDAOImpl.java | 118 ++++++ .../entities/longline/TripLonglineDAOImpl.java | 133 ++++++- .../entities/referentiel/ProgramDAOImpl.java | 101 ++++++ .../entities/referentiel/ReferenceEntities.java | 1 + .../entities/seine/ActivitySeineDAOImpl.java | 119 ++++++ .../entities/seine/FloatingObjectDAOImpl.java | 102 ++++++ .../ird/observe/entities/seine/RouteDAOImpl.java | 93 +++++ .../observe/entities/seine/TripSeineDAOImpl.java | 131 ++++++- 11 files changed, 1130 insertions(+), 110 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 index b86d44c..c810802 100644 --- a/observe-business/src/main/java/fr/ird/observe/DataService.java +++ b/observe-business/src/main/java/fr/ird/observe/DataService.java @@ -37,7 +37,9 @@ import fr.ird.observe.entities.OpenableEntities; import fr.ird.observe.entities.OpenableEntity; import fr.ird.observe.entities.Trip; import fr.ird.observe.entities.constants.GearType; +import fr.ird.observe.entities.constants.ReferenceLocale; import fr.ird.observe.entities.longline.ActivityLongline; +import fr.ird.observe.entities.longline.ActivityLonglineDAO; import fr.ird.observe.entities.longline.ActivityLonglines; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Branchline; @@ -56,7 +58,6 @@ import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ProgramDAO; -import fr.ird.observe.entities.referentiel.Programs; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Sex; import fr.ird.observe.entities.referentiel.Species; @@ -64,7 +65,10 @@ import fr.ird.observe.entities.referentiel.SpeciesList; import fr.ird.observe.entities.referentiel.SpeciesListDAO; import fr.ird.observe.entities.referentiel.longline.SensorType; import fr.ird.observe.entities.seine.ActivitySeine; +import fr.ird.observe.entities.seine.ActivitySeineDAO; import fr.ird.observe.entities.seine.ActivitySeines; +import fr.ird.observe.entities.seine.FloatingObject; +import fr.ird.observe.entities.seine.FloatingObjectDAO; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineImpl; import fr.ird.observe.entities.seine.GearUseFeaturesSeine; @@ -72,6 +76,7 @@ import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.entities.seine.Route; +import fr.ird.observe.entities.seine.RouteDAO; import fr.ird.observe.entities.seine.Routes; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.entities.seine.TargetCatch; @@ -109,7 +114,6 @@ import java.util.Collections; import java.util.Date; import java.util.EnumSet; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import static org.nuiton.i18n.I18n.t; @@ -129,8 +133,6 @@ public class DataService { String BEAN = "bean"; - String PROPERTY_ENABLED = "enabled"; - protected DecoratorService decoratorService; protected DataContext dataContext; @@ -483,10 +485,57 @@ public class DataService { } } + 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 List<TripSeine> getTripSeineByProgram(DataSource source, - String programId, - boolean decorateTrip) throws DataSourceException { + 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!"); @@ -494,23 +543,140 @@ public class DataService { return Collections.emptyList(); } - String txName = "getTripByProgram"; + String txName = "getTripSeineStubByProgram"; TopiaContext tx = beginTransaction(source, txName); - DecoratorService decoratorService = getDecoratorService(); - Decorator<TripSeine> decorator = null; - if (decorateTrip) { - decorator = decoratorService.getDecoratorByType(TripSeine.class); + + 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); - List<TripSeine> result = dao.findAllByProgramId(programId); - if (decorateTrip && CollectionUtils.isNotEmpty(result)) { - for (TripSeine maree : result) { - decorator.toString(maree); - } + 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 { @@ -518,10 +684,57 @@ public class DataService { } } + 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); - public List<TripLongline> getTripLonglineByProgram(DataSource source, - String programId, - boolean decorateTrip) throws DataSourceException { + 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!"); @@ -529,23 +742,68 @@ public class DataService { return Collections.emptyList(); } - String txName = "getTripByProgram"; + String txName = "getTripLonglineStubByProgram"; TopiaContext tx = beginTransaction(source, txName); - DecoratorService decoratorService = getDecoratorService(); - Decorator<TripLongline> decorator = null; - if (decorateTrip) { - decorator = decoratorService.getDecoratorByType(TripLongline.class); + + 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); - List<TripLongline> result = dao.findAllByProgramId(programId); - if (decorateTrip && CollectionUtils.isNotEmpty(result)) { - for (TripLongline maree : result) { - decorator.toString(maree); - } + 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 { @@ -553,6 +811,30 @@ public class DataService { } } + 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 { @@ -1185,61 +1467,6 @@ public class DataService { } } - - public List<Program> getClosedPrograms(DataSource source) throws DataSourceException { - List<Program> programs = getList(source, Program.class); - Iterator<Program> it = programs.iterator(); - while (it.hasNext()) { - //FIXME Do it also for Longline program - Program program = it.next(); - - - if (Programs.isProgramLongline(program)) { - List<TripLongline> mareeForProgram = - getTripLonglineByProgram(source, program.getTopiaId(), false); - - boolean add = true; - - if (mareeForProgram.isEmpty()) { - add = false; - } - for (TripLongline maree : mareeForProgram) { - if (maree.isOpen()) { - // pas fermer - add = false; - break; - } - } - - if (!add) { - it.remove(); - } - continue; - } - - if (Programs.isProgramSeine(program)) { - List<TripSeine> mareeForProgram = - getTripSeineByProgram(source, program.getTopiaId(), false); - boolean add = true; - if (mareeForProgram.isEmpty()) { - add = false; - } - for (TripSeine maree : mareeForProgram) { - if (maree.isOpen()) { - // pas fermer - add = false; - break; - } - } - if (!add) { - it.remove(); - } - } - - } - return programs; - } - public List<Program> getPossibleProgramsForTrip(DataSource source, String tripId) throws DataSourceException { final GearType gearType; diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/constants/GearType.java b/observe-entities/src/main/java/fr/ird/observe/entities/constants/GearType.java index be373df..26f07f9 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/constants/GearType.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/constants/GearType.java @@ -53,4 +53,15 @@ public enum GearType { public String toString() { return t(i18nKey); } + + public static GearType fromOrdinal(int ordinal) { + + GearType result = null; + for (GearType gearType : values()) { + if (ordinal == gearType.ordinal()) { + result = gearType; + } + } + return result; + } } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/constants/ReferenceLocale.java b/observe-entities/src/main/java/fr/ird/observe/entities/constants/ReferenceLocale.java index e5a8b8b..b3f053f 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/constants/ReferenceLocale.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/constants/ReferenceLocale.java @@ -84,9 +84,43 @@ public enum ReferenceLocale { "could not find referentiel locale from locale " + locale); } + public String getColumnName() { + return "label"+(ordinal() + 1); + } @Override public String toString() { return "<Locale: " + locale + ", index: " + name() + ">"; } + + public <E extends I18nReferenceEntity> void setLabel(String label, E i18nEntity) { + + switch (ordinal()+1) { + case 1: + i18nEntity.setLabel1(label); + break; + case 2: + i18nEntity.setLabel2(label); + break; + case 3: + i18nEntity.setLabel3(label); + break; + case 4: + i18nEntity.setLabel4(label); + break; + case 5: + i18nEntity.setLabel5(label); + break; + case 6: + i18nEntity.setLabel6(label); + break; + case 7: + i18nEntity.setLabel7(label); + break; + case 8: + i18nEntity.setLabel8(label); + break; + } + + } } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineDAOImpl.java new file mode 100644 index 0000000..af76d68 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/ActivityLonglineDAOImpl.java @@ -0,0 +1,118 @@ +package fr.ird.observe.entities.longline; + +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.longline.VesselActivityLongline; +import fr.ird.observe.entities.referentiel.longline.VesselActivityLonglineImpl; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class ActivityLonglineDAOImpl<E extends ActivityLongline> extends ActivityLonglineDAOAbstract<E> { + + public List<E> findAllStubByTripId(String tripId, ReferenceLocale referenceLocale) throws TopiaException { + + List<E> result = StubSqlQuery.findAll(context, tripId, referenceLocale); + return result; + + } + + public E findStubByTopiaId(String activityId, ReferenceLocale referenceLocale) throws TopiaException { + + E result = StubSqlQuery.find(context, activityId, referenceLocale); + return result; + + } + + private static class StubSqlQuery<E extends ActivityLongline> extends TopiaSQLQuery<E> { + + private final String sql; + + private final String id; + + private final ReferenceLocale referenceLocale; + + public static <E extends ActivityLongline> List<E> findAll(TopiaContextImplementor context, String tripId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " a.topiaId," + + " a.timestamp," + + " a.open," + + " a.set," + + " va." + referenceLocale.getColumnName() + + " FROM observe_longline.activity a, observe_longline.vesselactivity va" + + " WHERE " + + " a.trip = ?" + + " AND a.vesselactivity = va.topiaid" + + " ORDER BY a.timestamp"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, tripId, referenceLocale); + return request.findMultipleResult(context); + + } + + public static <E extends ActivityLongline> E find(TopiaContextImplementor context, String activityId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " a.topiaId," + + " a.timestamp," + + " a.open," + + " a.set," + + " va." + referenceLocale.getColumnName() + + " FROM observe_longline.activity a, observe_longline.vesselactivity va" + + " WHERE " + + " a.topiaId = ?" + + " AND a.vesselactivity = va.topiaid" + + " ORDER BY a.timestamp"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, activityId, referenceLocale); + return request.findSingleResult(context); + + } + + StubSqlQuery(String sql, String id, ReferenceLocale referenceLocale) { + this.sql = sql; + this.id = id; + this.referenceLocale = referenceLocale; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, id); + return preparedStatement; + } + + @Override + protected E prepareResult(ResultSet set) throws SQLException { + + E activity = (E) new ActivityLonglineImpl(); + activity.setTopiaId(set.getString(1)); + activity.setTimeStamp(set.getTimestamp(2)); + activity.setOpen(set.getBoolean(3)); + + String setId = set.getString(4); + if (setId != null) { + + SetLonglineImpl setLongline = new SetLonglineImpl(); + setLongline.setTopiaId(setId); + activity.setSetLongline(setLongline); + + } + VesselActivityLongline vesselActivity = new VesselActivityLonglineImpl(); + String label = set.getString(5); + referenceLocale.setLabel(label, vesselActivity); + activity.setVesselActivityLongline(vesselActivity); + + return activity; + + } + + } + +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineDAOImpl.java index 1fe43dd..525361b 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/longline/TripLonglineDAOImpl.java @@ -22,27 +22,26 @@ package fr.ird.observe.entities.longline; * #L% */ -import fr.ird.observe.entities.seine.TripSeine; +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.Person; +import fr.ird.observe.entities.referentiel.PersonImpl; +import fr.ird.observe.entities.referentiel.Vessel; +import fr.ird.observe.entities.referentiel.VesselImpl; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.List; public class TripLonglineDAOImpl<E extends TripLongline> extends TripLonglineDAOAbstract<E> { - - public List<E> findAllByProgramId(String programId) throws TopiaException { - TopiaQuery query = createQuery(); - query.addOrder(TripSeine.PROPERTY_END_DATE); - query.addEquals(TripSeine.PROPERTY_PROGRAM + "." + TopiaEntity.TOPIA_ID, programId); - List<E> result = findAllByQuery(query); - return result; - } - public int findPositionByProgramId(String programId, String tripId) throws TopiaException { int result = 0; - List<E> list = findAllByProgramId(programId); + List<E> list = findAllStubByProgramId(programId, ReferenceLocale.FR); for (E e : list) { if (tripId.equals(e.getTopiaId())) { return result; @@ -54,4 +53,110 @@ public class TripLonglineDAOImpl<E extends TripLongline> extends TripLonglineDAO return -1; } -} //TripLonglineDAOImpl<E extends TripLongline> + public List<E> findAllStubByProgramId(String programId, ReferenceLocale referenceLocale) throws TopiaException { + + List<E> result = StubSqlQuery.findAll(context, programId, referenceLocale); + return result; + + } + + public E findStubByTopiaId(String tripId, ReferenceLocale referenceLocale) throws TopiaException { + + E result = StubSqlQuery.find(context, tripId, referenceLocale); + return result; + + } + + private static class StubSqlQuery<E extends TripLongline> extends TopiaSQLQuery<E> { + + private final String sql; + + private final String id; + + private final ReferenceLocale referenceLocale; + + StubSqlQuery(String sql, String id, ReferenceLocale referenceLocale) { + this.sql = sql; + this.id = id; + this.referenceLocale = referenceLocale; + } + + public static <E extends TripLongline> List<E> findAll(TopiaContextImplementor context, String programId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " t.topiaId," + + " t.startDate," + + " t.endDate," + + " t.open," + + " p.lastName," + + " p.firstName," + + " v." + referenceLocale.getColumnName() + + " FROM observe_longline.trip t, observe_common.person p, observe_common.vessel v" + + " WHERE " + + " t.program = ?" + + " AND t.observer = p.topiaId" + + " AND t.vessel = v.topiaId" + + " ORDER BY t.endDate"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, programId, referenceLocale); + return request.findMultipleResult(context); + + } + + public static <E extends TripLongline> E find(TopiaContextImplementor context, String tripId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " t.topiaId," + + " t.startDate," + + " t.endDate," + + " t.open," + + " p.lastName," + + " p.firstName," + + " v." + referenceLocale.getColumnName() + + " FROM observe_longline.trip t, observe_common.person p, observe_common.vessel v" + + " WHERE " + + " t.topiaId = ?" + + " AND t.observer = p.topiaId" + + " AND t.vessel = v.topiaId" + + " ORDER BY t.endDate"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, tripId, referenceLocale); + return request.findSingleResult(context); + + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, id); + return preparedStatement; + } + + @Override + protected E prepareResult(ResultSet set) throws SQLException { + + E trip = (E) new TripLonglineImpl(); + trip.setTopiaId(set.getString(1)); + trip.setStartDate(set.getTimestamp(2)); + trip.setEndDate(set.getTimestamp(3)); + trip.setOpen(set.getBoolean(4)); + + String observerFirstName = set.getString(5); + String observerLastName = set.getString(6); + Person observer = new PersonImpl(); + observer.setFirstName(observerFirstName); + observer.setLastName(observerLastName); + trip.setObserver(observer); + + Vessel vessel = new VesselImpl(); + String label = set.getString(7); + referenceLocale.setLabel(label, vessel); + trip.setVessel(vessel); + + return trip; + + } + + } + +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ProgramDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ProgramDAOImpl.java new file mode 100644 index 0000000..7638768 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ProgramDAOImpl.java @@ -0,0 +1,101 @@ +package fr.ird.observe.entities.referentiel; + +import fr.ird.observe.entities.constants.GearType; +import fr.ird.observe.entities.constants.ReferenceLocale; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class ProgramDAOImpl<E extends Program> extends ProgramDAOAbstract<E> { + + public List<E> findAllStub(ReferenceLocale referenceLocale) throws TopiaException { + List<E> result = StubSqlQuery.findAll(context, referenceLocale); + return result; + + } + + public Program findStubByTopiaId(String programId, ReferenceLocale referentielLocale) throws TopiaException { + return StubSqlQuery.find(context, programId, referentielLocale); + } + + + private static class StubSqlQuery<E extends Program> extends TopiaSQLQuery<E> { + + private final String sql; + + private final String id; + + private final ReferenceLocale referenceLocale; + + static <E extends Program> List<E> findAll(TopiaContextImplementor context, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " p.topiaId," + + " p.gearType," + + " p." + referenceLocale.getColumnName() + + " FROM observe_common.program p" + + " ORDER BY p." + referenceLocale.getColumnName(); + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, null, referenceLocale); + return request.findMultipleResult(context); + + } + + static <E extends Program> E find(TopiaContextImplementor context, String tripId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " p.topiaId," + + " p.gearType," + + " p." + referenceLocale.getColumnName() + + " FROM observe_common.program p" + + " WHERE " + + " p.topiaId = ?" + + " ORDER BY p." + referenceLocale.getColumnName(); + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, tripId, referenceLocale); + return request.findSingleResult(context); + + } + + StubSqlQuery(String sql, String id, ReferenceLocale referenceLocale) { + this.sql = sql; + this.id = id; + this.referenceLocale = referenceLocale; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement preparedStatement = connection.prepareStatement(sql); + if (id != null) { + preparedStatement.setString(1, id); + } + return preparedStatement; + } + + @Override + protected E prepareResult(ResultSet set) throws SQLException { + + E program = (E) new ProgramImpl(); + program.setTopiaId(set.getString(1)); + + int gearTypeOrdinal = set.getInt(2); + GearType gearType = GearType.fromOrdinal(gearTypeOrdinal); + program.setGearType(gearType); + + String label = set.getString(3); + referenceLocale.setLabel(label, program); + + return program; + + } + + } + + +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java index 2f225bf..35ff744 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/referentiel/ReferenceEntities.java @@ -118,4 +118,5 @@ public class ReferenceEntities { <E extends TopiaEntity> void walk(Class<E> beanClass) throws Exception; } + } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineDAOImpl.java new file mode 100644 index 0000000..b82bfe7 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/ActivitySeineDAOImpl.java @@ -0,0 +1,119 @@ +package fr.ird.observe.entities.seine; + +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; +import fr.ird.observe.entities.referentiel.seine.VesselActivitySeineImpl; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class ActivitySeineDAOImpl<E extends ActivitySeine> extends ActivitySeineDAOAbstract<E> { + + public List<E> findAllStubByRouteId(String routeId, ReferenceLocale referenceLocale) throws TopiaException { + + List<E> result = StubSqlQuery.findAll(context, routeId, referenceLocale); + return result; + + } + + public E findStubByTopiaId(String activityId, ReferenceLocale referenceLocale) throws TopiaException { + + E result = StubSqlQuery.find(context, activityId, referenceLocale); + return result; + + } + + private static class StubSqlQuery<E extends ActivitySeine> extends TopiaSQLQuery<E> { + + private final String sql; + + private final String id; + + private final ReferenceLocale referenceLocale; + + static <E extends ActivitySeine> List<E> findAll(TopiaContextImplementor context, String routeId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " a.topiaId," + + " a.time," + + " a.open," + + " a.set," + + " va." + referenceLocale.getColumnName() + + " FROM observe_seine.activity a, observe_seine.vesselactivity va" + + " WHERE " + + " a.route = ?" + + " AND a.vesselactivity = va.topiaid" + + " ORDER BY a.time"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, routeId, referenceLocale); + return request.findMultipleResult(context); + + } + + static <E extends ActivitySeine> E find(TopiaContextImplementor context, String activityId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " a.topiaId," + + " a.time," + + " a.open," + + " a.set," + + " va." + referenceLocale.getColumnName() + + " FROM observe_seine.activity a, observe_seine.vesselactivity va" + + " WHERE " + + " a.topiaId = ?" + + " AND a.vesselactivity = va.topiaid" + + " ORDER BY a.time"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, activityId, referenceLocale); + return request.findSingleResult(context); + + } + + StubSqlQuery(String sql, String id, ReferenceLocale referenceLocale) { + this.sql = sql; + this.id = id; + this.referenceLocale = referenceLocale; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, id); + return preparedStatement; + } + + @Override + protected E prepareResult(ResultSet set) throws SQLException { + + E activity = (E) new ActivitySeineImpl(); + activity.setTopiaId(set.getString(1)); + activity.setTime(set.getTime(2)); + activity.setOpen(set.getBoolean(3)); + + String setId = set.getString(4); + if (setId != null) { + + SetSeine setSeine = new SetSeineImpl(); + setSeine.setTopiaId(setId); + activity.setSetSeine(setSeine); + + } + + VesselActivitySeine vesselActivity = new VesselActivitySeineImpl(); + String label = set.getString(5); + referenceLocale.setLabel(label, vesselActivity); + activity.setVesselActivitySeine(vesselActivity); + + return activity; + + } + + } + +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/FloatingObjectDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/FloatingObjectDAOImpl.java new file mode 100644 index 0000000..07a1c20 --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/FloatingObjectDAOImpl.java @@ -0,0 +1,102 @@ +package fr.ird.observe.entities.seine; + +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.seine.ObjectType; +import fr.ird.observe.entities.referentiel.seine.ObjectTypeImpl; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class FloatingObjectDAOImpl<E extends FloatingObject> extends FloatingObjectDAOAbstract<E> { + + public List<E> findAllStubByActivityId(String activityId, ReferenceLocale referenceLocale) throws TopiaException { + + List<E> result = StubSqlQuery.findAll(context, activityId, referenceLocale); + return result; + + } + + public E findStubByTopiaId(String floatingObjectId, ReferenceLocale referenceLocale) throws TopiaException { + + E result = StubSqlQuery.find(context, floatingObjectId, referenceLocale); + return result; + + } + + private static class StubSqlQuery<E extends FloatingObject> extends TopiaSQLQuery<E> { + + private final String sql; + + private final String id; + + private final ReferenceLocale referenceLocale; + + static <E extends FloatingObject> List<E> findAll(TopiaContextImplementor context, String activityId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " fo.topiaId," + + " ot." + referenceLocale.getColumnName() + + " FROM observe_seine.floatingobject fo, observe_seine.objecttype ot" + + " WHERE " + + " fo.activity = ?" + + " AND fo.objecttype = ot.topiaid" + + " ORDER BY ot." + referenceLocale.getColumnName(); + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, activityId, referenceLocale); + return request.findMultipleResult(context); + + } + + static <E extends FloatingObject> E find(TopiaContextImplementor context, String floatingObjectId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " fo.topiaId," + + " ot." + referenceLocale.getColumnName() + + " FROM observe_seine.floatingobject fo, observe_seine.objecttype ot" + + " WHERE " + + " fo.topiaId = ?" + + " AND fo.objecttype = ot.topiaid" + + " ORDER BY ot." + referenceLocale.getColumnName(); + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, floatingObjectId, referenceLocale); + return request.findSingleResult(context); + + } + + StubSqlQuery(String sql, String id, ReferenceLocale referenceLocale) { + this.sql = sql; + this.id = id; + this.referenceLocale = referenceLocale; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, id); + return preparedStatement; + } + + @Override + protected E prepareResult(ResultSet set) throws SQLException { + + E floatingObject = (E) new FloatingObjectImpl(); + floatingObject.setTopiaId(set.getString(1)); + + String objectTypeLabel = set.getString(2); + ObjectType objectType = new ObjectTypeImpl(); + referenceLocale.setLabel(objectTypeLabel, objectType); + floatingObject.setObjectType(objectType); + + return floatingObject; + + } + + } + +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/RouteDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/RouteDAOImpl.java new file mode 100644 index 0000000..acbcf9d --- /dev/null +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/RouteDAOImpl.java @@ -0,0 +1,93 @@ +package fr.ird.observe.entities.seine; + +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +public class RouteDAOImpl<E extends Route> extends RouteDAOAbstract<E> { + + public List<E> findAllStubByTripId(String tripSeineId) throws TopiaException { + + List<E> result = StubSqlQuery.findAll(context, tripSeineId); + return result; + + } + + public E findStubByTopiaId(String routeId) throws TopiaException { + + E result = StubSqlQuery.find(context, routeId); + return result; + + } + + + private static class StubSqlQuery<E extends Route> extends TopiaSQLQuery<E> { + + private final String sql; + + private final String id; + + static <E extends Route> List<E> findAll(TopiaContextImplementor context, String tripSeineId) throws TopiaException { + + String sql = "SELECT" + + " r.topiaId," + + " r.date," + + " r.open" + + " FROM observe_seine.route r" + + " WHERE " + + " r.trip = ?" + + " ORDER BY r.date"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, tripSeineId); + return request.findMultipleResult(context); + + } + + static <E extends Route> E find(TopiaContextImplementor context, String routeId) throws TopiaException { + + String sql = "SELECT" + + " r.topiaId," + + " r.date," + + " r.open" + + " FROM observe_seine.route r" + + " WHERE " + + " r.topiaId = ?" + + " ORDER BY r.date"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, routeId); + return request.findSingleResult(context); + + } + + StubSqlQuery(String sql, String id) { + this.id = id; + this.sql = sql; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, id); + return preparedStatement; + } + + @Override + protected E prepareResult(ResultSet set) throws SQLException { + + E trip = (E) new RouteImpl(); + trip.setTopiaId(set.getString(1)); + trip.setDate(set.getDate(2)); + trip.setOpen(set.getBoolean(3)); + + return trip; + + } + } + +} diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/seine/TripSeineDAOImpl.java b/observe-entities/src/main/java/fr/ird/observe/entities/seine/TripSeineDAOImpl.java index 6d83733..08a63a9 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/seine/TripSeineDAOImpl.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/seine/TripSeineDAOImpl.java @@ -21,10 +21,19 @@ */ package fr.ird.observe.entities.seine; +import fr.ird.observe.entities.constants.ReferenceLocale; +import fr.ird.observe.entities.referentiel.Person; +import fr.ird.observe.entities.referentiel.PersonImpl; +import fr.ird.observe.entities.referentiel.Vessel; +import fr.ird.observe.entities.referentiel.VesselImpl; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.List; /** @@ -35,17 +44,9 @@ import java.util.List; */ public class TripSeineDAOImpl<E extends TripSeine> extends TripSeineDAOAbstract<E> { - public List<E> findAllByProgramId(String programId) throws TopiaException { - TopiaQuery query = createQuery(); - query.addOrder(TripSeine.PROPERTY_END_DATE); - query.addEquals(TripSeine.PROPERTY_PROGRAM + "." + TopiaEntity.TOPIA_ID, programId); - List<E> result = findAllByQuery(query); - return result; - } - public int findPositionByProgramId(String programId, String tripId) throws TopiaException { int result = 0; - List<E> list = findAllByProgramId(programId); + List<E> list = findAllStubByProgramId(programId, ReferenceLocale.FR); for (E e : list) { if (tripId.equals(e.getTopiaId())) { return result; @@ -56,4 +57,112 @@ public class TripSeineDAOImpl<E extends TripSeine> extends TripSeineDAOAbstract< // not found return -1; } + + public List<E> findAllStubByProgramId(String programId, ReferenceLocale referenceLocale) throws TopiaException { + + List<E> result = StubSqlQuery.findAll(context, programId, referenceLocale); + return result; + + } + + public E findStubByTopiaId(String tripId, ReferenceLocale referenceLocale) throws TopiaException { + + E result = StubSqlQuery.find(context, tripId, referenceLocale); + return result; + + } + + private static class StubSqlQuery<E extends TripSeine> extends TopiaSQLQuery<E> { + + private final String sql; + + private final String id; + + private final ReferenceLocale referenceLocale; + + static <E extends TripSeine> List<E> findAll(TopiaContextImplementor context, String programId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " t.topiaId," + + " t.startDate," + + " t.endDate," + + " t.open," + + " p.lastName," + + " p.firstName," + + " v." + referenceLocale.getColumnName() + + " FROM observe_seine.trip t, observe_common.person p, observe_common.vessel v" + + " WHERE " + + " t.program = ?" + + " AND t.observer = p.topiaId" + + " AND t.vessel = v.topiaId" + + " ORDER BY t.endDate"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, programId, referenceLocale); + return request.findMultipleResult(context); + + } + + static <E extends TripSeine> E find(TopiaContextImplementor context, String tripId, ReferenceLocale referenceLocale) throws TopiaException { + + String sql = "SELECT" + + " t.topiaId," + + " t.startDate," + + " t.endDate," + + " t.open," + + " p.lastName," + + " p.firstName," + + " v." + referenceLocale.getColumnName() + + " FROM observe_seine.trip t, observe_common.person p, observe_common.vessel v" + + " WHERE " + + " t.topiaId = ?" + + " AND t.observer = p.topiaId" + + " AND t.vessel = v.topiaId" + + " ORDER BY t.endDate"; + + StubSqlQuery<E> request = new StubSqlQuery<E>(sql, tripId, referenceLocale); + return request.findSingleResult(context); + + } + + StubSqlQuery(String sql, String id, ReferenceLocale referenceLocale) { + this.sql = sql; + this.id = id; + this.referenceLocale = referenceLocale; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + PreparedStatement preparedStatement = connection.prepareStatement(sql); + preparedStatement.setString(1, id); + return preparedStatement; + } + + @Override + protected E prepareResult(ResultSet set) throws SQLException { + + E trip = (E) new TripSeineImpl(); + + trip.setTopiaId(set.getString(1)); + trip.setStartDate(set.getDate(2)); + trip.setEndDate(set.getDate(3)); + trip.setOpen(set.getBoolean(4)); + + String observerFirstName = set.getString(5); + String observerLastName = set.getString(6); + Person observer = new PersonImpl(); + observer.setFirstName(observerFirstName); + observer.setLastName(observerLastName); + trip.setObserver(observer); + + Vessel vessel = new VesselImpl(); + String label = set.getString(7); + referenceLocale.setLabel(label, vessel); + trip.setVessel(vessel); + + return trip; + + } + + } + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.