Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
90bb94b5
by Tony Chemit at 2022-01-19T16:20:06+01:00
30 changed files:
- models/persistence/java/src/main/java/fr/ird/observe/entities/ObserveTopiaApplicationContext.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/ObserveTopiaPersistenceContext.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/common/GearUseFeaturesSpi.java
- + models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/common/TripGearUseFeaturesSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/common/TripSpi.java
- − models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/common/TripTopiaDao.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/logbook/ActivitySampleSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/logbook/SetSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/observation/BranchlineSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/observation/SetDetailCompositionSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/observation/SetSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/common/GearUseFeaturesSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/localmarket/BatchSpi.java → models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/common/TripBatchSpi.java
- + models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/common/TripGearUseFeaturesSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/common/TripSpi.java
- − models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/common/TripTopiaDao.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/localmarket/SurveySpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/logbook/RouteSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/observation/RouteSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/observation/SampleSpi.java
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ps/observation/SetSpi.java
- models/persistence/test/src/test/java/fr/ird/observe/persistence/test/impl/ObserveTopiaPersistenceContextTest.java
- models/persistence/test/src/test/java/fr/ird/observe/persistence/test/impl/TestGetParent.java
- services/local/pom.xml
- services/local/src/main/java/fr/ird/observe/services/local/service/ObserveServiceLocal.java
- services/local/src/main/java/fr/ird/observe/services/local/service/data/ll/common/TripServiceLocalSupport.java
- services/local/src/main/java/fr/ird/observe/services/local/service/data/ps/common/TripServiceLocalSupport.java
- services/local/src/main/java/fr/ird/observe/services/local/service/internal/ContainerServiceLocalSupport.java
- services/local/src/main/java/fr/ird/observe/services/local/service/internal/ValidateServiceLocalSupport.java
- services/validation-spi/src/main/java/fr/ird/observe/validation/EntityInterceptors.java
Changes:
| ... | ... | @@ -58,7 +58,7 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat |
| 58 | 58 | |
| 59 | 59 | public ObserveTopiaPersistenceContext newPersistenceContext(Consumer<ObserveTopiaPersistenceContext> onPreClose) {
|
| 60 | 60 | ObserveTopiaPersistenceContext persistenceContext = newPersistenceContext();
|
| 61 | - if (onPreClose!=null) {
|
|
| 61 | + if (onPreClose != null) {
|
|
| 62 | 62 | persistenceContext.setOnPreClose(onPreClose);
|
| 63 | 63 | }
|
| 64 | 64 | return persistenceContext;
|
| ... | ... | @@ -76,7 +76,8 @@ public class ObserveTopiaApplicationContext extends AbstractObserveTopiaApplicat |
| 76 | 76 | getTopiaEntitySqlModelSupport(),
|
| 77 | 77 | this,
|
| 78 | 78 | getTopiaUsageModel(),
|
| 79 | - getConfiguration()
|
|
| 79 | + getConfiguration(),
|
|
| 80 | + getDaoMapping()
|
|
| 80 | 81 | )
|
| 81 | 82 | );
|
| 82 | 83 | registerPersistenceContext(persistenceContext);
|
| ... | ... | @@ -28,7 +28,6 @@ import fr.ird.observe.dto.data.ps.dcp.SimplifiedObjectTypeSpecializedRules; |
| 28 | 28 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 29 | 29 | import fr.ird.observe.dto.report.Report;
|
| 30 | 30 | import fr.ird.observe.dto.report.ReportRequestExecutor;
|
| 31 | -import fr.ird.observe.entities.data.RootOpenableEntity;
|
|
| 32 | 31 | import fr.ird.observe.entities.data.ps.dcp.SimplifiedObjectTypeManagerFactory;
|
| 33 | 32 | import fr.ird.observe.spi.context.OpenableDtoEntityContext;
|
| 34 | 33 | import fr.ird.observe.spi.navigation.parent.ObserveToParentIdProvider;
|
| ... | ... | @@ -36,30 +35,19 @@ import fr.ird.observe.spi.navigation.parent.ObserveToParentIdProviderImpl; |
| 36 | 35 | import fr.ird.observe.spi.report.ObserveDefaultReportRequestExecutor;
|
| 37 | 36 | import org.apache.logging.log4j.LogManager;
|
| 38 | 37 | import org.apache.logging.log4j.Logger;
|
| 39 | -import org.hibernate.SessionFactory;
|
|
| 40 | -import org.nuiton.topia.persistence.TopiaDao;
|
|
| 41 | 38 | import org.nuiton.topia.persistence.TopiaEntity;
|
| 42 | -import org.nuiton.topia.persistence.TopiaException;
|
|
| 43 | -import org.nuiton.topia.persistence.internal.AbstractTopiaDao;
|
|
| 44 | 39 | import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContextConstructorParameter;
|
| 45 | -import org.nuiton.topia.persistence.metadata.TopiaMetadataModel;
|
|
| 46 | 40 | import org.nuiton.topia.persistence.script.SqlScriptReader;
|
| 47 | 41 | |
| 48 | -import java.lang.reflect.InvocationTargetException;
|
|
| 49 | 42 | import java.sql.Timestamp;
|
| 50 | 43 | import java.util.Date;
|
| 51 | -import java.util.Locale;
|
|
| 52 | 44 | import java.util.Map;
|
| 53 | -import java.util.Objects;
|
|
| 54 | -import java.util.function.Consumer;
|
|
| 55 | 45 | import java.util.function.Supplier;
|
| 56 | 46 | |
| 57 | 47 | public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersistenceContext {
|
| 58 | 48 | |
| 59 | 49 | private static final Logger log = LogManager.getLogger(ObserveTopiaPersistenceContext.class);
|
| 60 | 50 | |
| 61 | - private Consumer<ObserveTopiaPersistenceContext> onPreClose;
|
|
| 62 | - |
|
| 63 | 51 | public ObserveTopiaPersistenceContext(AbstractTopiaPersistenceContextConstructorParameter parameter) {
|
| 64 | 52 | super(parameter);
|
| 65 | 53 | throw new IllegalStateException("Can't use this constructor!");
|
| ... | ... | @@ -93,50 +81,8 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste |
| 93 | 81 | }
|
| 94 | 82 | |
| 95 | 83 | @Override
|
| 96 | - public <E extends TopiaEntity> TopiaDao<E> getDao(Class<E> entityClass) {
|
|
| 97 | - |
|
| 98 | - SessionFactory hibernateFactory = hibernateSupport.getHibernateFactory();
|
|
| 99 | - Objects.requireNonNull(hibernateFactory, "The Hibernate SessionFactory is null, please initialize");
|
|
| 100 | - |
|
| 101 | - @SuppressWarnings("unchecked") TopiaDao<E> dao = (TopiaDao<E>) daoCache.get(entityClass);
|
|
| 102 | - if (dao == null) {
|
|
| 103 | - |
|
| 104 | - // Looking for specialized DAO
|
|
| 105 | - // This DAO is supposed to exist, as created by generation
|
|
| 106 | - String daoClassName = entityClass.getName() + "TopiaDao";
|
|
| 107 | - try {
|
|
| 108 | - @SuppressWarnings("unchecked") Class<TopiaDao<E>> daoClass = (Class<TopiaDao<E>>) Class.forName(daoClassName);
|
|
| 109 | - dao = daoClass.getConstructor().newInstance();
|
|
| 110 | - } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
|
| 111 | - log.fatal("Unable to instantiate DAO class " + daoClassName, e);
|
|
| 112 | - throw new TopiaException("unable to instantiate DAO class " + daoClassName, e);
|
|
| 113 | - } catch (ClassNotFoundException e) {
|
|
| 114 | - log.fatal("Unable to find DAO class " + daoClassName, e);
|
|
| 115 | - throw new TopiaException("unable to find DAO class " + daoClassName, e);
|
|
| 116 | - }
|
|
| 117 | - if (dao instanceof AbstractTopiaDao) {
|
|
| 118 | - AbstractTopiaDao<?> abstractTopiaDao = (AbstractTopiaDao<?>) dao;
|
|
| 119 | - abstractTopiaDao.init(jpaSupport, hibernateSupport, sqlSupport, topiaIdFactory, firesSupport, this);
|
|
| 120 | - }
|
|
| 121 | - daoCache.put(entityClass, dao);
|
|
| 122 | - }
|
|
| 123 | - return dao;
|
|
| 124 | - }
|
|
| 125 | - |
|
| 126 | - |
|
| 127 | - @Override
|
|
| 128 | - public void close() {
|
|
| 129 | - try {
|
|
| 130 | - if (onPreClose != null) {
|
|
| 131 | - onPreClose.accept(this);
|
|
| 132 | - }
|
|
| 133 | - } finally {
|
|
| 134 | - super.close();
|
|
| 135 | - }
|
|
| 136 | - }
|
|
| 137 | - |
|
| 138 | - public void setOnPreClose(Consumer<ObserveTopiaPersistenceContext> onPreClose) {
|
|
| 139 | - this.onPreClose = Objects.requireNonNull(onPreClose);
|
|
| 84 | + public <E extends TopiaEntity> ToolkitTopiaDao<E> getDao(Class<E> entityClass) {
|
|
| 85 | + return (ToolkitTopiaDao<E>) super.getDao(entityClass);
|
|
| 140 | 86 | }
|
| 141 | 87 | |
| 142 | 88 | @Override
|
| ... | ... | @@ -154,16 +100,6 @@ public class ObserveTopiaPersistenceContext extends AbstractObserveTopiaPersiste |
| 154 | 100 | };
|
| 155 | 101 | }
|
| 156 | 102 | |
| 157 | - @Override
|
|
| 158 | - public <E extends Entity> E getSingleAssociationParent(Locale locale, Class<E> associationContainerType, String associationName, String associationId) {
|
|
| 159 | - TopiaMetadataModel metadataModel = getMetadataModel();
|
|
| 160 | - if (RootOpenableEntity.class.isAssignableFrom(associationContainerType)) {
|
|
| 161 | - throw new IllegalStateException(String.format("Can't get parent of a RootOpenableEntity: %s", associationContainerType.getName()));
|
|
| 162 | - }
|
|
| 163 | - String parentId = metadataModel.getSingleAssociationParentId(getSqlSupport(), associationContainerType, associationName, associationId);
|
|
| 164 | - return getAssociationParent(locale, associationContainerType, associationName, associationId, parentId);
|
|
| 165 | - }
|
|
| 166 | - |
|
| 167 | 103 | public void applyPairing(OpenableDtoEntityContext<?, ?, ?, ?, ?> spi, Date now, Map<String, String> activityMapping) {
|
| 168 | 104 | //FIXME Loosing timeZone ?
|
| 169 | 105 | Timestamp t = new Timestamp(now.getTime());
|
| ... | ... | @@ -26,8 +26,6 @@ import fr.ird.observe.entities.referential.common.GearCharacteristic; |
| 26 | 26 | import fr.ird.observe.spi.decoration.ObserveI18nLabelsBuilder;
|
| 27 | 27 | import org.apache.commons.lang3.tuple.Pair;
|
| 28 | 28 | |
| 29 | -import java.util.Date;
|
|
| 30 | -import java.util.function.BiConsumer;
|
|
| 31 | 29 | import java.util.stream.Collectors;
|
| 32 | 30 | |
| 33 | 31 | /**
|
| ... | ... | @@ -52,13 +50,4 @@ public class GearUseFeaturesSpi extends GeneratedGearUseFeaturesSpi { |
| 52 | 50 | return String.format("( %s - %s%s = %s )", codeLabel, gearCharacteristic.getLabel2(), unitLabel, measurementValue);
|
| 53 | 51 | }
|
| 54 | 52 | |
| 55 | - @Override
|
|
| 56 | - public BiConsumer<Trip, Date> saveCallback() {
|
|
| 57 | - return (e, lastUpdateDate) -> {
|
|
| 58 | - for (GearUseFeatures features : e.getGearUseFeatures()) {
|
|
| 59 | - features.setLastUpdateDate(lastUpdateDate);
|
|
| 60 | - features.getGearUseFeaturesMeasurement().forEach(measurement -> measurement.setLastUpdateDate(lastUpdateDate));
|
|
| 61 | - }
|
|
| 62 | - };
|
|
| 63 | - }
|
|
| 64 | 53 | } |
| 1 | +package fr.ird.observe.entities.data.ll.common;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Models :: Persistence :: Java
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Code Lutin, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import java.util.Date;
|
|
| 26 | +import java.util.function.BiConsumer;
|
|
| 27 | + |
|
| 28 | +public class TripGearUseFeaturesSpi extends GeneratedTripGearUseFeaturesSpi {
|
|
| 29 | + |
|
| 30 | + @Override
|
|
| 31 | + public BiConsumer<Trip, Date> saveCallback() {
|
|
| 32 | + return (e, lastUpdateDate) -> {
|
|
| 33 | + for (GearUseFeatures features : e.getGearUseFeatures()) {
|
|
| 34 | + features.setLastUpdateDate(lastUpdateDate);
|
|
| 35 | + features.getGearUseFeaturesMeasurement().forEach(measurement -> measurement.setLastUpdateDate(lastUpdateDate));
|
|
| 36 | + }
|
|
| 37 | + };
|
|
| 38 | + }
|
|
| 39 | +} |
| ... | ... | @@ -31,7 +31,6 @@ import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet; |
| 31 | 31 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 32 | 32 | import fr.ird.observe.dto.referential.common.SpeciesReference;
|
| 33 | 33 | import fr.ird.observe.dto.referential.ll.common.VesselActivityReference;
|
| 34 | -import fr.ird.observe.entities.ObserveTopiaPersistenceContextSupport;
|
|
| 35 | 34 | import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 36 | 35 | import fr.ird.observe.entities.referential.common.Ocean;
|
| 37 | 36 | import fr.ird.observe.entities.referential.common.Species;
|
| ... | ... | @@ -43,6 +42,8 @@ import org.apache.logging.log4j.Logger; |
| 43 | 42 | |
| 44 | 43 | import java.util.Date;
|
| 45 | 44 | import java.util.LinkedHashSet;
|
| 45 | +import java.util.Map;
|
|
| 46 | +import java.util.Objects;
|
|
| 46 | 47 | import java.util.stream.Stream;
|
| 47 | 48 | |
| 48 | 49 | /**
|
| ... | ... | @@ -160,15 +161,34 @@ public class TripSpi extends GeneratedTripSpi { |
| 160 | 161 | }
|
| 161 | 162 | }
|
| 162 | 163 | |
| 163 | - public TripMapDto getTripMap(ObserveTopiaPersistenceContextSupport persistenceContext, TripMapConfigDto config) {
|
|
| 164 | - LinkedHashSet<TripMapPoint> points = Trip.SPI.getDao(persistenceContext).extractTripMapActivityPoints(config);
|
|
| 164 | + public TripMapDto getTripMap(ServiceContext context, TripMapConfigDto config) {
|
|
| 165 | + String tripId = config.getTripId();
|
|
| 166 | + TripTopiaDao dao = getDao(context);
|
|
| 167 | + Trip trip = dao.forTopiaIdEquals(tripId).findUnique();
|
|
| 168 | + LinkedHashSet<TripMapPoint> points = TripMapBuilder.build(dao.getTopiaSqlSupport(), config, trip);
|
|
| 165 | 169 | return TripMapDto.of(config.getTripId(), points);
|
| 166 | 170 | }
|
| 167 | 171 | |
| 172 | + public int getMatchingTripsVesselWithinDateRange(ServiceContext context, String id, String vesselId, Date startDate, Date endDate) {
|
|
| 173 | + if (vesselId == null || startDate == null || endDate == null) {
|
|
| 174 | + return 0;
|
|
| 175 | + }
|
|
| 176 | + return (int) getDao(context).
|
|
| 177 | + <Trip>stream("From fr.ird.observe.entities.data.ll.common.TripImpl Where vessel.id = :vesselId " +
|
|
| 178 | + "And (( :startDate <= endDate And :endDate >= endDate ) " +
|
|
| 179 | + " Or ( :endDate <= startDate And :endDate >= startDate )) " +
|
|
| 180 | + "Order By startDate, endDate", Map.of(
|
|
| 181 | + "vesselId", vesselId,
|
|
| 182 | + "startDate", startDate,
|
|
| 183 | + "endDate", endDate))
|
|
| 184 | + .filter(t -> !Objects.equals(id, t.getTopiaId()))
|
|
| 185 | + .count();
|
|
| 186 | + }
|
|
| 187 | + |
|
| 168 | 188 | public ReferentialDtoReferenceSet<SpeciesReference> getSpeciesByListAndTrip(ServiceContext context, String tripId, String speciesListId) {
|
| 169 | 189 | Ocean ocean = null;
|
| 170 | 190 | if (tripId != null) {
|
| 171 | - Trip trip = Trip.SPI.loadEntity(context, tripId);
|
|
| 191 | + Trip trip = loadEntity(context, tripId);
|
|
| 172 | 192 | ocean = trip.getOcean();
|
| 173 | 193 | }
|
| 174 | 194 | Stream<Species> speciesList = SpeciesList.loadEntity(context, speciesListId).getSpecies().stream();
|
| ... | ... | @@ -178,4 +198,5 @@ public class TripSpi extends GeneratedTripSpi { |
| 178 | 198 | }
|
| 179 | 199 | return Species.toReferenceSet(context.getReferentialLocale(), speciesList, null);
|
| 180 | 200 | }
|
| 201 | + |
|
| 181 | 202 | } |
| 1 | -package fr.ird.observe.entities.data.ll.common;
|
|
| 2 | - |
|
| 3 | -/*
|
|
| 4 | - * #%L
|
|
| 5 | - * ObServe Models :: Persistence :: Java
|
|
| 6 | - * %%
|
|
| 7 | - * Copyright (C) 2008 - 2022 IRD, Code Lutin, Ultreia.io
|
|
| 8 | - * %%
|
|
| 9 | - * This program is free software: you can redistribute it and/or modify
|
|
| 10 | - * it under the terms of the GNU General Public License as
|
|
| 11 | - * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | - * License, or (at your option) any later version.
|
|
| 13 | - *
|
|
| 14 | - * This program is distributed in the hope that it will be useful,
|
|
| 15 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | - * GNU General Public License for more details.
|
|
| 18 | - *
|
|
| 19 | - * You should have received a copy of the GNU General Public
|
|
| 20 | - * License along with this program. If not, see
|
|
| 21 | - * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | - * #L%
|
|
| 23 | - */
|
|
| 24 | - |
|
| 25 | -import fr.ird.observe.dto.data.TripMapConfigDto;
|
|
| 26 | -import fr.ird.observe.dto.data.TripMapPoint;
|
|
| 27 | -import fr.ird.observe.dto.data.ll.common.TripDto;
|
|
| 28 | -import fr.ird.observe.dto.data.ll.common.TripReference;
|
|
| 29 | -import fr.ird.observe.entities.data.RootOpenableEntityDao;
|
|
| 30 | - |
|
| 31 | -import java.util.Date;
|
|
| 32 | -import java.util.LinkedHashSet;
|
|
| 33 | -import java.util.Map;
|
|
| 34 | -import java.util.Objects;
|
|
| 35 | - |
|
| 36 | -public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements RootOpenableEntityDao<TripDto, TripReference, Trip> {
|
|
| 37 | - |
|
| 38 | -// @Override
|
|
| 39 | -// public String getReferencesSql(String extraCode) {
|
|
| 40 | -// String dbTableName = getTopiaEntityEnum().dbTableName();
|
|
| 41 | -// String dbSchemaName = getTopiaEntityEnum().dbSchemaName();
|
|
| 42 | -// return String.format("SELECT" +
|
|
| 43 | -// " t.topiaId," +
|
|
| 44 | -// " t.topiaCreateDate," +
|
|
| 45 | -// " t.topiaVersion," +
|
|
| 46 | -// " t.lastUpdateDate," +
|
|
| 47 | -// " t.observationsProgram," +
|
|
| 48 | -// " t.logbookProgram," +
|
|
| 49 | -// " t.startDate," +
|
|
| 50 | -// " t.endDate," +
|
|
| 51 | -// " t.vessel," +
|
|
| 52 | -// " t.tripType," +
|
|
| 53 | -// " t.observationsAvailability," +
|
|
| 54 | -// " t.logbookAvailability" +
|
|
| 55 | -// " FROM %1$s.%2$s t%3$s",
|
|
| 56 | -// dbSchemaName, dbTableName,
|
|
| 57 | -// (extraCode == null ? "" : " WHERE " + extraCode));
|
|
| 58 | -// }
|
|
| 59 | - |
|
| 60 | - public LinkedHashSet<TripMapPoint> extractTripMapActivityPoints(TripMapConfigDto tripMapConfig) {
|
|
| 61 | - String tripId = tripMapConfig.getTripId();
|
|
| 62 | - Trip trip = forTopiaIdEquals(tripId).findUnique();
|
|
| 63 | - return TripMapBuilder.build(topiaSqlSupport, tripMapConfig, trip);
|
|
| 64 | - }
|
|
| 65 | - |
|
| 66 | - public int getMatchingTripsVesselWithinDateRange(String id, String vesselId, Date startDate, Date endDate) {
|
|
| 67 | - if (vesselId == null || startDate == null || endDate == null) {
|
|
| 68 | - return 0;
|
|
| 69 | - }
|
|
| 70 | - return (int) this.
|
|
| 71 | - <Trip>stream("From fr.ird.observe.entities.data.ll.common.TripImpl Where vessel.id = :vesselId " +
|
|
| 72 | - "And (( :startDate <= endDate And :endDate >= endDate ) " +
|
|
| 73 | - " Or ( :endDate <= startDate And :endDate >= startDate )) " +
|
|
| 74 | - "Order By startDate, endDate", Map.of(
|
|
| 75 | - "vesselId", vesselId,
|
|
| 76 | - "startDate", startDate,
|
|
| 77 | - "endDate", endDate))
|
|
| 78 | - .filter(t -> !Objects.equals(id, t.getTopiaId()))
|
|
| 79 | - .count();
|
|
| 80 | - }
|
|
| 81 | -} |
| ... | ... | @@ -43,13 +43,12 @@ public class ActivitySampleSpi extends GeneratedActivitySampleSpi { |
| 43 | 43 | return super.preCreate(context, parent, preCreated);
|
| 44 | 44 | }
|
| 45 | 45 | |
| 46 | + //FIXME Use ToParentIdProvider to update all parent lastUpdateDate nice and easy
|
|
| 47 | + // As the sample is mainly associated to trip, updating only entity won't update the activity and his ancestor
|
|
| 46 | 48 | @Override
|
| 47 | - protected SaveResultDto onSave(ServiceContext context, ActivitySampleDto dto, Activity parent, Sample entity) {
|
|
| 48 | - Sample.ACTIVITY_SAMPLE_SPI.fromDto(context.getReferentialLocale(), entity, dto);
|
|
| 49 | - parent.setSample(entity);
|
|
| 50 | - // As the sample is mainly associated to trip, updating only entity won't update the activity and his ancestor
|
|
| 49 | + protected SaveResultDto saveEntity(ServiceContext context, Activity parent, Sample entity) {
|
|
| 51 | 50 | return newSaveHelper(context)
|
| 52 | - .update(Sample.ACTIVITY_SAMPLE_SPI, entity, false, true)
|
|
| 51 | + .update(this, entity, false, true)
|
|
| 53 | 52 | .updateLastUpdateDateField(Activity.SPI, parent)
|
| 54 | 53 | .build(entity);
|
| 55 | 54 | }
|
| ... | ... | @@ -76,7 +76,7 @@ public class SetSpi extends GeneratedSetSpi { |
| 76 | 76 | public java.util.Set<SetStubDto> getBrothers(ServiceContext context, Activity parent) {
|
| 77 | 77 | java.util.Set<SetStubDto> result = new HashSet<>();
|
| 78 | 78 | ReferentialLocale referentialLocale = context.getReferentialLocale();
|
| 79 | - Trip trip = getParent(context, Trip.SPI, Trip.PROPERTY_ACTIVITY_LOGBOOK, parent.getTopiaId());
|
|
| 79 | + Trip trip = Activity.SPI.getParent(context, parent.getTopiaId());
|
|
| 80 | 80 | trip.getActivityLogbook().stream().filter(a -> VesselActivityReference.isSetOperation(a.getVesselActivity()) && !Objects.equals(a, parent) && a.getSet() != null).forEach(
|
| 81 | 81 | oneParent -> {
|
| 82 | 82 | Set otherSet = oneParent.getSet();
|
| ... | ... | @@ -133,6 +133,6 @@ public class SetSpi extends GeneratedSetSpi { |
| 133 | 133 | entity.setLightsticksType(entityToCopy.getLightsticksType());
|
| 134 | 134 | entity.setLightsticksColor(entityToCopy.getLightsticksColor());
|
| 135 | 135 | onSave(context, parent, entity, dto);
|
| 136 | - return saveEntity(context, entity);
|
|
| 136 | + return saveEntity(context, parent, entity);
|
|
| 137 | 137 | }
|
| 138 | 138 | } |
| ... | ... | @@ -30,16 +30,15 @@ import fr.ird.observe.entities.Entity; |
| 30 | 30 | import fr.ird.observe.spi.service.ServiceContext;
|
| 31 | 31 | |
| 32 | 32 | public class BranchlineSpi extends GeneratedBranchlineSpi {
|
| 33 | + |
|
| 33 | 34 | public Form<BranchlineDto> loadForm(ServiceContext context, String id) {
|
| 34 | 35 | Branchline entity = loadEntity(context, id);
|
| 35 | 36 | return entityToForm(context, entity);
|
| 36 | - |
|
| 37 | 37 | }
|
| 38 | 38 | |
| 39 | 39 | public SaveResultDto save(ServiceContext context, BranchlineDto dto) {
|
| 40 | - |
|
| 41 | 40 | Set parent = getParent(context, dto);
|
| 42 | - Branchline entity = Branchline.SPI.loadOrCreateEntityFromDto(context, dto);
|
|
| 41 | + Branchline entity = Branchline.loadOrCreateEntityFromDto(context, dto);
|
|
| 43 | 42 | Branchline.SPI.checkLastUpdateDate(context, entity, dto);
|
| 44 | 43 | Branchline.fromDto(context.getReferentialLocale(), entity, dto);
|
| 45 | 44 | return newSaveHelper(context)
|
| ... | ... | @@ -52,6 +51,6 @@ public class BranchlineSpi extends GeneratedBranchlineSpi { |
| 52 | 51 | ToolkitParentIdDtoBean basketId = Branchline.SPI.getParentId(context, dto.getTopiaId());
|
| 53 | 52 | ToolkitParentIdDtoBean sectionId = Basket.SPI.getParentId(context, basketId.getTopiaId());
|
| 54 | 53 | ToolkitParentIdDtoBean setId = Section.SPI.getParentId(context, sectionId.getTopiaId());
|
| 55 | - return Set.SPI.loadEntity(context, setId.getTopiaId());
|
|
| 54 | + return Set.loadEntity(context, setId.getTopiaId());
|
|
| 56 | 55 | }
|
| 57 | -} //BranchlineSpi |
|
| 56 | +} |
| ... | ... | @@ -37,7 +37,8 @@ public class SetDetailCompositionSpi extends GeneratedSetDetailCompositionSpi { |
| 37 | 37 | @Override
|
| 38 | 38 | public void onLoadForm(ServiceContext context, Set entity, Form<SetDetailCompositionDto> form) {
|
| 39 | 39 | SetDetailCompositionDto dto = form.getObject();
|
| 40 | - SetTopiaDao dao = Set.SPI.getDao(context);
|
|
| 40 | + SetTopiaDao dao = Set.getDao(context);
|
|
| 41 | + //FIXME Use a real sql query to get this in one time
|
|
| 41 | 42 | java.util.Set<String> sectionUsed = dao.getSectionUsed(entity.getTopiaId());
|
| 42 | 43 | java.util.Set<String> basketUsed = dao.getBasketUsed(entity.getTopiaId());
|
| 43 | 44 | java.util.Set<String> branchlineUsed = dao.getBranchlineUsed(entity.getTopiaId());
|
| ... | ... | @@ -122,7 +122,7 @@ public class SetSpi extends GeneratedSetSpi { |
| 122 | 122 | |
| 123 | 123 | public java.util.Set<SetStubDto> getBrothers(ServiceContext context, Activity parent) {
|
| 124 | 124 | java.util.Set<SetStubDto> result = new HashSet<>();
|
| 125 | - Trip trip = getParent(context, Trip.SPI, Trip.PROPERTY_ACTIVITY_OBS, parent.getTopiaId());
|
|
| 125 | + Trip trip = Activity.SPI.getParent(context, parent.getTopiaId());
|
|
| 126 | 126 | ReferentialLocale referentialLocale = context.getReferentialLocale();
|
| 127 | 127 | trip.getActivityObs().stream().filter(a -> VesselActivityReference.isSetOperation(a.getVesselActivity())).filter(a -> !Objects.equals(a, parent)).forEach(
|
| 128 | 128 | oneParent -> {
|
| ... | ... | @@ -27,8 +27,6 @@ import fr.ird.observe.entities.referential.common.GearCharacteristic; |
| 27 | 27 | import fr.ird.observe.spi.decoration.ObserveI18nLabelsBuilder;
|
| 28 | 28 | import org.apache.commons.lang3.tuple.Pair;
|
| 29 | 29 | |
| 30 | -import java.util.Date;
|
|
| 31 | -import java.util.function.BiConsumer;
|
|
| 32 | 30 | import java.util.stream.Collectors;
|
| 33 | 31 | |
| 34 | 32 | /**
|
| ... | ... | @@ -53,13 +51,4 @@ public class GearUseFeaturesSpi extends GeneratedGearUseFeaturesSpi { |
| 53 | 51 | return String.format("( %s - %s%s = %s )", codeLabel, gearCharacteristic.getLabel2(), unitLabel, measurementValue);
|
| 54 | 52 | }
|
| 55 | 53 | |
| 56 | - @Override
|
|
| 57 | - public BiConsumer<Trip, Date> saveCallback() {
|
|
| 58 | - return (e, lastUpdateDate) -> {
|
|
| 59 | - for (GearUseFeatures features : e.getGearUseFeatures()) {
|
|
| 60 | - features.setLastUpdateDate(lastUpdateDate);
|
|
| 61 | - features.getGearUseFeaturesMeasurement().forEach(measurement -> measurement.setLastUpdateDate(lastUpdateDate));
|
|
| 62 | - }
|
|
| 63 | - };
|
|
| 64 | - }
|
|
| 65 | 54 | } |
| 1 | -package fr.ird.observe.entities.data.ps.localmarket;
|
|
| 1 | +package fr.ird.observe.entities.data.ps.common;
|
|
| 2 | 2 | |
| 3 | 3 | /*-
|
| 4 | 4 | * #%L
|
| ... | ... | @@ -25,7 +25,6 @@ package fr.ird.observe.entities.data.ps.localmarket; |
| 25 | 25 | import fr.ird.observe.dto.data.ps.localmarket.TripBatchDto;
|
| 26 | 26 | import fr.ird.observe.dto.form.Form;
|
| 27 | 27 | import fr.ird.observe.dto.referential.ps.localmarket.PackagingReference;
|
| 28 | -import fr.ird.observe.entities.data.ps.common.Trip;
|
|
| 29 | 28 | import fr.ird.observe.entities.referential.common.Harbour;
|
| 30 | 29 | import fr.ird.observe.entities.referential.ps.localmarket.Packaging;
|
| 31 | 30 | import fr.ird.observe.spi.service.ServiceContext;
|
| ... | ... | @@ -35,19 +34,12 @@ import java.util.LinkedHashSet; |
| 35 | 34 | import java.util.function.BiConsumer;
|
| 36 | 35 | import java.util.stream.Collectors;
|
| 37 | 36 | |
| 38 | -/**
|
|
| 39 | - * Created on 10/05/2021.
|
|
| 40 | - *
|
|
| 41 | - * @author Tony Chemit - dev@tchemit.fr
|
|
| 42 | - * @since 9.0.0
|
|
| 43 | - */
|
|
| 44 | -public class BatchSpi extends GeneratedBatchSpi {
|
|
| 45 | - public static LinkedHashSet<PackagingReference> getPackaging(ServiceContext context, Trip trip) {
|
|
| 46 | - Harbour landingHarbour = trip.getLandingHarbour();
|
|
| 47 | - Date date = trip.getEndDate();
|
|
| 48 | - return Packaging.toReferenceSet(context.getReferentialLocale(), Packaging.getDao(context)
|
|
| 49 | - .streamAll()
|
|
| 50 | - .filter(p -> p.acceptHarbour(landingHarbour) && p.acceptDate(date)), null).stream().collect(Collectors.toCollection(LinkedHashSet::new));
|
|
| 37 | +public class TripBatchSpi extends GeneratedTripBatchSpi {
|
|
| 38 | + |
|
| 39 | + @Override
|
|
| 40 | + public void loadForm(ServiceContext context, String id, Trip parent, Form<TripBatchDto> form) {
|
|
| 41 | + LinkedHashSet<PackagingReference> availablePackaging = getPackaging(context, parent);
|
|
| 42 | + form.getObject().setAvailablePackagings(availablePackaging);
|
|
| 51 | 43 | }
|
| 52 | 44 | |
| 53 | 45 | @Override
|
| ... | ... | @@ -55,10 +47,12 @@ public class BatchSpi extends GeneratedBatchSpi { |
| 55 | 47 | return (e, lastUpdateDate) -> e.getLocalmarketBatch().forEach(c -> c.setLastUpdateDate(lastUpdateDate));
|
| 56 | 48 | }
|
| 57 | 49 | |
| 58 | - @Override
|
|
| 59 | - public void loadForm(ServiceContext context, Trip parent, Form<TripBatchDto> form) {
|
|
| 60 | - LinkedHashSet<PackagingReference> availablePackaging = getPackaging(context, parent);
|
|
| 61 | - form.getObject().setAvailablePackagings(availablePackaging);
|
|
| 50 | + protected LinkedHashSet<PackagingReference> getPackaging(ServiceContext context, Trip trip) {
|
|
| 51 | + Harbour landingHarbour = trip.getLandingHarbour();
|
|
| 52 | + Date date = trip.getEndDate();
|
|
| 53 | + return Packaging.toReferenceSet(context.getReferentialLocale(), Packaging.getDao(context)
|
|
| 54 | + .streamAll()
|
|
| 55 | + .filter(p -> p.acceptHarbour(landingHarbour) && p.acceptDate(date)), null).stream().collect(Collectors.toCollection(LinkedHashSet::new));
|
|
| 62 | 56 | }
|
| 63 | 57 | |
| 64 | 58 | } |
| 1 | +package fr.ird.observe.entities.data.ps.common;
|
|
| 2 | + |
|
| 3 | +/*-
|
|
| 4 | + * #%L
|
|
| 5 | + * ObServe Models :: Persistence :: Java
|
|
| 6 | + * %%
|
|
| 7 | + * Copyright (C) 2008 - 2022 IRD, Code Lutin, Ultreia.io
|
|
| 8 | + * %%
|
|
| 9 | + * This program is free software: you can redistribute it and/or modify
|
|
| 10 | + * it under the terms of the GNU General Public License as
|
|
| 11 | + * published by the Free Software Foundation, either version 3 of the
|
|
| 12 | + * License, or (at your option) any later version.
|
|
| 13 | + *
|
|
| 14 | + * This program is distributed in the hope that it will be useful,
|
|
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 | + * GNU General Public License for more details.
|
|
| 18 | + *
|
|
| 19 | + * You should have received a copy of the GNU General Public
|
|
| 20 | + * License along with this program. If not, see
|
|
| 21 | + * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 | + * #L%
|
|
| 23 | + */
|
|
| 24 | + |
|
| 25 | +import java.util.Date;
|
|
| 26 | +import java.util.function.BiConsumer;
|
|
| 27 | + |
|
| 28 | +public class TripGearUseFeaturesSpi extends GeneratedTripGearUseFeaturesSpi {
|
|
| 29 | + |
|
| 30 | + @Override
|
|
| 31 | + public BiConsumer<Trip, Date> saveCallback() {
|
|
| 32 | + return (e, lastUpdateDate) -> {
|
|
| 33 | + for (GearUseFeatures features : e.getGearUseFeatures()) {
|
|
| 34 | + features.setLastUpdateDate(lastUpdateDate);
|
|
| 35 | + features.getGearUseFeaturesMeasurement().forEach(measurement -> measurement.setLastUpdateDate(lastUpdateDate));
|
|
| 36 | + }
|
|
| 37 | + };
|
|
| 38 | + }
|
|
| 39 | +} |
| ... | ... | @@ -33,7 +33,6 @@ import fr.ird.observe.dto.reference.DataDtoReferenceSet; |
| 33 | 33 | import fr.ird.observe.dto.reference.ReferentialDtoReferenceSet;
|
| 34 | 34 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 35 | 35 | import fr.ird.observe.dto.referential.common.SpeciesReference;
|
| 36 | -import fr.ird.observe.entities.ObserveTopiaPersistenceContextSupport;
|
|
| 37 | 36 | import fr.ird.observe.entities.data.ps.logbook.Activity;
|
| 38 | 37 | import fr.ird.observe.entities.data.ps.observation.Route;
|
| 39 | 38 | import fr.ird.observe.entities.referential.common.Ocean;
|
| ... | ... | @@ -49,6 +48,8 @@ import java.util.Collection; |
| 49 | 48 | import java.util.Date;
|
| 50 | 49 | import java.util.LinkedHashSet;
|
| 51 | 50 | import java.util.List;
|
| 51 | +import java.util.Map;
|
|
| 52 | +import java.util.Objects;
|
|
| 52 | 53 | import java.util.function.Supplier;
|
| 53 | 54 | import java.util.stream.Stream;
|
| 54 | 55 | |
| ... | ... | @@ -158,7 +159,7 @@ public class TripSpi extends GeneratedTripSpi { |
| 158 | 159 | public ReferentialDtoReferenceSet<SpeciesReference> getSpeciesByListAndTrip(ServiceContext context, String tripId, String speciesListId) {
|
| 159 | 160 | Ocean ocean = null;
|
| 160 | 161 | if (tripId != null) {
|
| 161 | - Trip trip = Trip.SPI.loadEntity(context, tripId);
|
|
| 162 | + Trip trip = loadEntity(context, tripId);
|
|
| 162 | 163 | ocean = trip.getOcean();
|
| 163 | 164 | }
|
| 164 | 165 | Stream<Species> speciesList = SpeciesList.loadEntity(context, speciesListId).getSpecies().stream();
|
| ... | ... | @@ -169,11 +170,30 @@ public class TripSpi extends GeneratedTripSpi { |
| 169 | 170 | return Species.toReferenceSet(context.getReferentialLocale(), speciesList, null);
|
| 170 | 171 | }
|
| 171 | 172 | |
| 172 | - public TripMapDto getTripMap(ObserveTopiaPersistenceContextSupport persistenceContext, TripMapConfigDto config) {
|
|
| 173 | - LinkedHashSet<TripMapPoint> points = getDao(persistenceContext).extractTripMapActivityPoints(config);
|
|
| 173 | + public TripMapDto getTripMap(ServiceContext context, TripMapConfigDto config) {
|
|
| 174 | + String tripId = config.getTripId();
|
|
| 175 | + TripTopiaDao dao = getDao(context);
|
|
| 176 | + Trip trip = dao.forTopiaIdEquals(tripId).findUnique();
|
|
| 177 | + LinkedHashSet<TripMapPoint> points = TripMapBuilder.build(dao.getTopiaSqlSupport(), config, trip);
|
|
| 174 | 178 | return TripMapDto.of(config.getTripId(), points);
|
| 175 | 179 | }
|
| 176 | 180 | |
| 181 | + public int getMatchingTripsVesselWithinDateRange(ServiceContext context, String id, String vesselId, Date startDate, Date endDate) {
|
|
| 182 | + if (vesselId == null || startDate == null || endDate == null) {
|
|
| 183 | + return 0;
|
|
| 184 | + }
|
|
| 185 | + return (int) getDao(context).
|
|
| 186 | + <Trip>stream("From fr.ird.observe.entities.data.ps.common.TripImpl Where vessel.id = :vesselId " +
|
|
| 187 | + "And (( :startDate <= endDate And :endDate >= endDate ) " +
|
|
| 188 | + " Or ( :endDate <= startDate And :endDate >= startDate )) " +
|
|
| 189 | + "Order By startDate, endDate", Map.of(
|
|
| 190 | + "vesselId", vesselId,
|
|
| 191 | + "startDate", startDate,
|
|
| 192 | + "endDate", endDate))
|
|
| 193 | + .filter(t -> !Objects.equals(id, t.getTopiaId()))
|
|
| 194 | + .count();
|
|
| 195 | + }
|
|
| 196 | + |
|
| 177 | 197 | public DataDtoReferenceSet<ActivityReference> getLogbookSetActivities(ServiceContext context, String tripId) {
|
| 178 | 198 | ReferentialLocale referentialLocale = context.getReferentialLocale();
|
| 179 | 199 | List<Activity> allStubByTripId = Activity.getDao(context).getLogbookSetActivities(tripId, referentialLocale.ordinal());
|
| 1 | -/*
|
|
| 2 | - * #%L
|
|
| 3 | - * ObServe Models :: Persistence :: Java
|
|
| 4 | - * %%
|
|
| 5 | - * Copyright (C) 2008 - 2022 IRD, Code Lutin, Ultreia.io
|
|
| 6 | - * %%
|
|
| 7 | - * This program is free software: you can redistribute it and/or modify
|
|
| 8 | - * it under the terms of the GNU General Public License as
|
|
| 9 | - * published by the Free Software Foundation, either version 3 of the
|
|
| 10 | - * License, or (at your option) any later version.
|
|
| 11 | - *
|
|
| 12 | - * This program is distributed in the hope that it will be useful,
|
|
| 13 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 14 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 15 | - * GNU General Public License for more details.
|
|
| 16 | - *
|
|
| 17 | - * You should have received a copy of the GNU General Public
|
|
| 18 | - * License along with this program. If not, see
|
|
| 19 | - * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 20 | - * #L%
|
|
| 21 | - */
|
|
| 22 | -package fr.ird.observe.entities.data.ps.common;
|
|
| 23 | - |
|
| 24 | -import fr.ird.observe.dto.data.TripMapConfigDto;
|
|
| 25 | -import fr.ird.observe.dto.data.TripMapPoint;
|
|
| 26 | -import fr.ird.observe.dto.data.ps.common.TripDto;
|
|
| 27 | -import fr.ird.observe.dto.data.ps.common.TripReference;
|
|
| 28 | -import fr.ird.observe.entities.data.RootOpenableEntityDao;
|
|
| 29 | - |
|
| 30 | -import java.util.Date;
|
|
| 31 | -import java.util.LinkedHashSet;
|
|
| 32 | -import java.util.Map;
|
|
| 33 | -import java.util.Objects;
|
|
| 34 | - |
|
| 35 | -/**
|
|
| 36 | - * Add some user methods.
|
|
| 37 | - *
|
|
| 38 | - * @author Tony Chemit - dev@tchemit.fr
|
|
| 39 | - * @since 2.2
|
|
| 40 | - */
|
|
| 41 | -public class TripTopiaDao extends AbstractTripTopiaDao<Trip> implements RootOpenableEntityDao<TripDto, TripReference, Trip> {
|
|
| 42 | - |
|
| 43 | -// @Override
|
|
| 44 | -// public String getReferencesSql(String extraCode) {
|
|
| 45 | -// String dbTableName = getTopiaEntityEnum().dbTableName();
|
|
| 46 | -// String dbSchemaName = getTopiaEntityEnum().dbSchemaName();
|
|
| 47 | -// return String.format("SELECT" +
|
|
| 48 | -// " t.topiaId," +
|
|
| 49 | -// " t.topiaCreateDate," +
|
|
| 50 | -// " t.topiaVersion," +
|
|
| 51 | -// " t.lastUpdateDate," +
|
|
| 52 | -// " t.observationsProgram," +
|
|
| 53 | -// " t.logbookProgram," +
|
|
| 54 | -// " t.startDate," +
|
|
| 55 | -// " t.endDate," +
|
|
| 56 | -// " t.vessel," +
|
|
| 57 | -// " t.observationsAcquisitionStatus," +
|
|
| 58 | -// " t.logbookAcquisitionStatus," +
|
|
| 59 | -// " t.targetWellsSamplingAcquisitionStatus," +
|
|
| 60 | -// " t.landingAcquisitionStatus," +
|
|
| 61 | -// " t.localMarketAcquisitionStatus," +
|
|
| 62 | -// " t.localMarketWellsSamplingAcquisitionStatus," +
|
|
| 63 | -// " t.localMarketSurveySamplingAcquisitionStatus," +
|
|
| 64 | -// " t.advancedSamplingAcquisitionStatus" +
|
|
| 65 | -// " FROM %1$s.%2$s t%3$s",
|
|
| 66 | -// dbSchemaName, dbTableName,
|
|
| 67 | -// (extraCode == null ? "" : " WHERE " + extraCode));
|
|
| 68 | -// }
|
|
| 69 | - |
|
| 70 | - public LinkedHashSet<TripMapPoint> extractTripMapActivityPoints(TripMapConfigDto tripMapConfig) {
|
|
| 71 | - String tripId = tripMapConfig.getTripId();
|
|
| 72 | - Trip trip = forTopiaIdEquals(tripId).findUnique();
|
|
| 73 | - return TripMapBuilder.build(topiaSqlSupport, tripMapConfig, trip);
|
|
| 74 | - }
|
|
| 75 | - |
|
| 76 | - public int getMatchingTripsVesselWithinDateRange(String id, String vesselId, Date startDate, Date endDate) {
|
|
| 77 | - if (vesselId == null || startDate == null || endDate == null) {
|
|
| 78 | - return 0;
|
|
| 79 | - }
|
|
| 80 | - return (int) this.
|
|
| 81 | - <Trip>stream("From fr.ird.observe.entities.data.ps.common.TripImpl Where vessel.id = :vesselId " +
|
|
| 82 | - "And (( :startDate <= endDate And :endDate >= endDate ) " +
|
|
| 83 | - " Or ( :endDate <= startDate And :endDate >= startDate )) " +
|
|
| 84 | - "Order By startDate, endDate", Map.of(
|
|
| 85 | - "vesselId", vesselId,
|
|
| 86 | - "startDate", startDate,
|
|
| 87 | - "endDate", endDate))
|
|
| 88 | - .filter(t -> !Objects.equals(id, t.getTopiaId()))
|
|
| 89 | - .count();
|
|
| 90 | - }
|
|
| 91 | -} |
| ... | ... | @@ -62,7 +62,7 @@ public class SurveySpi extends GeneratedSurveySpi { |
| 62 | 62 | |
| 63 | 63 | @Override
|
| 64 | 64 | public void onLoadForm(ServiceContext context, Survey entity, Form<SurveyDto> form) {
|
| 65 | - ToolkitParentIdDtoBean tripId = getDao(context).executeQueryGetParentId(entity.getTopiaId());
|
|
| 65 | + ToolkitParentIdDtoBean tripId = Survey.SPI.getParentId(context, entity.getTopiaId());
|
|
| 66 | 66 | Trip trip = Trip.SPI.loadEntity(context, tripId.getId());
|
| 67 | 67 | fillFormObject(context.getReferentialLocale(), trip, entity, form);
|
| 68 | 68 | }
|
| ... | ... | @@ -79,6 +79,6 @@ public class RouteSpi extends GeneratedRouteSpi { |
| 79 | 79 | |
| 80 | 80 | @Override
|
| 81 | 81 | public Set<ToolkitIdDtoBean> getRealDependencies(ServiceContext context, Set<String> ids) {
|
| 82 | - return Activity.getDao(context).executeQueryByParentId(ids).map(id -> ToolkitIdDtoBean.of(ActivityDto.class, id)).collect(Collectors.toSet());
|
|
| 82 | + return Activity.byParentId(context, ids).map(id -> ToolkitIdDtoBean.of(ActivityDto.class, id)).collect(Collectors.toSet());
|
|
| 83 | 83 | }
|
| 84 | 84 | } |
| ... | ... | @@ -95,7 +95,7 @@ public class RouteSpi extends GeneratedRouteSpi { |
| 95 | 95 | |
| 96 | 96 | @Override
|
| 97 | 97 | public Set<ToolkitIdDtoBean> getRealDependencies(ServiceContext context, Set<String> ids) {
|
| 98 | - return Activity.getDao(context).executeQueryByParentId(ids).map(id -> ToolkitIdDtoBean.of(ActivityDto.class, id)).collect(Collectors.toSet());
|
|
| 98 | + return Activity.byParentId(context, ids).map(id -> ToolkitIdDtoBean.of(ActivityDto.class, id)).collect(Collectors.toSet());
|
|
| 99 | 99 | }
|
| 100 | 100 | |
| 101 | 101 | private void bindEndOfSearchingProperties(Set<Activity> activities, LinkedHashSet<ActivityStubDto> activitySeineList) {
|
| ... | ... | @@ -34,6 +34,8 @@ import java.util.stream.Collectors; |
| 34 | 34 | |
| 35 | 35 | public class SampleSpi extends GeneratedSampleSpi {
|
| 36 | 36 | |
| 37 | + //FIXME We need to fix this code, this is the only case where we create a first entity when not found
|
|
| 38 | + @Override
|
|
| 37 | 39 | public Form<SampleDto> loadForm(ServiceContext context, String id) {
|
| 38 | 40 | Set parent = Set.loadEntity(context, id);
|
| 39 | 41 | Sample entity = loadSampleFormEntity(context, parent);
|
| ... | ... | @@ -46,16 +48,7 @@ public class SampleSpi extends GeneratedSampleSpi { |
| 46 | 48 | return form;
|
| 47 | 49 | }
|
| 48 | 50 | |
| 49 | - public Sample loadSampleFormEntity(ServiceContext context, Set parent) {
|
|
| 50 | - Sample sample;
|
|
| 51 | - if (parent.isSampleEmpty()) {
|
|
| 52 | - sample = Sample.newEntity(context.now());
|
|
| 53 | - } else {
|
|
| 54 | - sample = parent.getSample().iterator().next();
|
|
| 55 | - }
|
|
| 56 | - return sample;
|
|
| 57 | - }
|
|
| 58 | - |
|
| 51 | + @Override
|
|
| 59 | 52 | public SaveResultDto save(ServiceContext context, SampleDto dto) {
|
| 60 | 53 | // this is a trick we always use id as parent id...
|
| 61 | 54 | Set parent = Set.loadEntity(context, dto.getId());
|
| ... | ... | @@ -74,4 +67,11 @@ public class SampleSpi extends GeneratedSampleSpi { |
| 74 | 67 | .updateLastUpdateDateField(Set.SPI, parent)
|
| 75 | 68 | .build(entity);
|
| 76 | 69 | }
|
| 77 | -} |
|
| 70 | + |
|
| 71 | + protected Sample loadSampleFormEntity(ServiceContext context, Set parent) {
|
|
| 72 | + if (parent.isSampleEmpty()) {
|
|
| 73 | + return Sample.newEntity(context.now());
|
|
| 74 | + }
|
|
| 75 | + return parent.getSample().iterator().next();
|
|
| 76 | + }
|
|
| 77 | +} |
| ... | ... | @@ -22,7 +22,6 @@ package fr.ird.observe.entities.data.ps.observation; |
| 22 | 22 | * #L%
|
| 23 | 23 | */
|
| 24 | 24 | |
| 25 | -import fr.ird.observe.dto.ToolkitParentIdDtoBean;
|
|
| 26 | 25 | import fr.ird.observe.dto.data.ps.observation.SetDto;
|
| 27 | 26 | import fr.ird.observe.dto.form.Form;
|
| 28 | 27 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| ... | ... | @@ -49,8 +48,7 @@ public class SetSpi extends GeneratedSetSpi { |
| 49 | 48 | |
| 50 | 49 | @Override
|
| 51 | 50 | public Form<SetDto> preCreate(ServiceContext context, Activity parent, Set preCreated) {
|
| 52 | - ToolkitParentIdDtoBean routeId = Activity.SPI.getParentId(context, parent.getTopiaId());
|
|
| 53 | - Route route = Route.SPI.loadEntity(context, routeId.getId());
|
|
| 51 | + Route route = Activity.SPI.getParent(context, parent.getTopiaId());
|
|
| 54 | 52 | Date routeDate = route.getDate();
|
| 55 | 53 | // on utilise l'heure de l'activité comme début de calée
|
| 56 | 54 | Date date = Dates.getTime(parent.getTime(), false, false);
|
| ... | ... | @@ -69,7 +67,7 @@ public class SetSpi extends GeneratedSetSpi { |
| 69 | 67 | |
| 70 | 68 | @Override
|
| 71 | 69 | public void onLoadForm(ServiceContext context, Activity parent, Set entity, Form<SetDto> form) {
|
| 72 | - Route route = getParent(context, Route.SPI, Route.PROPERTY_ACTIVITY, parent.getTopiaId());
|
|
| 70 | + Route route = Activity.SPI.getParent(context, parent.getTopiaId());
|
|
| 73 | 71 | Date routeDate = route.getDate();
|
| 74 | 72 | form.getObject().setStartSetDate(routeDate);
|
| 75 | 73 | }
|
| ... | ... | @@ -26,10 +26,11 @@ import fr.ird.observe.dto.BusinessDto; |
| 26 | 26 | import fr.ird.observe.dto.ToolkitId;
|
| 27 | 27 | import fr.ird.observe.dto.ToolkitIdMap;
|
| 28 | 28 | import fr.ird.observe.entities.Entity;
|
| 29 | -import fr.ird.observe.entities.ObserveDaoQuerySupport;
|
|
| 30 | 29 | import fr.ird.observe.entities.ObserveEntityEnum;
|
| 31 | 30 | import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
| 31 | +import fr.ird.observe.entities.ToolkitTopiaDao;
|
|
| 32 | 32 | import fr.ird.observe.persistence.test.api.PersistenceTestSupportRead;
|
| 33 | +import fr.ird.observe.spi.ObservePersistenceBusinessProject;
|
|
| 33 | 34 | import fr.ird.observe.test.ObserveFixtures;
|
| 34 | 35 | import org.junit.Assert;
|
| 35 | 36 | import org.junit.Test;
|
| ... | ... | @@ -87,7 +88,7 @@ public class ObserveTopiaPersistenceContextTest extends PersistenceTestSupportRe |
| 87 | 88 | continue;
|
| 88 | 89 | }
|
| 89 | 90 | Class<? extends TopiaEntity> contract = value.getContract();
|
| 90 | - ObserveDaoQuerySupport dao = (ObserveDaoQuerySupport) persistenceContext.getDao(contract);
|
|
| 91 | + ToolkitTopiaDao<? extends TopiaEntity> dao = persistenceContext.getDao(contract);
|
|
| 91 | 92 | List<String> allIds = dao.findAllIds();
|
| 92 | 93 | if (allIds.isEmpty()) {
|
| 93 | 94 | continue;
|
| ... | ... | @@ -118,34 +119,13 @@ public class ObserveTopiaPersistenceContextTest extends PersistenceTestSupportRe |
| 118 | 119 | new TestGetParent(persistenceContext) {
|
| 119 | 120 | @Override
|
| 120 | 121 | protected ToolkitId produceQuery(Class<? extends Entity> entityType, Class<? extends BusinessDto> dtoType, String id) {
|
| 121 | - ToolkitId toolkitId = persistenceContext.executeQueryGetParentId(entityType, id);
|
|
| 122 | - if (toolkitId == null) {
|
|
| 123 | - toolkitId = persistenceContext.executeQueryGetParentId2(entityType, id);
|
|
| 124 | - }
|
|
| 125 | - return toolkitId;
|
|
| 122 | + return ObservePersistenceBusinessProject.fromEntity(entityType).getParentId(persistenceContext, id);
|
|
| 126 | 123 | }
|
| 127 | 124 | }.run();
|
| 128 | 125 | }
|
| 129 | 126 | |
| 130 | 127 | }
|
| 131 | 128 | |
| 132 | - @Test
|
|
| 133 | - public void testGetParentIdFromDao() {
|
|
| 134 | - try (ObserveTopiaPersistenceContext persistenceContext = localTestMethodResource.newPersistenceContext()) {
|
|
| 135 | - new TestGetParent(persistenceContext) {
|
|
| 136 | - @Override
|
|
| 137 | - protected ToolkitId produceQuery(Class<? extends Entity> entityType, Class<? extends BusinessDto> dtoType, String id) {
|
|
| 138 | - ObserveDaoQuerySupport dao = (ObserveDaoQuerySupport) persistenceContext.getDao(entityType);
|
|
| 139 | - ToolkitId toolkitId = dao.executeQueryGetParentId(id);
|
|
| 140 | - if (toolkitId == null) {
|
|
| 141 | - toolkitId = dao.executeQueryGetParentId2(id);
|
|
| 142 | - }
|
|
| 143 | - return toolkitId;
|
|
| 144 | - }
|
|
| 145 | - }.run();
|
|
| 146 | - }
|
|
| 147 | - }
|
|
| 148 | - |
|
| 149 | 129 | @Test
|
| 150 | 130 | public void testIdProjection() {
|
| 151 | 131 | try (ObserveTopiaPersistenceContext persistenceContext = localTestMethodResource.newPersistenceContext()) {
|
| ... | ... | @@ -192,7 +172,7 @@ public class ObserveTopiaPersistenceContextTest extends PersistenceTestSupportRe |
| 192 | 172 | continue;
|
| 193 | 173 | }
|
| 194 | 174 | Class<? extends TopiaEntity> contract = value.getContract();
|
| 195 | - ObserveDaoQuerySupport dao = (ObserveDaoQuerySupport) persistenceContext.getDao(contract);
|
|
| 175 | + ToolkitTopiaDao<? extends TopiaEntity> dao = persistenceContext.getDao(contract);
|
|
| 196 | 176 | List<String> allIds = dao.findAllIds();
|
| 197 | 177 | if (allIds.isEmpty()) {
|
| 198 | 178 | continue;
|
| ... | ... | @@ -26,9 +26,9 @@ import fr.ird.observe.dto.BusinessDto; |
| 26 | 26 | import fr.ird.observe.dto.ToolkitId;
|
| 27 | 27 | import fr.ird.observe.dto.reference.DtoReference;
|
| 28 | 28 | import fr.ird.observe.entities.Entity;
|
| 29 | -import fr.ird.observe.entities.ObserveDaoQuerySupport;
|
|
| 30 | 29 | import fr.ird.observe.entities.ObserveEntityEnum;
|
| 31 | 30 | import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
| 31 | +import fr.ird.observe.entities.ToolkitTopiaDao;
|
|
| 32 | 32 | import fr.ird.observe.spi.PersistenceBusinessProject;
|
| 33 | 33 | import fr.ird.observe.spi.context.DtoEntityContext;
|
| 34 | 34 | import fr.ird.observe.spi.module.BusinessProject;
|
| ... | ... | @@ -73,7 +73,7 @@ public abstract class TestGetParent implements Runnable { |
| 73 | 73 | if (BusinessProject.isReferential(dtoType)) {
|
| 74 | 74 | continue;
|
| 75 | 75 | }
|
| 76 | - ObserveDaoQuerySupport dao = (ObserveDaoQuerySupport) persistenceContext.getDao(contract);
|
|
| 76 | + ToolkitTopiaDao<? extends Entity> dao = persistenceContext.getDao(contract);
|
|
| 77 | 77 | List<String> allIds = dao.findAllIds();
|
| 78 | 78 | if (allIds.isEmpty()) {
|
| 79 | 79 | continue;
|
| ... | ... | @@ -132,10 +132,6 @@ |
| 132 | 132 | <groupId>org.hashids</groupId>
|
| 133 | 133 | <artifactId>hashids</artifactId>
|
| 134 | 134 | </dependency>
|
| 135 | - <dependency>
|
|
| 136 | - <groupId>org.nuiton.topia</groupId>
|
|
| 137 | - <artifactId>topia-persistence</artifactId>
|
|
| 138 | - </dependency>
|
|
| 139 | 135 | <dependency>
|
| 140 | 136 | <groupId>io.ultreia.java4all.decorator</groupId>
|
| 141 | 137 | <artifactId>decorator-api</artifactId>
|
| ... | ... | @@ -42,14 +42,13 @@ import fr.ird.observe.dto.reference.ReferentialDtoReference; |
| 42 | 42 | import fr.ird.observe.dto.referential.ReferentialDto;
|
| 43 | 43 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 44 | 44 | import fr.ird.observe.entities.Entity;
|
| 45 | -import fr.ird.observe.entities.ObserveDaoQuerySupport;
|
|
| 46 | 45 | import fr.ird.observe.entities.ObserveTopiaApplicationContext;
|
| 47 | 46 | import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
| 48 | 47 | import fr.ird.observe.entities.ReplicateDataEngine;
|
| 48 | +import fr.ird.observe.entities.ToolkitTopiaDao;
|
|
| 49 | 49 | import fr.ird.observe.entities.data.DataEntity;
|
| 50 | 50 | import fr.ird.observe.entities.data.DataGroupByEntity;
|
| 51 | 51 | import fr.ird.observe.entities.data.RootOpenableEntity;
|
| 52 | -import fr.ird.observe.entities.data.RootOpenableEntityDao;
|
|
| 53 | 52 | import fr.ird.observe.entities.referential.ReferentialEntity;
|
| 54 | 53 | import fr.ird.observe.gson.DtoGsonSupplier;
|
| 55 | 54 | import fr.ird.observe.navigation.select.ProjectSelectModel;
|
| ... | ... | @@ -81,7 +80,6 @@ import fr.ird.observe.validation.DefaultServiceValidationContextConfiguration; |
| 81 | 80 | import fr.ird.observe.validation.ObserveValidationRequest;
|
| 82 | 81 | import fr.ird.observe.validation.ServiceValidationContext;
|
| 83 | 82 | import io.ultreia.java4all.util.TimeLog;
|
| 84 | -import org.nuiton.topia.persistence.TopiaDao;
|
|
| 85 | 83 | import org.nuiton.validator.xwork2.XWork2ValidatorUtil;
|
| 86 | 84 | |
| 87 | 85 | import java.util.Date;
|
| ... | ... | @@ -208,7 +206,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 208 | 206 | public final <D extends DataDto,
|
| 209 | 207 | R extends DataDtoReference,
|
| 210 | 208 | E extends DataEntity,
|
| 211 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataEntity(E dtoType) {
|
|
| 209 | + T extends ToolkitTopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataEntity(E dtoType) {
|
|
| 212 | 210 | return ObservePersistenceBusinessProject.fromDataEntity(dtoType);
|
| 213 | 211 | }
|
| 214 | 212 | |
| ... | ... | @@ -216,7 +214,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 216 | 214 | public final <D extends DataDto,
|
| 217 | 215 | R extends DataDtoReference,
|
| 218 | 216 | E extends DataEntity,
|
| 219 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataDto(Class<D> dtoType) {
|
|
| 217 | + T extends ToolkitTopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataDto(Class<D> dtoType) {
|
|
| 220 | 218 | return ObservePersistenceBusinessProject.fromDataDto(dtoType);
|
| 221 | 219 | }
|
| 222 | 220 | |
| ... | ... | @@ -224,7 +222,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 224 | 222 | public final <D extends DataDto,
|
| 225 | 223 | R extends DataDtoReference,
|
| 226 | 224 | E extends DataEntity,
|
| 227 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataReference(Class<R> referenceType) {
|
|
| 225 | + T extends ToolkitTopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataReference(Class<R> referenceType) {
|
|
| 228 | 226 | Class<D> dtoType = ObserveReferenceDtoToDtoClassMapping.get().get(referenceType);
|
| 229 | 227 | return ObservePersistenceBusinessProject.fromDataDto(dtoType);
|
| 230 | 228 | }
|
| ... | ... | @@ -233,7 +231,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 233 | 231 | public final <D extends DataDto,
|
| 234 | 232 | R extends DataDtoReference,
|
| 235 | 233 | E extends DataEntity,
|
| 236 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataDto(ToolkitIdDtoBean dtoType) {
|
|
| 234 | + T extends ToolkitTopiaDao<E>> DataDtoEntityContext<D, R, E, T> fromDataDto(ToolkitIdDtoBean dtoType) {
|
|
| 237 | 235 | @SuppressWarnings("unchecked") Class<D> type = (Class<D>) dtoType.getType();
|
| 238 | 236 | return ObservePersistenceBusinessProject.fromDataDto(type);
|
| 239 | 237 | }
|
| ... | ... | @@ -243,7 +241,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 243 | 241 | D extends OpenableDto,
|
| 244 | 242 | R extends DataDtoReference,
|
| 245 | 243 | E extends DataEntity,
|
| 246 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> OpenableDtoEntityContext<PE, D, R, E, T> fromOpenableDto(Class<D> dtoType) {
|
|
| 244 | + T extends ToolkitTopiaDao<E>> OpenableDtoEntityContext<PE, D, R, E, T> fromOpenableDto(Class<D> dtoType) {
|
|
| 247 | 245 | return ObservePersistenceBusinessProject.fromOpenableDto(dtoType);
|
| 248 | 246 | }
|
| 249 | 247 | |
| ... | ... | @@ -251,7 +249,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 251 | 249 | public final <D extends RootOpenableDto,
|
| 252 | 250 | R extends DataDtoReference,
|
| 253 | 251 | E extends RootOpenableEntity,
|
| 254 | - T extends ObserveDaoQuerySupport & RootOpenableEntityDao<D, R, E> & TopiaDao<E>,
|
|
| 252 | + T extends ToolkitTopiaDao<E>,
|
|
| 255 | 253 | H extends DataGroupByReferentialHelper<D, R, E>> RootOpenableDtoEntityContext<D, R, E, T, H> fromRootOpenableDto(Class<D> dtoType) {
|
| 256 | 254 | return ObservePersistenceBusinessProject.fromRootOpenableDto(dtoType);
|
| 257 | 255 | }
|
| ... | ... | @@ -261,26 +259,24 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 261 | 259 | D extends EditableDto,
|
| 262 | 260 | R extends DataDtoReference,
|
| 263 | 261 | E extends DataEntity,
|
| 264 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> EditableDtoEntityContext<PE, D, R, E, T> fromEditableDto(Class<D> dtoType) {
|
|
| 262 | + T extends ToolkitTopiaDao<E>> EditableDtoEntityContext<PE, D, R, E, T> fromEditableDto(Class<D> dtoType) {
|
|
| 265 | 263 | return ObservePersistenceBusinessProject.fromEditableDto(dtoType);
|
| 266 | 264 | }
|
| 267 | 265 | |
| 268 | 266 | @Override
|
| 269 | - public final <PE extends DataEntity,
|
|
| 270 | - D extends ContainerChildDto,
|
|
| 271 | - M extends ContainerDto<D>,
|
|
| 267 | + public final <C extends ContainerChildDto,
|
|
| 268 | + D extends ContainerDto<C>,
|
|
| 272 | 269 | R extends DataDtoReference,
|
| 273 | 270 | E extends DataEntity,
|
| 274 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> ContainerDtoEntityContext<PE, D, M, R, E, T> fromContainerDto(Class<M> dtoType) {
|
|
| 275 | - Class<D> childDtoType = ObserveBusinessProject.get().getMapping().getDtoToFormDtoMapping().get(dtoType);
|
|
| 276 | - return ObservePersistenceBusinessProject.fromContainerDto(childDtoType);
|
|
| 271 | + T extends ToolkitTopiaDao<E>> ContainerDtoEntityContext<D, R, E, T> fromContainerDto(Class<D> dtoType) {
|
|
| 272 | + return ObservePersistenceBusinessProject.fromContainerDto(dtoType);
|
|
| 277 | 273 | }
|
| 278 | 274 | |
| 279 | 275 | @Override
|
| 280 | 276 | public final <D extends SimpleDto,
|
| 281 | 277 | R extends DataDtoReference,
|
| 282 | 278 | E extends DataEntity,
|
| 283 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> SimpleDtoEntityContext<D, R, E, T> fromSimpleDto(Class<D> dtoType) {
|
|
| 279 | + T extends ToolkitTopiaDao<E>> SimpleDtoEntityContext<D, R, E, T> fromSimpleDto(Class<D> dtoType) {
|
|
| 284 | 280 | return ObservePersistenceBusinessProject.fromSimpleDto(dtoType);
|
| 285 | 281 | }
|
| 286 | 282 | |
| ... | ... | @@ -288,7 +284,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 288 | 284 | public final <D extends ReferentialDto,
|
| 289 | 285 | R extends ReferentialDtoReference,
|
| 290 | 286 | E extends ReferentialEntity,
|
| 291 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> ReferentialDtoEntityContext<D, R, E, T> fromReferentialDto(ToolkitIdDtoBean dtoType) {
|
|
| 287 | + T extends ToolkitTopiaDao<E>> ReferentialDtoEntityContext<D, R, E, T> fromReferentialDto(ToolkitIdDtoBean dtoType) {
|
|
| 292 | 288 | @SuppressWarnings("unchecked") Class<D> type = (Class<D>) dtoType.getType();
|
| 293 | 289 | return ObservePersistenceBusinessProject.fromReferentialDto(type);
|
| 294 | 290 | }
|
| ... | ... | @@ -297,7 +293,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 297 | 293 | public final <D extends ReferentialDto,
|
| 298 | 294 | R extends ReferentialDtoReference,
|
| 299 | 295 | E extends ReferentialEntity,
|
| 300 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> ReferentialDtoEntityContext<D, R, E, T> fromReferentialDto(Class<D> dtoType) {
|
|
| 296 | + T extends ToolkitTopiaDao<E>> ReferentialDtoEntityContext<D, R, E, T> fromReferentialDto(Class<D> dtoType) {
|
|
| 301 | 297 | return ObservePersistenceBusinessProject.fromReferentialDto(dtoType);
|
| 302 | 298 | }
|
| 303 | 299 | |
| ... | ... | @@ -305,7 +301,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 305 | 301 | public final <D extends ReferentialDto,
|
| 306 | 302 | R extends ReferentialDtoReference,
|
| 307 | 303 | E extends ReferentialEntity,
|
| 308 | - T extends ObserveDaoQuerySupport & TopiaDao<E>> ReferentialDtoEntityContext<D, R, E, T> fromReferentialReference(Class<R> referenceType) {
|
|
| 304 | + T extends ToolkitTopiaDao<E>> ReferentialDtoEntityContext<D, R, E, T> fromReferentialReference(Class<R> referenceType) {
|
|
| 309 | 305 | Class<D> dtoType = ObserveReferenceDtoToDtoClassMapping.get().get(referenceType);
|
| 310 | 306 | return ObservePersistenceBusinessProject.fromReferentialDto(dtoType);
|
| 311 | 307 | }
|
| ... | ... | @@ -314,7 +310,7 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 314 | 310 | public final <D extends RootOpenableDto,
|
| 315 | 311 | R extends DataDtoReference,
|
| 316 | 312 | E extends RootOpenableEntity,
|
| 317 | - T extends ObserveDaoQuerySupport & RootOpenableEntityDao<D, R, E> & TopiaDao<E>,
|
|
| 313 | + T extends ToolkitTopiaDao<E>,
|
|
| 318 | 314 | H extends DataGroupByReferentialHelper<D, R, E>,
|
| 319 | 315 | F extends DataGroupByEntity<E>,
|
| 320 | 316 | FF extends DataGroupByDto<D>> GroupBySpiContext<D, R, E, T, H, F, FF> fromGroupByName(String parentProperty) {
|
| ... | ... | @@ -334,8 +330,8 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 334 | 330 | return validationContext;
|
| 335 | 331 | }
|
| 336 | 332 | |
| 337 | - protected final void initPersistence(String methodName, Permission methodeCredentials) {
|
|
| 338 | - serviceContext.initPersistence(methodName, methodeCredentials);
|
|
| 333 | + protected final void initPersistence(String methodName) {
|
|
| 334 | + serviceContext.initPersistence(methodName, Permission.NONE);
|
|
| 339 | 335 | }
|
| 340 | 336 | |
| 341 | 337 | public boolean initReadTransaction(String methodName, Permission methodeCredentials) {
|
| ... | ... | @@ -352,14 +348,6 @@ public abstract class ObserveServiceLocal implements ObserveService, ServiceCont |
| 352 | 348 | }
|
| 353 | 349 | }
|
| 354 | 350 | |
| 355 | - protected final ObserveTopiaPersistenceContext newReadTransaction(String methodName) {
|
|
| 356 | - return serviceContext.newReadTransaction(methodName);
|
|
| 357 | - }
|
|
| 358 | - |
|
| 359 | - protected final ObserveTopiaPersistenceContext newWriteTransaction(String methodName) {
|
|
| 360 | - return serviceContext.newWriteTransaction(methodName);
|
|
| 361 | - }
|
|
| 362 | - |
|
| 363 | 351 | protected final ObserveServiceInitializer getServiceInitializer() {
|
| 364 | 352 | return serviceContext.getServiceInitializer();
|
| 365 | 353 | }
|
| ... | ... | @@ -54,7 +54,7 @@ public abstract class TripServiceLocalSupport extends ObserveServiceLocal implem |
| 54 | 54 | |
| 55 | 55 | @Override
|
| 56 | 56 | public int getMatchingTripsVesselWithinDateRange(String tripId, String vesselId, Date startDate, Date endDate) {
|
| 57 | - return Trip.SPI.getDao(getTopiaPersistenceContext()).getMatchingTripsVesselWithinDateRange(tripId, vesselId, startDate, endDate);
|
|
| 57 | + return Trip.SPI.getMatchingTripsVesselWithinDateRange(this, tripId, vesselId, startDate, endDate);
|
|
| 58 | 58 | }
|
| 59 | 59 | |
| 60 | 60 | @Override
|
| ... | ... | @@ -64,7 +64,7 @@ public abstract class TripServiceLocalSupport extends ObserveServiceLocal implem |
| 64 | 64 | |
| 65 | 65 | @Override
|
| 66 | 66 | public TripMapDto getTripMap(TripMapConfigDto config) {
|
| 67 | - return Trip.SPI.getTripMap(getTopiaPersistenceContext(), config);
|
|
| 67 | + return Trip.SPI.getTripMap(this, config);
|
|
| 68 | 68 | }
|
| 69 | 69 | |
| 70 | 70 | public ReferentialDtoReferenceSet<SpeciesReference> getSpeciesByListAndTrip(String tripId, String speciesListId) {
|
| ... | ... | @@ -47,7 +47,7 @@ public abstract class TripServiceLocalSupport extends ObserveServiceLocal implem |
| 47 | 47 | |
| 48 | 48 | @Override
|
| 49 | 49 | public int getMatchingTripsVesselWithinDateRange(String tripId, String vesselId, Date startDate, Date endDate) {
|
| 50 | - return Trip.SPI.getDao(getTopiaPersistenceContext()).getMatchingTripsVesselWithinDateRange(tripId, vesselId, startDate, endDate);
|
|
| 50 | + return Trip.SPI.getMatchingTripsVesselWithinDateRange(this, tripId, vesselId, startDate, endDate);
|
|
| 51 | 51 | }
|
| 52 | 52 | |
| 53 | 53 | @Override
|
| ... | ... | @@ -62,7 +62,7 @@ public abstract class TripServiceLocalSupport extends ObserveServiceLocal implem |
| 62 | 62 | |
| 63 | 63 | @Override
|
| 64 | 64 | public TripMapDto getTripMap(TripMapConfigDto config) {
|
| 65 | - return Trip.SPI.getTripMap(getTopiaPersistenceContext(), config);
|
|
| 65 | + return Trip.SPI.getTripMap(this, config);
|
|
| 66 | 66 | }
|
| 67 | 67 | |
| 68 | 68 | @Override
|
| ... | ... | @@ -24,10 +24,8 @@ package fr.ird.observe.services.local.service.internal; |
| 24 | 24 | |
| 25 | 25 | import fr.ird.observe.dto.data.ContainerChildDto;
|
| 26 | 26 | import fr.ird.observe.dto.data.ContainerDto;
|
| 27 | -import fr.ird.observe.dto.data.ps.observation.SampleDto;
|
|
| 28 | 27 | import fr.ird.observe.dto.form.Form;
|
| 29 | 28 | import fr.ird.observe.dto.result.SaveResultDto;
|
| 30 | -import fr.ird.observe.entities.data.ps.observation.Sample;
|
|
| 31 | 29 | import fr.ird.observe.services.local.service.ObserveServiceLocal;
|
| 32 | 30 | import fr.ird.observe.services.service.internal.ContainerService;
|
| 33 | 31 | import fr.ird.observe.spi.context.ContainerDtoEntityContext;
|
| ... | ... | @@ -40,25 +38,16 @@ import fr.ird.observe.spi.context.ContainerDtoEntityContext; |
| 40 | 38 | */
|
| 41 | 39 | public class ContainerServiceLocalSupport extends ObserveServiceLocal implements ContainerService {
|
| 42 | 40 | |
| 43 | - @SuppressWarnings("unchecked")
|
|
| 44 | 41 | @Override
|
| 45 | 42 | public <C extends ContainerChildDto, D extends ContainerDto<C>> Form<D> loadForm(Class<D> dtoType, String parentId) {
|
| 46 | - //FIXME Find a better way to do this
|
|
| 47 | - if (SampleDto.class.equals(dtoType)) {
|
|
| 48 | - return (Form<D>) Sample.SPI.loadForm(this, parentId);
|
|
| 49 | - }
|
|
| 50 | - ContainerDtoEntityContext<?, C, D, ?, ?, ?> spi = fromContainerDto(dtoType);
|
|
| 43 | + ContainerDtoEntityContext<D, ?, ?, ?> spi = fromContainerDto(dtoType);
|
|
| 51 | 44 | return spi.loadForm(this, parentId);
|
| 52 | 45 | }
|
| 53 | 46 | |
| 54 | 47 | @Override
|
| 55 | 48 | public <C extends ContainerChildDto, D extends ContainerDto<C>> SaveResultDto save(D dto) {
|
| 56 | - //FIXME Find a better way to do this
|
|
| 57 | - if (dto instanceof SampleDto) {
|
|
| 58 | - return Sample.SPI.save(this, (SampleDto) dto);
|
|
| 59 | - }
|
|
| 60 | 49 | @SuppressWarnings("unchecked") Class<D> dtoType = (Class<D>) dto.getClass();
|
| 61 | - ContainerDtoEntityContext<?, C, D, ?, ?, ?> spi = fromContainerDto(dtoType);
|
|
| 50 | + ContainerDtoEntityContext<D, ?, ?, ?> spi = fromContainerDto(dtoType);
|
|
| 62 | 51 | return spi.save(this, dto);
|
| 63 | 52 | }
|
| 64 | 53 | } |
| ... | ... | @@ -26,7 +26,6 @@ import fr.ird.observe.dto.reference.ReferentialDtoReference; |
| 26 | 26 | import fr.ird.observe.dto.referential.ReferentialDto;
|
| 27 | 27 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 28 | 28 | import fr.ird.observe.dto.referential.common.SpeciesDto;
|
| 29 | -import fr.ird.observe.entities.ObserveDaoQuerySupport;
|
|
| 30 | 29 | import fr.ird.observe.entities.data.DataEntity;
|
| 31 | 30 | import fr.ird.observe.entities.data.RootOpenableEntity;
|
| 32 | 31 | import fr.ird.observe.entities.referential.ReferentialEntity;
|
| ... | ... | @@ -124,7 +123,7 @@ public class ValidateServiceLocalSupport extends ObserveServiceLocal implements |
| 124 | 123 | }
|
| 125 | 124 | |
| 126 | 125 | private <D extends ReferentialDto, R extends ReferentialDtoReference, E extends ReferentialEntity> void validateReferential(Class<D> dtoType, ValidationMessageDetector detector, ServiceValidationContext validationContext) {
|
| 127 | - ReferentialDtoEntityContext<D, R, E, ? extends ObserveDaoQuerySupport> spi = this.fromReferentialDto(dtoType);
|
|
| 126 | + ReferentialDtoEntityContext<D, R, E, ?> spi = this.fromReferentialDto(dtoType);
|
|
| 128 | 127 | Class<E> type = spi.toEntityType();
|
| 129 | 128 | List<E> entities = getTopiaPersistenceContext().loadEntities(type);
|
| 130 | 129 | validateReferential(dtoType, detector, validationContext, entities);
|
| ... | ... | @@ -28,8 +28,8 @@ import fr.ird.observe.dto.reference.DataDtoReference; |
| 28 | 28 | import fr.ird.observe.dto.referential.ReferentialDto;
|
| 29 | 29 | import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 30 | 30 | import fr.ird.observe.entities.Entity;
|
| 31 | -import fr.ird.observe.entities.ObserveDaoQuerySupport;
|
|
| 32 | 31 | import fr.ird.observe.entities.ObserveEntityEnum;
|
| 32 | +import fr.ird.observe.entities.ToolkitTopiaDao;
|
|
| 33 | 33 | import fr.ird.observe.entities.data.DataEntity;
|
| 34 | 34 | import fr.ird.observe.navigation.select.ProjectSelectModel;
|
| 35 | 35 | import fr.ird.observe.spi.ObservePersistenceBusinessProject;
|
| ... | ... | @@ -38,7 +38,6 @@ import fr.ird.observe.toolkit.navigation.id.NavigationModelNode; |
| 38 | 38 | import fr.ird.observe.toolkit.navigation.id.select.SelectNode;
|
| 39 | 39 | import org.apache.logging.log4j.LogManager;
|
| 40 | 40 | import org.apache.logging.log4j.Logger;
|
| 41 | -import org.nuiton.topia.persistence.TopiaDao;
|
|
| 42 | 41 | import org.nuiton.validator.bean.simple.SimpleBeanValidator;
|
| 43 | 42 | |
| 44 | 43 | import java.util.LinkedHashMap;
|
| ... | ... | @@ -108,7 +107,7 @@ public class EntityInterceptors { |
| 108 | 107 | interceptorsBuilder.put(ObserveEntityEnum.getImplementationClass(entityType), interceptor);
|
| 109 | 108 | }
|
| 110 | 109 | |
| 111 | - static <D extends DataDto, R extends DataDtoReference, E extends DataEntity,T extends ObserveDaoQuerySupport & TopiaDao<E>> void toData(Class<D> dtoType, NavigationModelNode<D> consumer, Map<Class<?>, EntityInterceptor<?, ?, ?>> interceptorsBuilder, ValidatorsMap validators, ReferentialLocale referentialLocale) {
|
|
| 110 | + static <D extends DataDto, R extends DataDtoReference, E extends DataEntity, T extends ToolkitTopiaDao<E>> void toData(Class<D> dtoType, NavigationModelNode<D> consumer, Map<Class<?>, EntityInterceptor<?, ?, ?>> interceptorsBuilder, ValidatorsMap validators, ReferentialLocale referentialLocale) {
|
|
| 112 | 111 | SimpleBeanValidator<D> validator = validators.getValidator(dtoType);
|
| 113 | 112 | if (validator == null) {
|
| 114 | 113 | log.warn(String.format("Not a main type (%s), skip it", dtoType));
|