Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
35a7ad77
by Tony Chemit at 2021-03-14T11:13:52+01:00
21 changed files:
- models/persistence/java/src/main/java/fr/ird/observe/entities/data/ll/common/TripImpl.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/ObserveServiceLocal.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ContainerDataServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/EditableDataServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/OpenableDataServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/SimpleDataServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/TripServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/common/TripServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/landing/LandingServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/ActivitySampleServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/ActivityServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/SampleServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/SetServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/ActivityServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/BranchlineServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/SetServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/ActivityServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/FloatingObjectServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/RouteServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/SampleDataServiceLocalSupport.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/SetServiceLocalSupport.java
Changes:
| ... | ... | @@ -26,6 +26,8 @@ import fr.ird.observe.dto.data.DataDto; |
| 26 | 26 |
import fr.ird.observe.dto.data.ll.common.TripDto;
|
| 27 | 27 |
import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 28 | 28 |
import io.ultreia.java4all.util.Dates;
|
| 29 |
+import org.apache.logging.log4j.LogManager;
|
|
| 30 |
+import org.apache.logging.log4j.Logger;
|
|
| 29 | 31 |
|
| 30 | 32 |
import java.util.Date;
|
| 31 | 33 |
|
| ... | ... | @@ -36,9 +38,39 @@ import java.util.Date; |
| 36 | 38 |
* @since 3.7
|
| 37 | 39 |
*/
|
| 38 | 40 |
public class TripImpl extends TripAbstract {
|
| 39 |
- |
|
| 41 |
+ private static final Logger log = LogManager.getLogger(TripImpl.class);
|
|
| 40 | 42 |
private static final long serialVersionUID = 1L;
|
| 41 | 43 |
|
| 44 |
+ @SuppressWarnings("UnusedReturnValue")
|
|
| 45 |
+ public static boolean copyTripLogbookMetaData(Trip oldTrip, Trip newTrip) {
|
|
| 46 |
+ if (!newTrip.isLogbookAvailability()) {
|
|
| 47 |
+ // copy logbook meta-data to new trip
|
|
| 48 |
+ log.info(String.format("Add logbook metadata to trip: %s", newTrip.getTopiaId()));
|
|
| 49 |
+ newTrip.setLogbookAvailability(true);
|
|
| 50 |
+ newTrip.setLogbookComment(oldTrip.getLogbookComment());
|
|
| 51 |
+ newTrip.setLogbookDataEntryOperator(oldTrip.getLogbookDataEntryOperator());
|
|
| 52 |
+ newTrip.setLogbookDataQuality(oldTrip.getLogbookDataQuality());
|
|
| 53 |
+ return true;
|
|
| 54 |
+ }
|
|
| 55 |
+ return false;
|
|
| 56 |
+ }
|
|
| 57 |
+ |
|
| 58 |
+ @SuppressWarnings("UnusedReturnValue")
|
|
| 59 |
+ public static boolean copyTripObservationMetaData(Trip oldTrip, Trip newTrip) {
|
|
| 60 |
+ if (!newTrip.isObservationsAvailability()) {
|
|
| 61 |
+ // copy observation meta-data to new trip
|
|
| 62 |
+ log.info(String.format("Add observation metadata to trip: %s", newTrip.getTopiaId()));
|
|
| 63 |
+ newTrip.setObservationsAvailability(true);
|
|
| 64 |
+ newTrip.setObservationsComment(oldTrip.getObservationsComment());
|
|
| 65 |
+ newTrip.setObservationMethod(oldTrip.getObservationMethod());
|
|
| 66 |
+ newTrip.setObserver(oldTrip.getObserver());
|
|
| 67 |
+ newTrip.setObservationsDataEntryOperator(oldTrip.getObservationsDataEntryOperator());
|
|
| 68 |
+ newTrip.setObservationsDataQuality(oldTrip.getObservationsDataQuality());
|
|
| 69 |
+ return true;
|
|
| 70 |
+ }
|
|
| 71 |
+ return false;
|
|
| 72 |
+ }
|
|
| 73 |
+ |
|
| 42 | 74 |
@Override
|
| 43 | 75 |
public <D extends DataDto> void toDto(ReferentialLocale referentialLocale, D dto) {
|
| 44 | 76 |
super.toDto(referentialLocale, dto);
|
| ... | ... | @@ -42,6 +42,7 @@ import fr.ird.observe.entities.ObserveTopiaApplicationContext; |
| 42 | 42 |
import fr.ird.observe.entities.ObserveTopiaApplicationContextFactory;
|
| 43 | 43 |
import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
| 44 | 44 |
import fr.ird.observe.entities.PersistenceResult;
|
| 45 |
+import fr.ird.observe.entities.ReplicateDataEngine;
|
|
| 45 | 46 |
import fr.ird.observe.entities.data.DataEntity;
|
| 46 | 47 |
import fr.ird.observe.entities.referential.ReferentialEntity;
|
| 47 | 48 |
import fr.ird.observe.security.Permission;
|
| ... | ... | @@ -160,23 +161,6 @@ public abstract class ObserveServiceLocal implements ObserveService { |
| 160 | 161 |
return persistenceContext;
|
| 161 | 162 |
}
|
| 162 | 163 |
|
| 163 |
- protected ObserveTopiaPersistenceContext initTransaction() {
|
|
| 164 |
- if (serviceContext.getTopiaApplicationContext() == null) {
|
|
| 165 |
- ObserveTopiaApplicationContext topiaApplicationContext;
|
|
| 166 |
- ObserveDataSourceConfigurationTopiaSupport dataSourceConfiguration;
|
|
| 167 |
- ObserveServiceInitializer initializer = serviceContext.getServiceInitializer();
|
|
| 168 |
- if (initializer.withConnection()) {
|
|
| 169 |
- String authenticationToken = initializer.getConnection().getAuthenticationToken();
|
|
| 170 |
- topiaApplicationContext = ObserveTopiaApplicationContextFactory.getTopiaApplicationContext(authenticationToken);
|
|
| 171 |
- } else {
|
|
| 172 |
- dataSourceConfiguration = (ObserveDataSourceConfigurationTopiaSupport) initializer.getConfiguration();
|
|
| 173 |
- topiaApplicationContext = ObserveTopiaApplicationContextFactory.getOrCreateTopiaApplicationContext(dataSourceConfiguration);
|
|
| 174 |
- }
|
|
| 175 |
- serviceContext.setTopiaApplicationContext(topiaApplicationContext);
|
|
| 176 |
- }
|
|
| 177 |
- return serviceContext.getTopiaPersistenceContext();
|
|
| 178 |
- }
|
|
| 179 |
- |
|
| 180 | 164 |
protected void checkCredentials(String methodName, Permission methodeCredentials) {
|
| 181 | 165 |
if (methodeCredentials != null && serviceContext.getServiceInitializer().withConnection()) {
|
| 182 | 166 |
ObserveDataSourceConnectionTopia dataSourceConnection = (ObserveDataSourceConnectionTopia) serviceContext.getServiceInitializer().getConnection();
|
| ... | ... | @@ -190,75 +174,16 @@ public abstract class ObserveServiceLocal implements ObserveService { |
| 190 | 174 |
return PersistenceResult.create(getTopiaPersistenceContext(), this::now);
|
| 191 | 175 |
}
|
| 192 | 176 |
|
| 177 |
+ protected ReplicateDataEngine newReplicateDataEngine() {
|
|
| 178 |
+ return serviceContext.getTopiaApplicationContext().newReplicateDataEngine(getTopiaPersistenceContext());
|
|
| 179 |
+ }
|
|
| 180 |
+ |
|
| 193 | 181 |
protected <E extends Entity> SaveResultDto saveEntity(DtoEntityContext<?, ?, E, ?> spi, E entity) {
|
| 194 | 182 |
return newSaveHelper()
|
| 195 | 183 |
.update(spi, entity)
|
| 196 |
- .updateLastUpdateDateField(spi, entity)
|
|
| 197 |
- .updateLastUpdateDateTable(spi)
|
|
| 198 | 184 |
.build(entity);
|
| 199 |
-// entity = spi.update(getTopiaPersistenceContext(), entity);
|
|
| 200 |
-// getTopiaPersistenceContext().flush();
|
|
| 201 |
-// Date lastUpdateDate = now();
|
|
| 202 |
-// spi.updateLastUpdateDateField(getTopiaPersistenceContext(), entity.getTopiaId(), lastUpdateDate);
|
|
| 203 |
-// spi.updateLastUpdateDateTable(getTopiaPersistenceContext(), lastUpdateDate);
|
|
| 204 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 205 | 185 |
}
|
| 206 | 186 |
|
| 207 |
-// protected <E extends Entity> SaveResultDto saveEntity(DataDtoEntityContext<?, ?, ?, ?> parentSpi, DataDtoEntityContext spi, E entity) {
|
|
| 208 |
-// spi.update(getTopiaPersistenceContext(), entity);
|
|
| 209 |
-// getTopiaPersistenceContext().flush();
|
|
| 210 |
-// Date lastUpdateDate = now();
|
|
| 211 |
-// parentSpi.updateLastUpdateDateField(getTopiaPersistenceContext(), entity.getTopiaId(), lastUpdateDate);
|
|
| 212 |
-// spi.updateLastUpdateDateTable(getTopiaPersistenceContext(), lastUpdateDate);
|
|
| 213 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 214 |
-// }
|
|
| 215 |
- |
|
| 216 |
-// protected <E extends Entity> SaveResultDto saveEntity(DataDtoEntityContext<?, ?, ?, ?> parentSpi, DataDtoEntityContext spi, E entity, BiConsumer<E, Date> children) {
|
|
| 217 |
-// spi.update(getTopiaPersistenceContext(), entity);
|
|
| 218 |
-// getTopiaPersistenceContext().flush();
|
|
| 219 |
-// Date lastUpdateDate = now();
|
|
| 220 |
-// children.accept(entity, lastUpdateDate);
|
|
| 221 |
-// parentSpi.updateLastUpdateDateField(getTopiaPersistenceContext(), entity.getTopiaId(), lastUpdateDate);
|
|
| 222 |
-// spi.updateLastUpdateDateTable(getTopiaPersistenceContext(), lastUpdateDate);
|
|
| 223 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 224 |
-// }
|
|
| 225 |
- |
|
| 226 |
-// protected <E extends DataEntity> SaveResultDto saveEntity(DataDtoEntityContext<?, ?, E, ?> parentSpi, E entity, BiConsumer<E, Date> children) {
|
|
| 227 |
-// parentSpi.update(getTopiaPersistenceContext(), entity);
|
|
| 228 |
-// getTopiaPersistenceContext().flush();
|
|
| 229 |
-// Date lastUpdateDate = now();
|
|
| 230 |
-// children.accept(entity, lastUpdateDate);
|
|
| 231 |
-// parentSpi.updateLastUpdateDateField(getTopiaPersistenceContext(), entity.getTopiaId(), lastUpdateDate);
|
|
| 232 |
-// parentSpi.updateLastUpdateDateTable(getTopiaPersistenceContext(), lastUpdateDate);
|
|
| 233 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 234 |
-// }
|
|
| 235 |
- |
|
| 236 |
-// protected <P extends DataEntity<?, ?>, E extends DataEntity<?, ?>> SaveResultDto saveEntity(DataDtoEntityContext<?, ?, P, ?> parentSpi, P parenEntity, E entity) {
|
|
| 237 |
-// Date lastUpdateDate = now();
|
|
| 238 |
-// ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
|
|
| 239 |
-// persistenceContext.flush();
|
|
| 240 |
-// parentSpi.updateLastUpdateDateField(persistenceContext, parenEntity.getTopiaId(), lastUpdateDate);
|
|
| 241 |
-// parentSpi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 242 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 243 |
-// }
|
|
| 244 |
- |
|
| 245 |
-// protected <P extends DataEntity<?, ?>, E extends DataEntity<?, ?>> SaveResultDto saveEntity(DataDtoEntityContext<?, ?, P, ?> parentSpi, DataDtoEntityContext<?, ?, E, ?> spi, P parenEntity, E entity) {
|
|
| 246 |
-// spi.update(getTopiaPersistenceContext(), entity);
|
|
| 247 |
-// Date lastUpdateDate = now();
|
|
| 248 |
-// ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
|
|
| 249 |
-// persistenceContext.flush();
|
|
| 250 |
-// parentSpi.updateLastUpdateDateField(persistenceContext, parenEntity.getTopiaId(), lastUpdateDate);
|
|
| 251 |
-// spi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 252 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 253 |
-// }
|
|
| 254 |
- |
|
| 255 |
-// protected <E extends Entity> SaveResultDto toSaveResult(E entity, Date lastUpdateDate) {
|
|
| 256 |
-// SaveResultDto result = new SaveResultDto();
|
|
| 257 |
-// EntityHelper.toDto(entity, result);
|
|
| 258 |
-// result.setLastUpdateDate(lastUpdateDate);
|
|
| 259 |
-// return result;
|
|
| 260 |
-// }
|
|
| 261 |
- |
|
| 262 | 187 |
protected <E extends Entity> void checkLastUpdateDate(E entity, IdDto dto) {
|
| 263 | 188 |
if (entity.isPersisted()) {
|
| 264 | 189 |
Date lastUpdateDate = entity.getLastUpdateDate();
|
| ... | ... | @@ -313,14 +238,14 @@ public abstract class ObserveServiceLocal implements ObserveService { |
| 313 | 238 |
return ReferentialDtoReferenceSet.of(spi.toReferenceType(), references.build(), lastUpdate);
|
| 314 | 239 |
}
|
| 315 | 240 |
|
| 316 |
- protected void deleteSingleAssociation(String idToDelete,
|
|
| 317 |
- DataDtoEntityContext<?, ?, ?, ?> spi,
|
|
| 318 |
- DtoEntityContext<?, ?, ?, ?> parentSpi,
|
|
| 319 |
- String associationName) {
|
|
| 241 |
+ protected <E extends DataEntity<?, ?>, PE extends Entity> void deleteSingleAssociation(String idToDelete,
|
|
| 242 |
+ DataDtoEntityContext<?, ?, E, ?> spi,
|
|
| 243 |
+ DtoEntityContext<?, ?, PE, ?> parentSpi,
|
|
| 244 |
+ String associationName) {
|
|
| 320 | 245 |
|
| 321 |
- DataEntity<?, ?> entityToDelete = spi.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), idToDelete);
|
|
| 322 |
- Entity parentEntity = getTopiaPersistenceContext().getSingleAssociationParent(getApplicationLocale(), parentSpi.toEntityType(), associationName, idToDelete);
|
|
| 323 |
- Object realChild = parentEntity.get(associationName);
|
|
| 246 |
+ E entityToDelete = spi.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), idToDelete);
|
|
| 247 |
+ PE parentEntity = getTopiaPersistenceContext().getSingleAssociationParent(getApplicationLocale(), parentSpi.toEntityType(), associationName, idToDelete);
|
|
| 248 |
+ E realChild = parentEntity.get(associationName);
|
|
| 324 | 249 |
if (!Objects.equals(entityToDelete, realChild)) {
|
| 325 | 250 |
throw new DataNotFoundException(getApplicationLocale(), spi.toDtoType(), idToDelete);
|
| 326 | 251 |
}
|
| ... | ... | @@ -328,10 +253,10 @@ public abstract class ObserveServiceLocal implements ObserveService { |
| 328 | 253 |
afterDeleteAssociationEntity(parentSpi, spi, parentEntity);
|
| 329 | 254 |
}
|
| 330 | 255 |
|
| 331 |
- protected <E extends Entity> void deleteMultipleAssociation(DtoEntityContext<?, ?, E, ?> parentSpi, String associationName, DataDtoEntityContext<?, ?, ?, ?> spi, String idToDelete) {
|
|
| 256 |
+ protected <E extends DataEntity<?, ?>, PE extends Entity> void deleteMultipleAssociation(DtoEntityContext<?, ?, PE, ?> parentSpi, String associationName, DataDtoEntityContext<?, ?, E, ?> spi, String idToDelete) {
|
|
| 332 | 257 |
|
| 333 |
- DataEntity<?, ?> entityToDelete = spi.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), idToDelete);
|
|
| 334 |
- E parentEntity = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), parentSpi.toEntityType(), associationName, idToDelete);
|
|
| 258 |
+ E entityToDelete = spi.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), idToDelete);
|
|
| 259 |
+ PE parentEntity = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), parentSpi.toEntityType(), associationName, idToDelete);
|
|
| 335 | 260 |
Collection<?> realChild = parentEntity.get(associationName);
|
| 336 | 261 |
if (!realChild.contains(entityToDelete)) {
|
| 337 | 262 |
throw new DataNotFoundException(getApplicationLocale(), spi.toDtoType(), idToDelete);
|
| ... | ... | @@ -354,11 +279,11 @@ public abstract class ObserveServiceLocal implements ObserveService { |
| 354 | 279 |
return spi.toReferenceSet(referentialLocale, parents.stream(), id, now());
|
| 355 | 280 |
}
|
| 356 | 281 |
|
| 357 |
- private <E extends Entity> void afterDeleteAssociationEntity(DtoEntityContext<?, ?, ?, ?> parentSpi, DataDtoEntityContext<?, ?, ?, ?> spi, E parentEntity) {
|
|
| 358 |
- Date lastUpdateDate = now();
|
|
| 359 |
- getTopiaPersistenceContext().flush();
|
|
| 360 |
- parentSpi.updateLastUpdateDateField(getTopiaPersistenceContext(), parentEntity.getTopiaId(), lastUpdateDate);
|
|
| 361 |
- spi.updateLastUpdateDateTable(getTopiaPersistenceContext(), lastUpdateDate);
|
|
| 282 |
+ private <E extends DataEntity<?, ?>, PE extends Entity> void afterDeleteAssociationEntity(DtoEntityContext<?, ?, PE, ?> parentSpi, DataDtoEntityContext<?, ?, E, ?> spi, PE parentEntity) {
|
|
| 283 |
+ newSaveHelper()
|
|
| 284 |
+ .updateLastUpdateDateField(parentSpi, parentEntity)
|
|
| 285 |
+ .updateLastUpdateDateTable(spi)
|
|
| 286 |
+ .build();
|
|
| 362 | 287 |
}
|
| 363 | 288 |
}
|
| 364 | 289 |
|
| ... | ... | @@ -71,8 +71,7 @@ public class ContainerDataServiceLocalSupport<PE extends DataEntity<?, ?>, D ext |
| 71 | 71 |
checkLastUpdateDate(entity, dto);
|
| 72 | 72 |
entity.fromDto(getReferentialLocale(), dto);
|
| 73 | 73 |
return newSaveHelper()
|
| 74 |
- .update(parentSpi, entity, saveCallback)
|
|
| 75 |
- .updateLastUpdateDateField(parentSpi, entity)
|
|
| 74 |
+ .update(parentSpi, entity, saveCallback, true, false)
|
|
| 76 | 75 |
.updateLastUpdateDateTable(spi)
|
| 77 | 76 |
.build(entity);
|
| 78 | 77 |
// if (saveCallback == null) {
|
| ... | ... | @@ -45,7 +45,7 @@ import java.util.stream.Stream; |
| 45 | 45 |
* @author Tony Chemit - dev@tchemit.fr
|
| 46 | 46 |
* @since 8.0.1
|
| 47 | 47 |
*/
|
| 48 |
-public abstract class EditableDataServiceLocalSupport<PE extends Entity, D extends EditableDto, R extends DataDtoReference, E extends DataEntity<?, ?>, T extends TopiaDao<E>, S extends SaveResultDto> extends ObserveServiceLocal implements EditableDataService<D, R> {
|
|
| 48 |
+public abstract class EditableDataServiceLocalSupport<PE extends Entity, D extends EditableDto, R extends DataDtoReference, E extends DataEntity<?, ?>, T extends TopiaDao<E>> extends ObserveServiceLocal implements EditableDataService<D, R> {
|
|
| 49 | 49 |
|
| 50 | 50 |
protected final DataDtoEntityContext<D, R, E, T> spi;
|
| 51 | 51 |
protected final DtoEntityContext<?, ?, PE, ?> parentSpi;
|
| ... | ... | @@ -159,17 +159,4 @@ public abstract class EditableDataServiceLocalSupport<PE extends Entity, D exten |
| 159 | 159 |
return getSingleAssociationParent(parentSpi, propertyName, id);
|
| 160 | 160 |
}
|
| 161 | 161 |
|
| 162 |
-// protected SaveResultDto saveEntity(E entity) {
|
|
| 163 |
-// return saveEntity(spi, entity);
|
|
| 164 |
-// }
|
|
| 165 |
- |
|
| 166 |
-// protected SaveResultDto saveEntity(PE parenEntity, E entity) {
|
|
| 167 |
-// spi.update(getTopiaPersistenceContext(), entity);
|
|
| 168 |
-// ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
|
|
| 169 |
-// persistenceContext.flush();
|
|
| 170 |
-// Date lastUpdateDate = now();
|
|
| 171 |
-// parentSpi.updateLastUpdateDateField(persistenceContext, parenEntity.getTopiaId(), lastUpdateDate);
|
|
| 172 |
-// spi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 173 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 174 |
-// }
|
|
| 175 | 162 |
}
|
| ... | ... | @@ -31,7 +31,6 @@ import fr.ird.observe.dto.reference.DataDtoReferenceSet; |
| 31 | 31 |
import fr.ird.observe.dto.reference.UpdatedDataDtoReferenceSet;
|
| 32 | 32 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 33 | 33 |
import fr.ird.observe.entities.Entity;
|
| 34 |
-import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
|
| 35 | 34 |
import fr.ird.observe.entities.PersistenceResult;
|
| 36 | 35 |
import fr.ird.observe.entities.ReplicateDataEngine;
|
| 37 | 36 |
import fr.ird.observe.entities.data.DataEntity;
|
| ... | ... | @@ -148,8 +147,7 @@ public abstract class OpenableDataServiceLocalSupport<PE extends Entity, D exten |
| 148 | 147 |
Collection<E> oldCollection = getChildren0(oldParent);
|
| 149 | 148 |
Collection<E> newCollection = getChildren0(newParent);
|
| 150 | 149 |
List<E> moved = new LinkedList<>();
|
| 151 |
- ObserveTopiaPersistenceContext topiaPersistenceContext = getTopiaPersistenceContext();
|
|
| 152 |
- ReplicateDataEngine replicateEngine = serviceContext.getTopiaApplicationContext().newReplicateDataEngine(topiaPersistenceContext);
|
|
| 150 |
+ ReplicateDataEngine replicateEngine = newReplicateDataEngine();
|
|
| 153 | 151 |
|
| 154 | 152 |
for (String id : ids) {
|
| 155 | 153 |
E entity = loadEntity(id);
|
| ... | ... | @@ -282,28 +280,4 @@ public abstract class OpenableDataServiceLocalSupport<PE extends Entity, D exten |
| 282 | 280 |
protected PE getParent(String id) {
|
| 283 | 281 |
return getParent(parentSpi, propertyName, id);
|
| 284 | 282 |
}
|
| 285 |
- |
|
| 286 |
-// protected SaveResultDto saveEntity(E entity) {
|
|
| 287 |
-// return saveEntity(spi, entity);
|
|
| 288 |
-// }
|
|
| 289 |
- |
|
| 290 |
-// protected void saveParentEntity(PE oldParent, PE newParent, Collection<String> ids) {
|
|
| 291 |
-// ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
|
|
| 292 |
-// persistenceContext.flush();
|
|
| 293 |
-// Date lastUpdateDate = now();
|
|
| 294 |
-// parentSpi.updateLastUpdateDateField(persistenceContext, oldParent.getTopiaId(), lastUpdateDate);
|
|
| 295 |
-// parentSpi.updateLastUpdateDateField(persistenceContext, newParent.getTopiaId(), lastUpdateDate);
|
|
| 296 |
-// ids.forEach(id -> spi.updateLastUpdateDateField(persistenceContext, id, lastUpdateDate));
|
|
| 297 |
-// spi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 298 |
-// }
|
|
| 299 |
- |
|
| 300 |
-// protected SaveResultDto saveEntity(PE parenEntity, E entity) {
|
|
| 301 |
-// spi.update(getTopiaPersistenceContext(), entity);
|
|
| 302 |
-// ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
|
|
| 303 |
-// persistenceContext.flush();
|
|
| 304 |
-// Date lastUpdateDate = now();
|
|
| 305 |
-// parentSpi.updateLastUpdateDateField(persistenceContext, parenEntity.getTopiaId(), lastUpdateDate);
|
|
| 306 |
-// spi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 307 |
-// return toSaveResult(entity, lastUpdateDate);
|
|
| 308 |
-// }
|
|
| 309 | 283 |
}
|
| ... | ... | @@ -64,8 +64,7 @@ public class SimpleDataServiceLocalSupport<PE extends DataEntity<?, ?>, M extend |
| 64 | 64 |
checkLastUpdateDate(entity, dto);
|
| 65 | 65 |
entity.fromDto(getReferentialLocale(), dto);
|
| 66 | 66 |
return newSaveHelper()
|
| 67 |
- .update(parentSpi, entity, saveCallback)
|
|
| 68 |
- .updateLastUpdateDateField(parentSpi, entity)
|
|
| 67 |
+ .update(parentSpi, entity, saveCallback, true, false)
|
|
| 69 | 68 |
.updateLastUpdateDateTable(spi)
|
| 70 | 69 |
.build(entity);
|
| 71 | 70 |
// if (saveCallback == null) {
|
| ... | ... | @@ -164,7 +164,7 @@ public abstract class TripServiceLocalSupport<D extends OpenableDto & fr.ird.obs |
| 164 | 164 |
saveHelper.updateLastUpdateDateField(spi, entity);
|
| 165 | 165 |
// saveEntity(spi, entity);
|
| 166 | 166 |
}
|
| 167 |
- saveHelper.build();
|
|
| 167 |
+ saveHelper.updateLastUpdateDateTable(spi).build();
|
|
| 168 | 168 |
return ids;
|
| 169 | 169 |
}
|
| 170 | 170 |
|
| ... | ... | @@ -28,45 +28,12 @@ import fr.ird.observe.entities.data.ll.common.Trip; |
| 28 | 28 |
import fr.ird.observe.entities.data.ll.common.TripTopiaDao;
|
| 29 | 29 |
import fr.ird.observe.entities.referential.common.Program;
|
| 30 | 30 |
import fr.ird.observe.services.service.data.ll.common.TripService;
|
| 31 |
-import org.apache.logging.log4j.LogManager;
|
|
| 32 |
-import org.apache.logging.log4j.Logger;
|
|
| 33 | 31 |
|
| 34 | 32 |
/**
|
| 35 | 33 |
* @author Tony Chemit - dev@tchemit.fr
|
| 36 | 34 |
*/
|
| 37 | 35 |
public class TripServiceLocalSupport extends fr.ird.observe.services.local.service.data.TripServiceLocalSupport<TripDto, TripReference, Trip, TripTopiaDao> implements TripService {
|
| 38 | 36 |
|
| 39 |
- private static final Logger log = LogManager.getLogger(TripServiceLocalSupport.class);
|
|
| 40 |
- |
|
| 41 |
- public static boolean copyTripLogbookMetaData(Trip oldTrip, Trip newTrip) {
|
|
| 42 |
- if (!newTrip.isLogbookAvailability()) {
|
|
| 43 |
- // copy logbook meta-data to new trip
|
|
| 44 |
- log.info(String.format("Add logbook metadata to trip: %s", newTrip.getTopiaId()));
|
|
| 45 |
- newTrip.setLogbookAvailability(true);
|
|
| 46 |
- newTrip.setLogbookComment(oldTrip.getLogbookComment());
|
|
| 47 |
- newTrip.setLogbookDataEntryOperator(oldTrip.getLogbookDataEntryOperator());
|
|
| 48 |
- newTrip.setLogbookDataQuality(oldTrip.getLogbookDataQuality());
|
|
| 49 |
- return true;
|
|
| 50 |
- }
|
|
| 51 |
- return false;
|
|
| 52 |
- }
|
|
| 53 |
- |
|
| 54 |
- @SuppressWarnings("UnusedReturnValue")
|
|
| 55 |
- public static boolean copyTripObservationMetaData(Trip oldTrip, Trip newTrip) {
|
|
| 56 |
- if (!newTrip.isObservationsAvailability()) {
|
|
| 57 |
- // copy observation meta-data to new trip
|
|
| 58 |
- log.info(String.format("Add observation metadata to trip: %s", newTrip.getTopiaId()));
|
|
| 59 |
- newTrip.setObservationsAvailability(true);
|
|
| 60 |
- newTrip.setObservationsComment(oldTrip.getObservationsComment());
|
|
| 61 |
- newTrip.setObservationMethod(oldTrip.getObservationMethod());
|
|
| 62 |
- newTrip.setObserver(oldTrip.getObserver());
|
|
| 63 |
- newTrip.setObservationsDataEntryOperator(oldTrip.getObservationsDataEntryOperator());
|
|
| 64 |
- newTrip.setObservationsDataQuality(oldTrip.getObservationsDataQuality());
|
|
| 65 |
- return true;
|
|
| 66 |
- }
|
|
| 67 |
- return false;
|
|
| 68 |
- }
|
|
| 69 |
- |
|
| 70 | 37 |
public TripServiceLocalSupport() {
|
| 71 | 38 |
super(Program.SPI, Trip.SPI, Trip.PROPERTY_PROGRAM);
|
| 72 | 39 |
}
|
| ... | ... | @@ -44,18 +44,4 @@ class LandingServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, L |
| 44 | 44 |
preCreated.setStartDate(parent.getEndDate());
|
| 45 | 45 |
}
|
| 46 | 46 |
|
| 47 |
-// @Override
|
|
| 48 |
-// protected SaveResultDto onSave(Trip parent, Landing entity, LandingDto dto) {
|
|
| 49 |
-// if (dto.isNotPersisted()) {
|
|
| 50 |
-// parent.addLanding(entity);
|
|
| 51 |
-// }
|
|
| 52 |
-// parent.updateEndDate();
|
|
| 53 |
-// //FIXME Check this is ok to not do this
|
|
| 54 |
-// return newSaveHelper()
|
|
| 55 |
-// .update(spi, entity)
|
|
| 56 |
-// .updateLastUpdateDateField(parentSpi, parent)
|
|
| 57 |
-// .updateLastUpdateDateTable(spi)
|
|
| 58 |
-// .build(entity);
|
|
| 59 |
-// }
|
|
| 60 |
- |
|
| 61 | 47 |
}
|
| ... | ... | @@ -31,27 +31,23 @@ import fr.ird.observe.dto.reference.DataDtoReferenceSet; |
| 31 | 31 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 32 | 32 |
import fr.ird.observe.entities.DataNotFoundException;
|
| 33 | 33 |
import fr.ird.observe.entities.Entity;
|
| 34 |
-import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
|
| 35 | 34 |
import fr.ird.observe.entities.ReplicateDataEngine;
|
| 36 |
-import fr.ird.observe.entities.data.DataEntity;
|
|
| 37 | 35 |
import fr.ird.observe.entities.data.TripAware;
|
| 38 | 36 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 37 |
+import fr.ird.observe.entities.data.ll.common.TripImpl;
|
|
| 39 | 38 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 40 | 39 |
import fr.ird.observe.entities.data.ll.logbook.Sample;
|
| 41 | 40 |
import fr.ird.observe.entities.data.ll.logbook.SampleTopiaDao;
|
| 42 | 41 |
import fr.ird.observe.entities.referential.common.Program;
|
| 43 | 42 |
import fr.ird.observe.services.local.service.data.EditableDataServiceLocalSupport;
|
| 44 |
-import fr.ird.observe.services.local.service.data.ll.common.TripServiceLocalSupport;
|
|
| 45 | 43 |
import fr.ird.observe.services.service.data.ll.logbook.ActivitySampleService;
|
| 46 |
-import fr.ird.observe.spi.context.DataDtoEntityContext;
|
|
| 47 | 44 |
|
| 48 |
-import java.util.Date;
|
|
| 49 | 45 |
import java.util.stream.Stream;
|
| 50 | 46 |
|
| 51 | 47 |
/**
|
| 52 | 48 |
* @author Tony Chemit - dev@tchemit.fr
|
| 53 | 49 |
*/
|
| 54 |
-class ActivitySampleServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, ActivitySampleDto, ActivitySampleReference, Sample, SampleTopiaDao, SaveResultDto> implements ActivitySampleService {
|
|
| 50 |
+class ActivitySampleServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, ActivitySampleDto, ActivitySampleReference, Sample, SampleTopiaDao> implements ActivitySampleService {
|
|
| 55 | 51 |
|
| 56 | 52 |
public ActivitySampleServiceLocalSupport() {
|
| 57 | 53 |
super(Activity.SPI, Sample.ACTIVITY_SAMPLE_SPI, Activity.PROPERTY_SAMPLE);
|
| ... | ... | @@ -74,13 +70,11 @@ class ActivitySampleServiceLocalSupport extends EditableDataServiceLocalSupport< |
| 74 | 70 |
@Override
|
| 75 | 71 |
protected SaveResultDto onSave(Activity parent, Sample entity, ActivitySampleDto dto) {
|
| 76 | 72 |
parent.setSample(entity);
|
| 77 |
- //FIXME Why we are using this ???
|
|
| 73 |
+ // As the sample is mainly associated to trip, updating only entity won't update the activity and his ancestor
|
|
| 78 | 74 |
return newSaveHelper()
|
| 79 |
- .update(spi, entity)
|
|
| 75 |
+ .update(spi, entity, false, true)
|
|
| 80 | 76 |
.updateLastUpdateDateField(parentSpi, parent)
|
| 81 |
- .updateLastUpdateDateTable(spi)
|
|
| 82 | 77 |
.build(entity);
|
| 83 |
-// return saveEntity(parent, entity);
|
|
| 84 | 78 |
}
|
| 85 | 79 |
|
| 86 | 80 |
@Override
|
| ... | ... | @@ -92,7 +86,7 @@ class ActivitySampleServiceLocalSupport extends EditableDataServiceLocalSupport< |
| 92 | 86 |
if (!sampleLogbookId.equals(sample.getTopiaId())) {
|
| 93 | 87 |
throw new DataNotFoundException(getApplicationLocale(), ActivitySampleDto.class, sampleLogbookId);
|
| 94 | 88 |
}
|
| 95 |
- ReplicateDataEngine replicateEngine = serviceContext.getTopiaApplicationContext().newReplicateDataEngine(getTopiaPersistenceContext());
|
|
| 89 |
+ ReplicateDataEngine replicateEngine = newReplicateDataEngine();
|
|
| 96 | 90 |
Sample replicateData = replicateEngine.replicate(sample);
|
| 97 | 91 |
if (newParent instanceof Activity) {
|
| 98 | 92 |
replicateEngine.flush(Sample.class);
|
| ... | ... | @@ -105,7 +99,11 @@ class ActivitySampleServiceLocalSupport extends EditableDataServiceLocalSupport< |
| 105 | 99 |
private ImmutableSet<String> moveToActivity(Activity oldActivity, Activity newActivity, Sample sample) {
|
| 106 | 100 |
oldActivity.setSample(null);
|
| 107 | 101 |
newActivity.setSample(sample);
|
| 108 |
- saveEntity2(Activity.SPI, Activity.SPI, oldActivity, newActivity);
|
|
| 102 |
+ newSaveHelper()
|
|
| 103 |
+ .update(Activity.SPI, oldActivity)
|
|
| 104 |
+ .update(Activity.SPI, newActivity, (activity, date) -> activity.getSample().setLastUpdateDate(date))
|
|
| 105 |
+ .updateLastUpdateDateTable(spi)
|
|
| 106 |
+ .build();
|
|
| 109 | 107 |
return ImmutableSet.of(sample.getTopiaId());
|
| 110 | 108 |
}
|
| 111 | 109 |
|
| ... | ... | @@ -113,24 +111,15 @@ class ActivitySampleServiceLocalSupport extends EditableDataServiceLocalSupport< |
| 113 | 111 |
Trip oldTrip = getParent(Trip.SPI, Trip.PROPERTY_ACTIVITY_LOGBOOK, oldActivity.getTopiaId());
|
| 114 | 112 |
oldActivity.setSample(null);
|
| 115 | 113 |
newTrip.addSample(sample);
|
| 116 |
- TripServiceLocalSupport.copyTripLogbookMetaData(oldTrip, newTrip);
|
|
| 117 |
- saveEntity2(Trip.SPI, Activity.SPI, newTrip, oldActivity);
|
|
| 114 |
+ TripImpl.copyTripLogbookMetaData(oldTrip, newTrip);
|
|
| 115 |
+ newSaveHelper()
|
|
| 116 |
+ .update(Activity.SPI, oldActivity)
|
|
| 117 |
+ .update(spi, sample)
|
|
| 118 |
+ .build();
|
|
| 118 | 119 |
return ImmutableSet.of(sample.getTopiaId());
|
| 119 | 120 |
}
|
| 120 | 121 |
|
| 121 | 122 |
protected Stream<Trip> getTrips(Program program) {
|
| 122 | 123 |
return Trip.getDao(getTopiaPersistenceContext()).forEquals(TripAware.PROPERTY_PROGRAM, program).stream();
|
| 123 | 124 |
}
|
| 124 |
- |
|
| 125 |
- protected <P extends DataEntity<?, ?>, E extends DataEntity<?, ?>> void saveEntity2(DataDtoEntityContext<?, ?, P, ?> parentSpi, DataDtoEntityContext<?, ?, E, ?> spi, P parenEntity, E entity) {
|
|
| 126 |
- parentSpi.update(getTopiaPersistenceContext(), parenEntity);
|
|
| 127 |
- spi.update(getTopiaPersistenceContext(), entity);
|
|
| 128 |
- Date lastUpdateDate = now();
|
|
| 129 |
- ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
|
|
| 130 |
- persistenceContext.flush();
|
|
| 131 |
- spi.updateLastUpdateDateField(persistenceContext, entity.getTopiaId(), lastUpdateDate);
|
|
| 132 |
- spi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 133 |
- parentSpi.updateLastUpdateDateField(persistenceContext, parenEntity.getTopiaId(), lastUpdateDate);
|
|
| 134 |
- parentSpi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 135 |
- }
|
|
| 136 | 125 |
}
|
| ... | ... | @@ -28,13 +28,13 @@ import fr.ird.observe.dto.data.ll.logbook.ActivityDto; |
| 28 | 28 |
import fr.ird.observe.dto.data.ll.logbook.ActivityReference;
|
| 29 | 29 |
import fr.ird.observe.entities.data.DataEntity;
|
| 30 | 30 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 31 |
+import fr.ird.observe.entities.data.ll.common.TripImpl;
|
|
| 31 | 32 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 32 | 33 |
import fr.ird.observe.entities.data.ll.logbook.ActivityTopiaDao;
|
| 33 | 34 |
import fr.ird.observe.entities.data.ll.logbook.Sample;
|
| 34 | 35 |
import fr.ird.observe.entities.data.ll.logbook.Set;
|
| 35 | 36 |
import fr.ird.observe.entities.referential.common.DataQuality;
|
| 36 | 37 |
import fr.ird.observe.services.local.service.data.OpenableDataServiceLocalSupport;
|
| 37 |
-import fr.ird.observe.services.local.service.data.ll.common.TripServiceLocalSupport;
|
|
| 38 | 38 |
import fr.ird.observe.services.service.data.ll.logbook.ActivityService;
|
| 39 | 39 |
import io.ultreia.java4all.util.Dates;
|
| 40 | 40 |
|
| ... | ... | @@ -70,15 +70,6 @@ class ActivityServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, |
| 70 | 70 |
preCreated.setDataQuality(defaultDataQuality);
|
| 71 | 71 |
}
|
| 72 | 72 |
|
| 73 |
-// @Override
|
|
| 74 |
-// protected SaveResultDto onSave(Trip parent, Activity entity, ActivityDto dto) {
|
|
| 75 |
-// if (dto.isNotPersisted()) {
|
|
| 76 |
-// parent.addActivityLogbook(entity);
|
|
| 77 |
-// }
|
|
| 78 |
-// parent.updateEndDate();
|
|
| 79 |
-// return saveEntity(entity);
|
|
| 80 |
-// }
|
|
| 81 |
- |
|
| 82 | 73 |
@SuppressWarnings("unchecked")
|
| 83 | 74 |
@Override
|
| 84 | 75 |
protected Class<? extends DataEntity<?, ?>>[] getEntityTypeToCreateOnReplicate() {
|
| ... | ... | @@ -87,7 +78,7 @@ class ActivityServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, |
| 87 | 78 |
|
| 88 | 79 |
@Override
|
| 89 | 80 |
protected void moveCallback(Trip oldParent, Trip newParent, List<Activity> moved) {
|
| 90 |
- TripServiceLocalSupport.copyTripLogbookMetaData(oldParent, newParent);
|
|
| 81 |
+ TripImpl.copyTripLogbookMetaData(oldParent, newParent);
|
|
| 91 | 82 |
}
|
| 92 | 83 |
|
| 93 | 84 |
@Override
|
| ... | ... | @@ -28,17 +28,14 @@ import fr.ird.observe.dto.ShortIdDto; |
| 28 | 28 |
import fr.ird.observe.dto.data.TripAware;
|
| 29 | 29 |
import fr.ird.observe.dto.data.ll.logbook.SampleDto;
|
| 30 | 30 |
import fr.ird.observe.dto.data.ll.logbook.SampleReference;
|
| 31 |
-import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
|
| 32 | 31 |
import fr.ird.observe.entities.ReplicateDataEngine;
|
| 33 |
-import fr.ird.observe.entities.data.DataEntity;
|
|
| 34 | 32 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 33 |
+import fr.ird.observe.entities.data.ll.common.TripImpl;
|
|
| 35 | 34 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 36 | 35 |
import fr.ird.observe.entities.data.ll.logbook.Sample;
|
| 37 | 36 |
import fr.ird.observe.entities.data.ll.logbook.SampleTopiaDao;
|
| 38 | 37 |
import fr.ird.observe.services.local.service.data.OpenableDataServiceLocalSupport;
|
| 39 |
-import fr.ird.observe.services.local.service.data.ll.common.TripServiceLocalSupport;
|
|
| 40 | 38 |
import fr.ird.observe.services.service.data.ll.logbook.SampleService;
|
| 41 |
-import fr.ird.observe.spi.context.DataDtoEntityContext;
|
|
| 42 | 39 |
|
| 43 | 40 |
import java.util.Calendar;
|
| 44 | 41 |
import java.util.Date;
|
| ... | ... | @@ -68,20 +65,6 @@ class SampleServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, Sa |
| 68 | 65 |
preCreated.setTimeStamp(timestamp);
|
| 69 | 66 |
}
|
| 70 | 67 |
|
| 71 |
-// @Override
|
|
| 72 |
-// protected SaveResultDto onSave(Trip parent, Sample entity, SampleDto dto) {
|
|
| 73 |
-// if (dto.isNotPersisted()) {
|
|
| 74 |
-// parent.addSample(entity);
|
|
| 75 |
-// }
|
|
| 76 |
-// parent.updateEndDate();
|
|
| 77 |
-// //FIXME Check this is ok to not do this
|
|
| 78 |
-// return newSaveHelper()
|
|
| 79 |
-// .update(spi, entity)
|
|
| 80 |
-// .updateLastUpdateDateField(parentSpi, parent)
|
|
| 81 |
-// .updateLastUpdateDateTable(spi)
|
|
| 82 |
-// .build(entity);
|
|
| 83 |
-// }
|
|
| 84 |
- |
|
| 85 | 68 |
@Override
|
| 86 | 69 |
public ImmutableSet<String> move(ShortIdDto oldParentId, ShortIdDto newParentId, ImmutableSet<String> ids) {
|
| 87 | 70 |
if (TripAware.class.isAssignableFrom(newParentId.getType())) {
|
| ... | ... | @@ -98,30 +81,18 @@ class SampleServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, Sa |
| 98 | 81 |
String id = ids.iterator().next();
|
| 99 | 82 |
Sample entity = loadEntity(id);
|
| 100 | 83 |
Trip newTrip = getParent(Trip.SPI, Trip.PROPERTY_ACTIVITY_LOGBOOK, newParent.getTopiaId());
|
| 101 |
- ReplicateDataEngine replicateEngine = serviceContext.getTopiaApplicationContext().newReplicateDataEngine(getTopiaPersistenceContext());
|
|
| 84 |
+ ReplicateDataEngine replicateEngine = newReplicateDataEngine();
|
|
| 102 | 85 |
Sample replicateData = replicateEngine.replicate(entity);
|
| 103 |
- |
|
| 104 | 86 |
oldParent.removeSample(entity);
|
| 105 | 87 |
replicateEngine.flush(Sample.class);
|
| 106 | 88 |
newParent.setSample(replicateData);
|
| 107 |
- boolean newTripUpdated = TripServiceLocalSupport.copyTripLogbookMetaData(oldParent, newTrip);
|
|
| 108 |
- Date lastUpdateDate = saveEntity2(Trip.SPI, Activity.SPI, oldParent, newParent);
|
|
| 109 |
- if (newTripUpdated) {
|
|
| 110 |
- parentSpi.updateLastUpdateDateField(getTopiaPersistenceContext(), newParent.getTopiaId(), lastUpdateDate);
|
|
| 111 |
- }
|
|
| 89 |
+ TripImpl.copyTripLogbookMetaData(oldParent, newTrip);
|
|
| 90 |
+ newSaveHelper()
|
|
| 91 |
+ .update(parentSpi, oldParent)
|
|
| 92 |
+ .update(Activity.SPI, newParent,(activity, date) -> activity.getSample().setLastUpdateDate(date))
|
|
| 93 |
+ .updateLastUpdateDateTable(spi)
|
|
| 94 |
+ .build();
|
|
| 112 | 95 |
return ImmutableSet.of(replicateData.getTopiaId());
|
| 113 | 96 |
}
|
| 114 | 97 |
|
| 115 |
- protected <P extends DataEntity<?, ?>, E extends DataEntity<?, ?>> Date saveEntity2(DataDtoEntityContext<?, ?, P, ?> parentSpi, DataDtoEntityContext<?, ?, E, ?> spi, P parenEntity, E entity) {
|
|
| 116 |
- parentSpi.update(getTopiaPersistenceContext(), parenEntity);
|
|
| 117 |
- spi.update(getTopiaPersistenceContext(), entity);
|
|
| 118 |
- Date lastUpdateDate = now();
|
|
| 119 |
- ObserveTopiaPersistenceContext persistenceContext = getTopiaPersistenceContext();
|
|
| 120 |
- persistenceContext.flush();
|
|
| 121 |
- spi.updateLastUpdateDateField(persistenceContext, entity.getTopiaId(), lastUpdateDate);
|
|
| 122 |
- spi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 123 |
- parentSpi.updateLastUpdateDateField(persistenceContext, parenEntity.getTopiaId(), lastUpdateDate);
|
|
| 124 |
- parentSpi.updateLastUpdateDateTable(persistenceContext, lastUpdateDate);
|
|
| 125 |
- return lastUpdateDate;
|
|
| 126 |
- }
|
|
| 127 | 98 |
}
|
| ... | ... | @@ -45,7 +45,7 @@ import java.util.Objects; |
| 45 | 45 |
/**
|
| 46 | 46 |
* @author Tony Chemit - dev@tchemit.fr
|
| 47 | 47 |
*/
|
| 48 |
-class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, SetDto, SetReference, Set, SetTopiaDao, SaveResultDto> implements SetService {
|
|
| 48 |
+class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, SetDto, SetReference, Set, SetTopiaDao> implements SetService {
|
|
| 49 | 49 |
|
| 50 | 50 |
public SetServiceLocalSupport() {
|
| 51 | 51 |
super(Activity.SPI, Set.SPI, Activity.PROPERTY_SET);
|
| ... | ... | @@ -83,14 +83,6 @@ class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, S |
| 83 | 83 |
preCreated.setTotalSectionsCount(1);
|
| 84 | 84 |
}
|
| 85 | 85 |
|
| 86 |
-// @Override
|
|
| 87 |
-// protected SaveResultDto onSave(Activity parent, Set entity, SetDto dto) {
|
|
| 88 |
-// if (dto.isNotPersisted()) {
|
|
| 89 |
-// parent.setSet(entity);
|
|
| 90 |
-// }
|
|
| 91 |
-// return saveEntity(entity);
|
|
| 92 |
-// }
|
|
| 93 |
- |
|
| 94 | 86 |
@Override
|
| 95 | 87 |
public SaveResultDto saveAndCopyProperties(String setToCopyId, SetDto dto) {
|
| 96 | 88 |
Activity parent = getParent(setToCopyId);
|
| ... | ... | @@ -27,6 +27,7 @@ import fr.ird.observe.dto.data.ll.observation.ActivityDto; |
| 27 | 27 |
import fr.ird.observe.dto.data.ll.observation.ActivityReference;
|
| 28 | 28 |
import fr.ird.observe.entities.data.DataEntity;
|
| 29 | 29 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 30 |
+import fr.ird.observe.entities.data.ll.common.TripImpl;
|
|
| 30 | 31 |
import fr.ird.observe.entities.data.ll.observation.Activity;
|
| 31 | 32 |
import fr.ird.observe.entities.data.ll.observation.ActivityTopiaDao;
|
| 32 | 33 |
import fr.ird.observe.entities.data.ll.observation.Basket;
|
| ... | ... | @@ -34,7 +35,6 @@ import fr.ird.observe.entities.data.ll.observation.Branchline; |
| 34 | 35 |
import fr.ird.observe.entities.data.ll.observation.Section;
|
| 35 | 36 |
import fr.ird.observe.entities.data.ll.observation.Set;
|
| 36 | 37 |
import fr.ird.observe.services.local.service.data.OpenableDataServiceLocalSupport;
|
| 37 |
-import fr.ird.observe.services.local.service.data.ll.common.TripServiceLocalSupport;
|
|
| 38 | 38 |
import fr.ird.observe.services.service.data.ll.observation.ActivityService;
|
| 39 | 39 |
|
| 40 | 40 |
import java.util.Calendar;
|
| ... | ... | @@ -67,30 +67,12 @@ class ActivityServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, |
| 67 | 67 |
preCreated.setTimeStamp(timestamp);
|
| 68 | 68 |
}
|
| 69 | 69 |
|
| 70 |
-// @Override
|
|
| 71 |
-// protected SaveResultDto onSave(Trip parent, Activity entity, ActivityDto dto) {
|
|
| 72 |
-// if (dto.isNotPersisted()) {
|
|
| 73 |
-// parent.addActivityObs(entity);
|
|
| 74 |
-// }
|
|
| 75 |
-// parent.updateEndDate();
|
|
| 76 |
-// return saveEntity(entity);
|
|
| 77 |
-// }
|
|
| 78 |
- |
|
| 70 |
+ @SuppressWarnings("unchecked")
|
|
| 79 | 71 |
@Override
|
| 80 | 72 |
protected Class<? extends DataEntity<?, ?>>[] getEntityTypeToCreateOnReplicate() {
|
| 81 | 73 |
return new Class[]{Set.class, Section.class, Basket.class, Branchline.class};
|
| 82 | 74 |
}
|
| 83 | 75 |
|
| 84 |
- @Override
|
|
| 85 |
- protected void moveCallback(Trip oldParent, Trip newParent, List<Activity> moved) {
|
|
| 86 |
- TripServiceLocalSupport.copyTripObservationMetaData(Objects.requireNonNull(oldParent), newParent);
|
|
| 87 |
-// for (fr.ird.observe.entities.data.ll.logbook.Activity activity : oldParent.getActivityLogbook()) {
|
|
| 88 |
-// if (activity.getRelatedObservedActivity() != null && moved.contains(activity.getRelatedObservedActivity())) {
|
|
| 89 |
-// activity.setRelatedObservedActivity(null);
|
|
| 90 |
-// }
|
|
| 91 |
-// }
|
|
| 92 |
- }
|
|
| 93 |
- |
|
| 94 | 76 |
@Override
|
| 95 | 77 |
protected void moveCallback(Trip oldParent, Trip newParent, Activity moved) {
|
| 96 | 78 |
for (fr.ird.observe.entities.data.ll.logbook.Activity activity : oldParent.getActivityLogbook()) {
|
| ... | ... | @@ -99,4 +81,9 @@ class ActivityServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, |
| 99 | 81 |
}
|
| 100 | 82 |
}
|
| 101 | 83 |
}
|
| 84 |
+ |
|
| 85 |
+ @Override
|
|
| 86 |
+ protected void moveCallback(Trip oldParent, Trip newParent, List<Activity> moved) {
|
|
| 87 |
+ TripImpl.copyTripObservationMetaData(Objects.requireNonNull(oldParent), newParent);
|
|
| 88 |
+ }
|
|
| 102 | 89 |
}
|
| ... | ... | @@ -25,6 +25,7 @@ package fr.ird.observe.services.local.service.data.ll.observation; |
| 25 | 25 |
import fr.ird.observe.dto.data.ll.observation.BranchlineDto;
|
| 26 | 26 |
import fr.ird.observe.dto.form.Form;
|
| 27 | 27 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 28 |
+import fr.ird.observe.entities.Entity;
|
|
| 28 | 29 |
import fr.ird.observe.entities.data.ll.observation.Basket;
|
| 29 | 30 |
import fr.ird.observe.entities.data.ll.observation.Branchline;
|
| 30 | 31 |
import fr.ird.observe.entities.data.ll.observation.Section;
|
| ... | ... | @@ -50,11 +51,9 @@ class BranchlineServiceLocalSupport extends ObserveServiceLocal implements Branc |
| 50 | 51 |
checkLastUpdateDate(entity, dto);
|
| 51 | 52 |
entity.fromDto(getReferentialLocale(), dto);
|
| 52 | 53 |
return newSaveHelper()
|
| 53 |
- .update(Branchline.SPI, entity)
|
|
| 54 |
+ .update(Branchline.SPI, entity, Entity::setLastUpdateDate, false, true)
|
|
| 54 | 55 |
.updateLastUpdateDateField(Set.SPI, parent)
|
| 55 |
- .updateLastUpdateDateTable(Branchline.SPI)
|
|
| 56 | 56 |
.build(entity);
|
| 57 |
-// return saveEntity(Set.SPI, Branchline.SPI, parent, entity);
|
|
| 58 | 57 |
}
|
| 59 | 58 |
|
| 60 | 59 |
protected Set getParent(BranchlineDto dto) {
|
| ... | ... | @@ -27,7 +27,6 @@ import fr.ird.observe.dto.data.ll.observation.SetDto; |
| 27 | 27 |
import fr.ird.observe.dto.data.ll.observation.SetReference;
|
| 28 | 28 |
import fr.ird.observe.dto.data.ll.observation.SetStubDto;
|
| 29 | 29 |
import fr.ird.observe.dto.form.Form;
|
| 30 |
-import fr.ird.observe.dto.result.SaveResultDto;
|
|
| 31 | 30 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 32 | 31 |
import fr.ird.observe.entities.data.ll.observation.Activity;
|
| 33 | 32 |
import fr.ird.observe.entities.data.ll.observation.Set;
|
| ... | ... | @@ -43,7 +42,7 @@ import java.util.Objects; |
| 43 | 42 |
/**
|
| 44 | 43 |
* @author Tony Chemit - dev@tchemit.fr
|
| 45 | 44 |
*/
|
| 46 |
-class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, SetDto, SetReference, Set, SetTopiaDao, SaveResultDto> implements SetService {
|
|
| 45 |
+class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, SetDto, SetReference, Set, SetTopiaDao> implements SetService {
|
|
| 47 | 46 |
|
| 48 | 47 |
public SetServiceLocalSupport() {
|
| 49 | 48 |
super(Activity.SPI, Set.SPI, Activity.PROPERTY_SET);
|
| ... | ... | @@ -78,14 +77,6 @@ class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, S |
| 78 | 77 |
preCreated.setSettingStartLongitude(parent.getLongitude());
|
| 79 | 78 |
}
|
| 80 | 79 |
|
| 81 |
-// @Override
|
|
| 82 |
-// protected SaveResultDto onSave(Activity parent, Set entity, SetDto dto) {
|
|
| 83 |
-// if (dto.isNotPersisted()) {
|
|
| 84 |
-// parent.setSet(entity);
|
|
| 85 |
-// }
|
|
| 86 |
-// return saveEntity(entity);
|
|
| 87 |
-// }
|
|
| 88 |
- |
|
| 89 | 80 |
private java.util.Set<SetStubDto> getBrothers(Activity parent) {
|
| 90 | 81 |
java.util.Set<SetStubDto> result = new HashSet<>();
|
| 91 | 82 |
Trip trip = getParent(Trip.SPI, Trip.PROPERTY_ACTIVITY_OBS, parent.getTopiaId());
|
| ... | ... | @@ -67,14 +67,6 @@ class ActivityServiceLocalSupport extends OpenableDataServiceLocalSupport<Route, |
| 67 | 67 |
preCreated.setCurrentFpaZone(currentFpaZone);
|
| 68 | 68 |
}
|
| 69 | 69 |
|
| 70 |
-// @Override
|
|
| 71 |
-// protected SaveResultDto onSave(Route parent, Activity entity, ActivityDto dto) {
|
|
| 72 |
-// if (dto.isNotPersisted()) {
|
|
| 73 |
-// parent.addActivity(entity);
|
|
| 74 |
-// }
|
|
| 75 |
-// return saveEntity(spi, entity);
|
|
| 76 |
-// }
|
|
| 77 |
- |
|
| 78 | 70 |
@SuppressWarnings("unchecked")
|
| 79 | 71 |
@Override
|
| 80 | 72 |
protected Class<? extends DataEntity<?, ?>>[] getEntityTypeToCreateOnReplicate() {
|
| ... | ... | @@ -71,7 +71,7 @@ import java.util.stream.Collectors; |
| 71 | 71 |
/**
|
| 72 | 72 |
* @author Tony Chemit - dev@tchemit.fr
|
| 73 | 73 |
*/
|
| 74 |
-class FloatingObjectServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, FloatingObjectDto, FloatingObjectReference, FloatingObject, FloatingObjectTopiaDao, SaveResultDto> implements FloatingObjectService {
|
|
| 74 |
+class FloatingObjectServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, FloatingObjectDto, FloatingObjectReference, FloatingObject, FloatingObjectTopiaDao> implements FloatingObjectService {
|
|
| 75 | 75 |
|
| 76 | 76 |
private static final Logger log = LogManager.getLogger(FloatingObjectServiceLocalSupport.class);
|
| 77 | 77 |
|
| ... | ... | @@ -93,8 +93,6 @@ class RouteServiceLocalSupport extends OpenableDataServiceLocalSupport<Trip, Rou |
| 93 | 93 |
}
|
| 94 | 94 |
}
|
| 95 | 95 |
return super.onSave(parent, entity, dto);
|
| 96 |
-// parent.updateEndDate();
|
|
| 97 |
-// return saveEntity(spi, entity);
|
|
| 98 | 96 |
}
|
| 99 | 97 |
|
| 100 | 98 |
@SuppressWarnings("unchecked")
|
| ... | ... | @@ -77,9 +77,7 @@ public abstract class SampleDataServiceLocalSupport<C extends ContainerChildDto, |
| 77 | 77 |
return newSaveHelper()
|
| 78 | 78 |
.update(spi, entity)
|
| 79 | 79 |
.updateLastUpdateDateField(Set.SPI, parent)
|
| 80 |
- .updateLastUpdateDateTable(spi)
|
|
| 81 | 80 |
.build(entity);
|
| 82 |
-// return saveEntity(Set.SPI, spi, parent, entity);
|
|
| 83 | 81 |
}
|
| 84 | 82 |
|
| 85 | 83 |
public final E newEntity() {
|
| ... | ... | @@ -25,7 +25,6 @@ package fr.ird.observe.services.local.service.data.ps.observation; |
| 25 | 25 |
import fr.ird.observe.dto.data.ps.observation.SetDto;
|
| 26 | 26 |
import fr.ird.observe.dto.data.ps.observation.SetReference;
|
| 27 | 27 |
import fr.ird.observe.dto.form.Form;
|
| 28 |
-import fr.ird.observe.dto.result.SaveResultDto;
|
|
| 29 | 28 |
import fr.ird.observe.entities.data.ps.observation.Activity;
|
| 30 | 29 |
import fr.ird.observe.entities.data.ps.observation.Route;
|
| 31 | 30 |
import fr.ird.observe.entities.data.ps.observation.Set;
|
| ... | ... | @@ -40,7 +39,7 @@ import java.util.Date; |
| 40 | 39 |
/**
|
| 41 | 40 |
* @author Tony Chemit - dev@tchemit.fr
|
| 42 | 41 |
*/
|
| 43 |
-class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, SetDto, SetReference, Set, SetTopiaDao, SaveResultDto> implements SetService {
|
|
| 42 |
+class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, SetDto, SetReference, Set, SetTopiaDao> implements SetService {
|
|
| 44 | 43 |
|
| 45 | 44 |
public SetServiceLocalSupport() {
|
| 46 | 45 |
super(Activity.SPI, Set.SPI, Activity.PROPERTY_SET);
|
| ... | ... | @@ -79,11 +78,4 @@ class SetServiceLocalSupport extends EditableDataServiceLocalSupport<Activity, S |
| 79 | 78 |
preCreated.setSchoolType(schoolType);
|
| 80 | 79 |
}
|
| 81 | 80 |
|
| 82 |
-// @Override
|
|
| 83 |
-// protected SaveResultDto onSave(Activity parent, Set entity, SetDto dto) {
|
|
| 84 |
-// if (dto.isNotPersisted()) {
|
|
| 85 |
-// parent.setSet(entity);
|
|
| 86 |
-// }
|
|
| 87 |
-// return saveEntity(entity);
|
|
| 88 |
-// }
|
|
| 89 | 81 |
}
|