Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
9e4cd83f
by Tony Chemit at 2020-08-14T15:07:17+02:00
-
1c2d492a
by Tony Chemit at 2020-08-14T15:36:36+02:00
18 changed files:
- common-persistence/pom.xml
- common-persistence/src/main/java/fr/ird/observe/entities/Entity.java
- common-persistence/src/main/java/fr/ird/observe/entities/ObserveTopiaPersistenceContextSupport.java
- + persistence/src/main/java/fr/ird/observe/entities/EntityImpl.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/landing/LandingServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/ActivitySampleServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/ActivityServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/SetServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/TripSampleServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/ActivityServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ll/observation/SetServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/ActivityServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/FloatingObjectServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/RouteServiceLocal.java
- services-local/src/main/java/fr/ird/observe/services/local/service/data/ps/observation/SetServiceLocal.java
- templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityTransformer.java
Changes:
| ... | ... | @@ -70,6 +70,10 @@ |
| 70 | 70 |
<groupId>io.ultreia.java4all</groupId>
|
| 71 | 71 |
<artifactId>application-context</artifactId>
|
| 72 | 72 |
</dependency>
|
| 73 |
+ <dependency>
|
|
| 74 |
+ <groupId>io.ultreia.java4all</groupId>
|
|
| 75 |
+ <artifactId>java-bean</artifactId>
|
|
| 76 |
+ </dependency>
|
|
| 73 | 77 |
<dependency>
|
| 74 | 78 |
<groupId>io.ultreia.java4all.i18n</groupId>
|
| 75 | 79 |
<artifactId>i18n-runtime</artifactId>
|
| ... | ... | @@ -23,12 +23,15 @@ package fr.ird.observe.entities; |
| 23 | 23 |
*/
|
| 24 | 24 |
|
| 25 | 25 |
import fr.ird.observe.dto.reference.DtoReferenceAware;
|
| 26 |
+import io.ultreia.java4all.bean.JavaBean;
|
|
| 27 |
+import io.ultreia.java4all.bean.definition.JavaBeanDefinition;
|
|
| 28 |
+import io.ultreia.java4all.bean.definition.JavaBeanDefinitionStore;
|
|
| 26 | 29 |
import org.nuiton.topia.persistence.TopiaEntity;
|
| 27 | 30 |
import org.nuiton.topia.persistence.event.ListenableTopiaEntity;
|
| 28 | 31 |
|
| 29 | 32 |
import java.util.Date;
|
| 30 | 33 |
|
| 31 |
-public interface Entity extends TopiaEntity, ListenableTopiaEntity, DtoReferenceAware {
|
|
| 34 |
+public interface Entity extends TopiaEntity, ListenableTopiaEntity, DtoReferenceAware, JavaBean {
|
|
| 32 | 35 |
|
| 33 | 36 |
String PROPERTY_LAST_UPDATE_DATE = "lastUpdateDate";
|
| 34 | 37 |
|
| ... | ... | @@ -211,7 +211,11 @@ public abstract class ObserveTopiaPersistenceContextSupport extends AbstractTopi |
| 211 | 211 |
Class<? extends DataEntity> associationType = getTopiaIdFactory().getClassName(associationId);
|
| 212 | 212 |
throw new DataAssociationParentNotFoundException(locale, DbModelHelper.fromDataEntity(associationType).toDtoType(), associationName, associationId);
|
| 213 | 213 |
}
|
| 214 |
- return getDao(associationContainerType).forTopiaIdEquals(Objects.requireNonNull(parentId)).findUnique();
|
|
| 214 |
+ E result = getDao(associationContainerType).forTopiaIdEquals(Objects.requireNonNull(parentId)).findUniqueOrNull();
|
|
| 215 |
+ if (result == null) {
|
|
| 216 |
+ throw new DataNotFoundException(locale, DbModelHelper.fromEntity(associationContainerType).toDtoType(), parentId);
|
|
| 217 |
+ }
|
|
| 218 |
+ return result;
|
|
| 215 | 219 |
}
|
| 216 | 220 |
|
| 217 | 221 |
protected class CountTableSqlWork extends TopiaSqlQuery<Long> {
|
| 1 |
+package fr.ird.observe.entities;
|
|
| 2 |
+ |
|
| 3 |
+/*-
|
|
| 4 |
+ * #%L
|
|
| 5 |
+ * ObServe :: Persistence
|
|
| 6 |
+ * %%
|
|
| 7 |
+ * Copyright (C) 2008 - 2020 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 |
+ |
|
| 26 |
+import io.ultreia.java4all.bean.definition.JavaBeanDefinition;
|
|
| 27 |
+import io.ultreia.java4all.bean.definition.JavaBeanDefinitionStore;
|
|
| 28 |
+import org.apache.logging.log4j.LogManager;
|
|
| 29 |
+import org.apache.logging.log4j.Logger;
|
|
| 30 |
+ |
|
| 31 |
+public abstract class EntityImpl extends EntityAbstract {
|
|
| 32 |
+ |
|
| 33 |
+ private static final long serialVersionUID = 1L;
|
|
| 34 |
+ private static final Logger log = LogManager.getLogger(EntityImpl.class);
|
|
| 35 |
+ private JavaBeanDefinition javaBeanDefinition;
|
|
| 36 |
+ |
|
| 37 |
+ @Override
|
|
| 38 |
+ public JavaBeanDefinition javaBeanDefinition() {
|
|
| 39 |
+ if (javaBeanDefinition == null) {
|
|
| 40 |
+ Class<? extends Entity> contractClass = ObserveEntityEnum.getContractClass(getClass());
|
|
| 41 |
+ javaBeanDefinition = JavaBeanDefinitionStore.getDefinition(contractClass).orElseThrow(IllegalStateException::new);
|
|
| 42 |
+ log.info(String.format("Loaded javaBean definition for: %s → %s", contractClass.getName(), javaBeanDefinition));
|
|
| 43 |
+ }
|
|
| 44 |
+ return javaBeanDefinition;
|
|
| 45 |
+ }
|
|
| 46 |
+}
|
| ... | ... | @@ -106,6 +106,10 @@ |
| 106 | 106 |
<groupId>io.ultreia.java4all</groupId>
|
| 107 | 107 |
<artifactId>class-mapping</artifactId>
|
| 108 | 108 |
</dependency>
|
| 109 |
+ <dependency>
|
|
| 110 |
+ <groupId>io.ultreia.java4all</groupId>
|
|
| 111 |
+ <artifactId>java-bean</artifactId>
|
|
| 112 |
+ </dependency>
|
|
| 109 | 113 |
|
| 110 | 114 |
<dependency>
|
| 111 | 115 |
<groupId>org.apache.logging.log4j</groupId>
|
| ... | ... | @@ -218,6 +218,42 @@ public abstract class ObserveServiceLocal implements ObserveService { |
| 218 | 218 |
protected List<Species> filterByOcean(Collection<Species> speciesCollection, Ocean ocean) {
|
| 219 | 219 |
return speciesCollection.stream().filter(s -> s.containsOcean(ocean)).collect(Collectors.toList());
|
| 220 | 220 |
}
|
| 221 |
+ |
|
| 222 |
+ protected void deleteSingleAssociation(String idToDelete,
|
|
| 223 |
+ DataDtoEntityContext<?, ?, ?, ?> spi,
|
|
| 224 |
+ DataDtoEntityContext<?, ?, ?, ?> parentSpi,
|
|
| 225 |
+ String associationName) {
|
|
| 226 |
+ |
|
| 227 |
+ DataEntity<?, ?> entityToDelete = spi.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), idToDelete);
|
|
| 228 |
+ DataEntity<?, ?> parentEntity = getTopiaPersistenceContext().getSingleAssociationParent(getApplicationLocale(), parentSpi.toEntityType(), associationName, idToDelete);
|
|
| 229 |
+ Object realChild = parentEntity.get(associationName);
|
|
| 230 |
+ if (!Objects.equals(entityToDelete, realChild)) {
|
|
| 231 |
+ throw new DataNotFoundException(getApplicationLocale(), spi.toDtoType(), idToDelete);
|
|
| 232 |
+ }
|
|
| 233 |
+ parentEntity.set(associationName, null);
|
|
| 234 |
+ deleteEntity(parentSpi, parentEntity, entityToDelete);
|
|
| 235 |
+ }
|
|
| 236 |
+ |
|
| 237 |
+ protected <E extends DataEntity<?, ?>> E deleteMultipleAssociation(DataDtoEntityContext<?, ?, E, ?> parentSpi, String associationName, DataDtoEntityContext<?, ?, ?, ?> spi, String idToDelete) {
|
|
| 238 |
+ |
|
| 239 |
+ DataEntity<?, ?> entityToDelete = spi.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), idToDelete);
|
|
| 240 |
+ E parentEntity = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), parentSpi.toEntityType(), associationName, idToDelete);
|
|
| 241 |
+ Collection<?> realChild = parentEntity.get(associationName);
|
|
| 242 |
+ if (!realChild.contains(entityToDelete)) {
|
|
| 243 |
+ throw new DataNotFoundException(getApplicationLocale(), spi.toDtoType(), idToDelete);
|
|
| 244 |
+ }
|
|
| 245 |
+ realChild.remove(entityToDelete);
|
|
| 246 |
+ deleteEntity(parentSpi, parentEntity, entityToDelete);
|
|
| 247 |
+ return parentEntity;
|
|
| 248 |
+ }
|
|
| 249 |
+ |
|
| 250 |
+ private <C extends Entity, E extends Entity> void deleteEntity(DataDtoEntityContext<?, ?, ?, ?> spi, E parentEntity, C deletedEntity) {
|
|
| 251 |
+ Date lastUpdateDate = now();
|
|
| 252 |
+ getTopiaPersistenceContext().updateLastUpdateDate(parentEntity, lastUpdateDate);
|
|
| 253 |
+ spi.updateLastUpdates(getTopiaPersistenceContext(), parentEntity.getTopiaId(), lastUpdateDate);
|
|
| 254 |
+ updateLastUpdateDate(spi.toEntityType());
|
|
| 255 |
+ updateLastUpdateDate(getTopiaPersistenceContext().getType(deletedEntity));
|
|
| 256 |
+ }
|
|
| 221 | 257 |
}
|
| 222 | 258 |
|
| 223 | 259 |
|
| ... | ... | @@ -29,7 +29,6 @@ import fr.ird.observe.dto.form.Form; |
| 29 | 29 |
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
|
| 30 | 30 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 31 | 31 |
import fr.ird.observe.dto.result.TripChildSaveResultDto;
|
| 32 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 33 | 32 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 34 | 33 |
import fr.ird.observe.entities.data.ll.common.TripTopiaDao;
|
| 35 | 34 |
import fr.ird.observe.entities.data.ll.landing.Landing;
|
| ... | ... | @@ -93,13 +92,7 @@ public class LandingServiceLocal extends ObserveServiceLocal implements LandingS |
| 93 | 92 |
|
| 94 | 93 |
@Override
|
| 95 | 94 |
public void delete(String landingLogbookId) {
|
| 96 |
- Trip trip = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Trip.class, Trip.PROPERTY_LANDING, landingLogbookId);
|
|
| 97 |
- Landing landing = Landing.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), landingLogbookId);
|
|
| 98 |
- if (!trip.containsLanding(landing)) {
|
|
| 99 |
- throw new DataNotFoundException(getApplicationLocale(), LandingDto.class, landingLogbookId);
|
|
| 100 |
- }
|
|
| 101 |
- trip.removeLanding(landing);
|
|
| 102 |
- saveEntity(Trip.SPI, trip);
|
|
| 95 |
+ deleteMultipleAssociation(Trip.SPI, Trip.PROPERTY_LANDING, Landing.SPI, landingLogbookId);
|
|
| 103 | 96 |
}
|
| 104 | 97 |
|
| 105 | 98 |
@Override
|
| ... | ... | @@ -69,10 +69,7 @@ public class ActivitySampleServiceLocal extends ObserveServiceLocal implements A |
| 69 | 69 |
|
| 70 | 70 |
@Override
|
| 71 | 71 |
public void delete(String sampleLogbookId) {
|
| 72 |
- Activity activity = getActivityLonglineLogbook(sampleLogbookId);
|
|
| 73 |
- Sample.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), sampleLogbookId);
|
|
| 74 |
- activity.setSample(null);
|
|
| 75 |
- saveEntity(Activity.SPI, activity);
|
|
| 72 |
+ deleteSingleAssociation(sampleLogbookId, Sample.SPI, Activity.SPI, Activity.PROPERTY_SAMPLE);
|
|
| 76 | 73 |
}
|
| 77 | 74 |
|
| 78 | 75 |
@Override
|
| ... | ... | @@ -31,7 +31,6 @@ import fr.ird.observe.dto.form.Form; |
| 31 | 31 |
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
|
| 32 | 32 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 33 | 33 |
import fr.ird.observe.dto.result.TripChildSaveResultDto;
|
| 34 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 35 | 34 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 36 | 35 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 37 | 36 |
import fr.ird.observe.entities.data.ll.logbook.ActivityTopiaDao;
|
| ... | ... | @@ -120,13 +119,7 @@ public class ActivityServiceLocal extends ObserveServiceLocal implements Activit |
| 120 | 119 |
|
| 121 | 120 |
@Override
|
| 122 | 121 |
public boolean delete(String activityLonglineId) {
|
| 123 |
- Trip trip = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Trip.class, Trip.PROPERTY_ACTIVITY_LOGBOOK, activityLonglineId);
|
|
| 124 |
- Activity activityLongline = Activity.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), activityLonglineId);
|
|
| 125 |
- if (!trip.containsActivityLogbook(activityLongline)) {
|
|
| 126 |
- throw new DataNotFoundException(getApplicationLocale(), ActivityDto.class, activityLonglineId);
|
|
| 127 |
- }
|
|
| 128 |
- trip.removeActivityLogbook(activityLongline);
|
|
| 129 |
- saveEntity(Trip.SPI, trip);
|
|
| 122 |
+ Trip trip = deleteMultipleAssociation(Trip.SPI, Trip.PROPERTY_ACTIVITY_LOGBOOK, Activity.SPI, activityLonglineId);
|
|
| 130 | 123 |
return Trip.getDao(getTopiaPersistenceContext()).updateEndDate(trip);
|
| 131 | 124 |
}
|
| 132 | 125 |
|
| ... | ... | @@ -29,7 +29,6 @@ import fr.ird.observe.dto.data.ll.logbook.SetReference; |
| 29 | 29 |
import fr.ird.observe.dto.data.ll.logbook.SetStubDto;
|
| 30 | 30 |
import fr.ird.observe.dto.form.Form;
|
| 31 | 31 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 32 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 33 | 32 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 34 | 33 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 35 | 34 |
import fr.ird.observe.entities.data.ll.logbook.Set;
|
| ... | ... | @@ -157,13 +156,14 @@ public class SetServiceLocal extends ObserveServiceLocal implements SetService { |
| 157 | 156 |
|
| 158 | 157 |
@Override
|
| 159 | 158 |
public void delete(String setLonglineId) {
|
| 160 |
- Activity activityLongline = getActivityLonglineLogbook(setLonglineId);
|
|
| 161 |
- Set setLongline = Set.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), setLonglineId);
|
|
| 162 |
- if (!activityLongline.getSet().equals(setLongline)) {
|
|
| 163 |
- throw new DataNotFoundException(getApplicationLocale(), SetDto.class, setLonglineId);
|
|
| 164 |
- }
|
|
| 165 |
- activityLongline.setSet(null);
|
|
| 166 |
- saveEntity(Activity.SPI, activityLongline);
|
|
| 159 |
+ deleteSingleAssociation(setLonglineId, Set.SPI, Activity.SPI, Activity.PROPERTY_SET);
|
|
| 160 |
+// Activity activityLongline = getActivityLonglineLogbook(setLonglineId);
|
|
| 161 |
+// Set setLongline = Set.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), setLonglineId);
|
|
| 162 |
+// if (!activityLongline.getSet().equals(setLongline)) {
|
|
| 163 |
+// throw new DataNotFoundException(getApplicationLocale(), SetDto.class, setLonglineId);
|
|
| 164 |
+// }
|
|
| 165 |
+// activityLongline.setSet(null);
|
|
| 166 |
+// saveEntity(Activity.SPI, activityLongline);
|
|
| 167 | 167 |
}
|
| 168 | 168 |
|
| 169 | 169 |
private Activity getActivityLonglineLogbook(String setToCopyId) {
|
| ... | ... | @@ -30,7 +30,6 @@ import fr.ird.observe.dto.form.Form; |
| 30 | 30 |
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
|
| 31 | 31 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 32 | 32 |
import fr.ird.observe.dto.result.TripChildSaveResultDto;
|
| 33 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 34 | 33 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 35 | 34 |
import fr.ird.observe.entities.data.ll.common.TripTopiaDao;
|
| 36 | 35 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| ... | ... | @@ -110,13 +109,7 @@ public class TripSampleServiceLocal extends ObserveServiceLocal implements TripS |
| 110 | 109 |
|
| 111 | 110 |
@Override
|
| 112 | 111 |
public void delete(String tripLonglineId, String sampleLogbookId) {
|
| 113 |
- Trip trip = Trip.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), tripLonglineId);
|
|
| 114 |
- Sample sample = Sample.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), sampleLogbookId);
|
|
| 115 |
- if (!trip.containsSample(sample)) {
|
|
| 116 |
- throw new DataNotFoundException(getApplicationLocale(), SampleDto.class, sampleLogbookId);
|
|
| 117 |
- }
|
|
| 118 |
- trip.removeSample(sample);
|
|
| 119 |
- saveEntity(Trip.SPI, trip);
|
|
| 112 |
+ deleteMultipleAssociation(Trip.SPI, Trip.PROPERTY_SAMPLE, Sample.SPI, tripLonglineId);
|
|
| 120 | 113 |
}
|
| 121 | 114 |
|
| 122 | 115 |
@Override
|
| ... | ... | @@ -30,7 +30,6 @@ import fr.ird.observe.dto.form.Form; |
| 30 | 30 |
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
|
| 31 | 31 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 32 | 32 |
import fr.ird.observe.dto.result.TripChildSaveResultDto;
|
| 33 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 34 | 33 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 35 | 34 |
import fr.ird.observe.entities.data.ll.observation.Activity;
|
| 36 | 35 |
import fr.ird.observe.entities.data.ll.observation.ActivityTopiaDao;
|
| ... | ... | @@ -112,13 +111,7 @@ public class ActivityServiceLocal extends ObserveServiceLocal implements Activit |
| 112 | 111 |
|
| 113 | 112 |
@Override
|
| 114 | 113 |
public boolean delete(String activityLonglineId) {
|
| 115 |
- Trip trip = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Trip.class, Trip.PROPERTY_ACTIVITY_OBS, activityLonglineId);
|
|
| 116 |
- Activity activityLongline = Activity.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), activityLonglineId);
|
|
| 117 |
- if (!trip.containsActivityObs(activityLongline)) {
|
|
| 118 |
- throw new DataNotFoundException(getApplicationLocale(), ActivityDto.class, activityLonglineId);
|
|
| 119 |
- }
|
|
| 120 |
- trip.removeActivityObs(activityLongline);
|
|
| 121 |
- saveEntity(Trip.SPI, trip);
|
|
| 114 |
+ Trip trip = deleteMultipleAssociation(Trip.SPI, Trip.PROPERTY_ACTIVITY_OBS, Activity.SPI, activityLonglineId);
|
|
| 122 | 115 |
return Trip.getDao(getTopiaPersistenceContext()).updateEndDate(trip);
|
| 123 | 116 |
}
|
| 124 | 117 |
|
| ... | ... | @@ -28,7 +28,6 @@ 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 | 30 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 31 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 32 | 31 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 33 | 32 |
import fr.ird.observe.entities.data.ll.observation.Activity;
|
| 34 | 33 |
import fr.ird.observe.entities.data.ll.observation.Set;
|
| ... | ... | @@ -104,13 +103,7 @@ public class SetServiceLocal extends ObserveServiceLocal implements SetService { |
| 104 | 103 |
|
| 105 | 104 |
@Override
|
| 106 | 105 |
public void delete(String setLonglineId) {
|
| 107 |
- Activity activityLongline = getTopiaPersistenceContext().getSingleAssociationParent(getApplicationLocale(), Activity.class, Activity.PROPERTY_SET, setLonglineId);
|
|
| 108 |
- Set setLongline = Set.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), setLonglineId);
|
|
| 109 |
- if (!activityLongline.getSet().equals(setLongline)) {
|
|
| 110 |
- throw new DataNotFoundException(getApplicationLocale(), SetDto.class, setLonglineId);
|
|
| 111 |
- }
|
|
| 112 |
- activityLongline.setSet(null);
|
|
| 113 |
- saveEntity(Activity.SPI, activityLongline);
|
|
| 106 |
+ deleteSingleAssociation(setLonglineId, Set.SPI, Activity.SPI, Activity.PROPERTY_SET);
|
|
| 114 | 107 |
}
|
| 115 | 108 |
|
| 116 | 109 |
private java.util.Set<SetStubDto> getOtherSetLonglineDtoSet(Activity currentActivityLongline, Set setLongline) {
|
| ... | ... | @@ -30,7 +30,6 @@ import fr.ird.observe.dto.form.Form; |
| 30 | 30 |
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
|
| 31 | 31 |
import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 32 | 32 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 33 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 34 | 33 |
import fr.ird.observe.entities.data.ps.observation.Activity;
|
| 35 | 34 |
import fr.ird.observe.entities.data.ps.observation.Route;
|
| 36 | 35 |
import fr.ird.observe.entities.referential.common.FpaZone;
|
| ... | ... | @@ -118,13 +117,7 @@ public class ActivityServiceLocal extends ObserveServiceLocal implements Activit |
| 118 | 117 |
|
| 119 | 118 |
@Override
|
| 120 | 119 |
public void delete(String activitySeineId) {
|
| 121 |
- Route route = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Route.class, Route.PROPERTY_ACTIVITY, activitySeineId);
|
|
| 122 |
- Activity activity = Activity.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), activitySeineId);
|
|
| 123 |
- if (!route.containsActivity(activity)) {
|
|
| 124 |
- throw new DataNotFoundException(getApplicationLocale(), ActivityDto.class, activitySeineId);
|
|
| 125 |
- }
|
|
| 126 |
- route.removeActivity(activity);
|
|
| 127 |
- saveEntity(Route.SPI, route);
|
|
| 120 |
+ deleteMultipleAssociation(Route.SPI, Route.PROPERTY_ACTIVITY, Activity.SPI, activitySeineId);
|
|
| 128 | 121 |
}
|
| 129 | 122 |
|
| 130 | 123 |
@Override
|
| ... | ... | @@ -36,7 +36,6 @@ import fr.ird.observe.dto.reference.DataDtoReferenceSet; |
| 36 | 36 |
import fr.ird.observe.dto.referential.ReferentialLocale;
|
| 37 | 37 |
import fr.ird.observe.dto.referential.ps.observation.ObjectMaterialDto;
|
| 38 | 38 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 39 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 40 | 39 |
import fr.ird.observe.entities.ObserveTopiaPersistenceContext;
|
| 41 | 40 |
import fr.ird.observe.entities.data.ps.observation.Activity;
|
| 42 | 41 |
import fr.ird.observe.entities.data.ps.observation.FloatingObject;
|
| ... | ... | @@ -201,13 +200,7 @@ public class FloatingObjectServiceLocal extends ObserveServiceLocal implements F |
| 201 | 200 |
|
| 202 | 201 |
@Override
|
| 203 | 202 |
public void delete(String floatingObjectId) {
|
| 204 |
- Activity activity = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Activity.class, Activity.PROPERTY_FLOATING_OBJECT, floatingObjectId);
|
|
| 205 |
- FloatingObject floatingObject = FloatingObject.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), floatingObjectId);
|
|
| 206 |
- if (!activity.containsFloatingObject(floatingObject)) {
|
|
| 207 |
- throw new DataNotFoundException(getApplicationLocale(), FloatingObjectDto.class, floatingObjectId);
|
|
| 208 |
- }
|
|
| 209 |
- activity.removeFloatingObject(floatingObject);
|
|
| 210 |
- saveEntity(Activity.SPI, activity);
|
|
| 203 |
+ deleteMultipleAssociation(Activity.SPI, Activity.PROPERTY_FLOATING_OBJECT, FloatingObject.SPI, floatingObjectId);
|
|
| 211 | 204 |
}
|
| 212 | 205 |
|
| 213 | 206 |
private List<ObjectMaterialHierarchyDto> getObjectMaterialHierarchyDtos(List<ObjectMaterial> objectMaterials) {
|
| ... | ... | @@ -31,7 +31,6 @@ import fr.ird.observe.dto.form.Form; |
| 31 | 31 |
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
|
| 32 | 32 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 33 | 33 |
import fr.ird.observe.dto.result.TripChildSaveResultDto;
|
| 34 |
-import fr.ird.observe.entities.DataNotFoundException;
|
|
| 35 | 34 |
import fr.ird.observe.entities.data.ps.common.Trip;
|
| 36 | 35 |
import fr.ird.observe.entities.data.ps.observation.Activity;
|
| 37 | 36 |
import fr.ird.observe.entities.data.ps.observation.ActivityImpl;
|
| ... | ... | @@ -140,13 +139,7 @@ public class RouteServiceLocal extends ObserveServiceLocal implements RouteServi |
| 140 | 139 |
|
| 141 | 140 |
@Override
|
| 142 | 141 |
public boolean delete(String routeId) {
|
| 143 |
- Trip trip = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Trip.class, Trip.PROPERTY_ROUTE, routeId);
|
|
| 144 |
- Route route = Route.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), routeId);
|
|
| 145 |
- if (!trip.containsRoute(route)) {
|
|
| 146 |
- throw new DataNotFoundException(getApplicationLocale(), RouteDto.class, routeId);
|
|
| 147 |
- }
|
|
| 148 |
- trip.removeRoute(route);
|
|
| 149 |
- saveEntity(Trip.SPI, trip);
|
|
| 142 |
+ Trip trip = deleteMultipleAssociation(Trip.SPI, Trip.PROPERTY_ROUTE, Route.SPI, routeId);
|
|
| 150 | 143 |
return Trip.getDao(getTopiaPersistenceContext()).updateEndDate(trip);
|
| 151 | 144 |
}
|
| 152 | 145 |
|
| ... | ... | @@ -103,16 +103,7 @@ public class SetServiceLocal extends ObserveServiceLocal implements SetService { |
| 103 | 103 |
|
| 104 | 104 |
@Override
|
| 105 | 105 |
public void delete(String setSeineId) {
|
| 106 |
- Set set = Set.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), setSeineId);
|
|
| 107 |
- Activity activity = getTopiaPersistenceContext().getSingleAssociationParent(getApplicationLocale(), Activity.class, Activity.PROPERTY_SET, setSeineId);
|
|
| 108 |
- if (!activity.getSet().equals(set)) {
|
|
| 109 |
- throw new DataNotFoundException(getApplicationLocale(), SetDto.class, setSeineId);
|
|
| 110 |
- }
|
|
| 111 |
- activity.setSet(null);
|
|
| 112 |
- saveEntity(Activity.SPI, activity);
|
|
| 113 |
- //FIXME Do this in update entity method
|
|
| 114 |
- updateLastUpdateDate(Set.class);
|
|
| 115 |
- updateLastUpdateDate(Activity.class);
|
|
| 106 |
+ deleteSingleAssociation(setSeineId, Set.SPI, Activity.SPI, Activity.PROPERTY_SET);
|
|
| 116 | 107 |
}
|
| 117 | 108 |
|
| 118 | 109 |
}
|
| ... | ... | @@ -40,6 +40,7 @@ import fr.ird.observe.spi.context.ReferentialDtoEntityContext; |
| 40 | 40 |
import fr.ird.observe.spi.mapping.DtoToEntityContextMapping;
|
| 41 | 41 |
import fr.ird.observe.spi.mapping.EntityToDtoClassMapping;
|
| 42 | 42 |
import fr.ird.observe.toolkit.templates.TemplateContract;
|
| 43 |
+import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition;
|
|
| 43 | 44 |
import io.ultreia.java4all.classmapping.ImmutableClassMapping;
|
| 44 | 45 |
import io.ultreia.java4all.lang.Strings;
|
| 45 | 46 |
import org.apache.commons.lang3.StringUtils;
|
| ... | ... | @@ -227,7 +228,7 @@ public class EntityTransformer extends TopiaEntityTransformer implements Templat |
| 227 | 228 |
if (GeneratorUtil.hasDocumentation(input)) {
|
| 228 | 229 |
setDocumentation(outputInterface, input.getDocumentation());
|
| 229 | 230 |
}
|
| 230 |
- |
|
| 231 |
+ addAnnotation(outputInterface, outputInterface, GenerateJavaBeanDefinition.class);
|
|
| 231 | 232 |
boolean oneParentContainsEntity = false;
|
| 232 | 233 |
List<String> interfaceAlreadyDone = new LinkedList<>();
|
| 233 | 234 |
for (ObjectModelClassifier parent : input.getInterfaces()) {
|