Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
014fc593
by Tony Chemit at 2020-12-02T11:12:38+01:00
8 changed files:
- client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/logbook/ActivitySampleUIHandler.java
- client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/logbook/SampleListUIHandler.java
- client/datasource/editor/ll/src/main/java/fr/ird/observe/client/datasource/editor/ll/data/logbook/SampleUIHandler.java
- server/core/src/main/filtered-resources/mapping
- services/api/src/main/java/fr/ird/observe/services/service/data/ll/logbook/ActivitySampleService.java
- − services/api/src/main/java/fr/ird/observe/services/service/data/ll/logbook/SampleService.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/ActivitySampleServiceLocal.java
- services/local-impl/src/main/java/fr/ird/observe/services/local/service/data/ll/logbook/SampleServiceLocal.java
Changes:
| ... | ... | @@ -34,8 +34,6 @@ import org.nuiton.jaxx.runtime.context.JAXXContextEntryDef; |
| 34 | 34 |
import java.awt.Component;
|
| 35 | 35 |
import java.awt.Container;
|
| 36 | 36 |
|
| 37 |
-import static fr.ird.observe.client.datasource.editor.ll.data.logbook.SampleUIHandler.toTrip;
|
|
| 38 |
- |
|
| 39 | 37 |
/**
|
| 40 | 38 |
* Created on 12/5/14.
|
| 41 | 39 |
*
|
| ... | ... | @@ -88,7 +86,7 @@ public class ActivitySampleUIHandler extends GeneratedActivitySampleUIHandler { |
| 88 | 86 |
.setAskNewParentMessage(I18n.t("observe.data.ll.logbook.Sample.action.move.choose.parent.activity.message"))
|
| 89 | 87 |
.setParentCandidates(this.getLlLogbookActivityService()::getBrothers);
|
| 90 | 88 |
},
|
| 91 |
- r -> toTrip(r) ? getLlLogbookActivitySampleService()::moveToTrip : getLlLogbookActivitySampleService()::move,
|
|
| 89 |
+ r -> getLlLogbookActivitySampleService()::move,
|
|
| 92 | 90 |
r -> new ActivitySampleUIMoveTreeAdapter());
|
| 93 | 91 |
}
|
| 94 | 92 |
|
| ... | ... | @@ -37,7 +37,7 @@ class SampleListUIHandler extends GeneratedSampleListUIHandler { |
| 37 | 37 |
protected void installMoveAction() {
|
| 38 | 38 |
MoveMultiple.installMoveAction(ui,
|
| 39 | 39 |
SampleUIHandler.newSupplier(this, getModel()::toMoveRequest),
|
| 40 |
- r -> SampleUIHandler.toTrip(r) ? getLlLogbookSampleService()::move : getLlLogbookSampleService()::moveToActivity,
|
|
| 40 |
+ r -> getLlLogbookSampleService()::move,
|
|
| 41 | 41 |
r -> SampleUIHandler.toTrip(r) ? new DefaultMultipleMoveTreeAdapter() : new ActivitySampleUIMoveTreeAdapter());
|
| 42 | 42 |
}
|
| 43 | 43 |
}
|
| ... | ... | @@ -118,7 +118,7 @@ class SampleUIHandler extends GeneratedSampleUIHandler { |
| 118 | 118 |
protected void installMoveAction() {
|
| 119 | 119 |
MoveOpenable.installAction(ui,
|
| 120 | 120 |
newSupplier(this, getModel()::toMoveRequest),
|
| 121 |
- r -> toTrip(r) ? getLlLogbookSampleService()::move : getLlLogbookSampleService()::moveToActivity,
|
|
| 121 |
+ r -> getLlLogbookSampleService()::move,
|
|
| 122 | 122 |
r -> toTrip(r) ? new DefaultSingleMoveTreeAdapter() : new ActivitySampleUIMoveTreeAdapter());
|
| 123 | 123 |
}
|
| 124 | 124 |
|
| ... | ... | @@ -128,7 +128,6 @@ GET /api/v1/data/ll/logbook/ActivitySampleService/loadDto |
| 128 | 128 |
GET /api/v1/data/ll/logbook/ActivitySampleService/loadForm v1.data.ll.logbook.ActivitySampleServiceRestApi.loadForm
|
| 129 | 129 |
GET /api/v1/data/ll/logbook/ActivitySampleService/loadReferenceToRead v1.data.ll.logbook.ActivitySampleServiceRestApi.loadReferenceToRead
|
| 130 | 130 |
POST /api/v1/data/ll/logbook/ActivitySampleService/move v1.data.ll.logbook.ActivitySampleServiceRestApi.move
|
| 131 |
-POST /api/v1/data/ll/logbook/ActivitySampleService/moveToTrip v1.data.ll.logbook.ActivitySampleServiceRestApi.moveToTrip
|
|
| 132 | 131 |
GET /api/v1/data/ll/logbook/ActivitySampleService/preCreate v1.data.ll.logbook.ActivitySampleServiceRestApi.preCreate
|
| 133 | 132 |
POST /api/v1/data/ll/logbook/ActivitySampleService/save v1.data.ll.logbook.ActivitySampleServiceRestApi.save
|
| 134 | 133 |
DELETE /api/v1/data/ll/logbook/ActivityService/delete v1.data.ll.logbook.ActivityServiceRestApi.delete
|
| ... | ... | @@ -149,7 +148,6 @@ GET /api/v1/data/ll/logbook/SampleService/loadDto |
| 149 | 148 |
GET /api/v1/data/ll/logbook/SampleService/loadForm v1.data.ll.logbook.SampleServiceRestApi.loadForm
|
| 150 | 149 |
GET /api/v1/data/ll/logbook/SampleService/loadReferenceToRead v1.data.ll.logbook.SampleServiceRestApi.loadReferenceToRead
|
| 151 | 150 |
POST /api/v1/data/ll/logbook/SampleService/move v1.data.ll.logbook.SampleServiceRestApi.move
|
| 152 |
-POST /api/v1/data/ll/logbook/SampleService/moveToActivity v1.data.ll.logbook.SampleServiceRestApi.moveToActivity
|
|
| 153 | 151 |
GET /api/v1/data/ll/logbook/SampleService/preCreate v1.data.ll.logbook.SampleServiceRestApi.preCreate
|
| 154 | 152 |
POST /api/v1/data/ll/logbook/SampleService/save v1.data.ll.logbook.SampleServiceRestApi.save
|
| 155 | 153 |
GET /api/v1/data/ll/logbook/SetCatchService/getCatchSpecies v1.data.ll.logbook.SetCatchServiceRestApi.getCatchSpecies
|
| ... | ... | @@ -43,10 +43,5 @@ public interface ActivitySampleService extends GeneratedActivitySampleService { |
| 43 | 43 |
@Write
|
| 44 | 44 |
@Post
|
| 45 | 45 |
@MethodCredential(Permission.WRITE_DATA)
|
| 46 |
- void moveToTrip(String newTripId, ImmutableSet<String> sampleIds);
|
|
| 47 |
- |
|
| 48 |
- @Write
|
|
| 49 |
- @Post
|
|
| 50 |
- @MethodCredential(Permission.WRITE_DATA)
|
|
| 51 |
- void move(String newActivityId, ImmutableSet<String> sampleIds);
|
|
| 46 |
+ void move(String newParentId, ImmutableSet<String> sampleIds);
|
|
| 52 | 47 |
}
|
| 1 |
-package fr.ird.observe.services.service.data.ll.logbook;
|
|
| 2 |
- |
|
| 3 |
-/*
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe Services :: API
|
|
| 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 |
-import com.google.common.collect.ImmutableSet;
|
|
| 26 |
-import fr.ird.observe.security.Permission;
|
|
| 27 |
-import fr.ird.observe.services.spi.MethodCredential;
|
|
| 28 |
-import fr.ird.observe.services.spi.Write;
|
|
| 29 |
-import io.ultreia.java4all.http.spi.Post;
|
|
| 30 |
- |
|
| 31 |
-/**
|
|
| 32 |
- * @author Tony Chemit - dev@tchemit.fr
|
|
| 33 |
- */
|
|
| 34 |
-public interface SampleService extends GeneratedSampleService {
|
|
| 35 |
- |
|
| 36 |
- @MethodCredential(Permission.WRITE_DATA)
|
|
| 37 |
- @Write
|
|
| 38 |
- @Post
|
|
| 39 |
- void moveToActivity(String newActivityId, ImmutableSet<String> sampleIds);
|
|
| 40 |
-}
|
| ... | ... | @@ -29,6 +29,7 @@ import fr.ird.observe.dto.data.ll.logbook.SampleReference; |
| 29 | 29 |
import fr.ird.observe.dto.reference.DataDtoReferenceSet;
|
| 30 | 30 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 31 | 31 |
import fr.ird.observe.entities.DataNotFoundException;
|
| 32 |
+import fr.ird.observe.entities.Entity;
|
|
| 32 | 33 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 33 | 34 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 34 | 35 |
import fr.ird.observe.entities.data.ll.logbook.Sample;
|
| ... | ... | @@ -71,37 +72,44 @@ public class ActivitySampleServiceLocal extends EditableDataServiceLocalSupport< |
| 71 | 72 |
}
|
| 72 | 73 |
|
| 73 | 74 |
@Override
|
| 74 |
- public void moveToTrip(String newTripId, ImmutableSet<String> sampleIds) {
|
|
| 75 |
- //FIXME Manage fields to remove like associated observed activity
|
|
| 75 |
+ public void move(String newParentId, ImmutableSet<String> sampleIds) {
|
|
| 76 |
+ Entity entity = loadEntity0(newParentId);
|
|
| 77 |
+ if (entity instanceof Activity) {
|
|
| 78 |
+ moveToActivity((Activity) entity, sampleIds);
|
|
| 79 |
+ } else {
|
|
| 80 |
+ moveToTrip((Trip) entity, sampleIds);
|
|
| 81 |
+ }
|
|
| 82 |
+ }
|
|
| 83 |
+ |
|
| 84 |
+ private void moveToActivity(Activity newActivity, ImmutableSet<String> sampleIds) {
|
|
| 76 | 85 |
String sampleLogbookId = sampleIds.iterator().next();
|
| 86 |
+ //FIXME Manage fields to remove like associated observed activity
|
|
| 77 | 87 |
Activity oldActivity = getActivityLonglineLogbook(sampleLogbookId);
|
| 78 | 88 |
Sample sample = oldActivity.getSample();
|
| 79 | 89 |
if (!sampleLogbookId.equals(sample.getTopiaId())) {
|
| 80 | 90 |
throw new DataNotFoundException(getApplicationLocale(), SampleDto.class, sampleLogbookId);
|
| 81 | 91 |
}
|
| 82 |
- Trip oldTrip = getParent(Trip.SPI, Trip.PROPERTY_ACTIVITY_LOGBOOK, oldActivity.getTopiaId());
|
|
| 83 |
- Trip newTrip = Trip.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), newTripId);
|
|
| 84 | 92 |
oldActivity.setSample(null);
|
| 85 |
- newTrip.addSample(sample);
|
|
| 86 |
- TripServiceLocal.copyTripLogbookMetaData(oldTrip, newTrip);
|
|
| 93 |
+ newActivity.setSample(sample);
|
|
| 87 | 94 |
saveEntity(Activity.SPI, oldActivity);
|
| 88 |
- saveEntity(Trip.SPI, newTrip);
|
|
| 95 |
+ saveEntity(Activity.SPI, newActivity);
|
|
| 89 | 96 |
}
|
| 90 | 97 |
|
| 91 |
- @Override
|
|
| 92 |
- public void move(String newActivityId, ImmutableSet<String> sampleIds) {
|
|
| 93 |
- String sampleLogbookId = sampleIds.iterator().next();
|
|
| 98 |
+ private void moveToTrip(Trip newTrip, ImmutableSet<String> sampleIds) {
|
|
| 94 | 99 |
//FIXME Manage fields to remove like associated observed activity
|
| 100 |
+ String sampleLogbookId = sampleIds.iterator().next();
|
|
| 95 | 101 |
Activity oldActivity = getActivityLonglineLogbook(sampleLogbookId);
|
| 96 |
- Activity newActivity = Activity.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), newActivityId);
|
|
| 97 | 102 |
Sample sample = oldActivity.getSample();
|
| 98 | 103 |
if (!sampleLogbookId.equals(sample.getTopiaId())) {
|
| 99 | 104 |
throw new DataNotFoundException(getApplicationLocale(), SampleDto.class, sampleLogbookId);
|
| 100 | 105 |
}
|
| 106 |
+ Trip oldTrip = getParent(Trip.SPI, Trip.PROPERTY_ACTIVITY_LOGBOOK, oldActivity.getTopiaId());
|
|
| 107 |
+ |
|
| 101 | 108 |
oldActivity.setSample(null);
|
| 102 |
- newActivity.setSample(sample);
|
|
| 109 |
+ newTrip.addSample(sample);
|
|
| 110 |
+ TripServiceLocal.copyTripLogbookMetaData(oldTrip, newTrip);
|
|
| 103 | 111 |
saveEntity(Activity.SPI, oldActivity);
|
| 104 |
- saveEntity(Activity.SPI, newActivity);
|
|
| 112 |
+ saveEntity(Trip.SPI, newTrip);
|
|
| 105 | 113 |
}
|
| 106 | 114 |
|
| 107 | 115 |
private Activity getActivityLonglineLogbook(String sampleLogbookId) {
|
| ... | ... | @@ -27,6 +27,7 @@ import com.google.common.collect.Iterables; |
| 27 | 27 |
import fr.ird.observe.dto.data.ll.logbook.SampleDto;
|
| 28 | 28 |
import fr.ird.observe.dto.data.ll.logbook.SampleReference;
|
| 29 | 29 |
import fr.ird.observe.dto.result.SaveResultDto;
|
| 30 |
+import fr.ird.observe.entities.Entity;
|
|
| 30 | 31 |
import fr.ird.observe.entities.data.ll.common.Trip;
|
| 31 | 32 |
import fr.ird.observe.entities.data.ll.logbook.Activity;
|
| 32 | 33 |
import fr.ird.observe.entities.data.ll.logbook.Sample;
|
| ... | ... | @@ -73,13 +74,22 @@ public class SampleServiceLocal extends OpenableDataServiceLocalSupport<Trip, Sa |
| 73 | 74 |
}
|
| 74 | 75 |
|
| 75 | 76 |
@Override
|
| 76 |
- public void moveToActivity(String newActivityId, ImmutableSet<String> sampleIds) {
|
|
| 77 |
+ public void move(String newParentId, ImmutableSet<String> ids) {
|
|
| 78 |
+ Entity entity = loadEntity0(newParentId);
|
|
| 79 |
+ if (entity instanceof Activity) {
|
|
| 80 |
+ moveToActivity((Activity) entity, ids);
|
|
| 81 |
+ } else {
|
|
| 82 |
+ // default behaviour
|
|
| 83 |
+ super.move(newParentId, ids);
|
|
| 84 |
+ }
|
|
| 85 |
+ }
|
|
| 86 |
+ |
|
| 87 |
+ private void moveToActivity(Activity newActivity, ImmutableSet<String> sampleIds) {
|
|
| 77 | 88 |
String sampleLogbookId = sampleIds.iterator().next();
|
| 78 | 89 |
Trip oldTrip = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Trip.class, Trip.PROPERTY_SAMPLE, sampleLogbookId);
|
| 79 |
- Trip newTrip = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Trip.class, Trip.PROPERTY_ACTIVITY_LOGBOOK, newActivityId);
|
|
| 90 |
+ Trip newTrip = getTopiaPersistenceContext().getMultipleAssociationParent(getApplicationLocale(), Trip.class, Trip.PROPERTY_ACTIVITY_LOGBOOK, newActivity.getTopiaId());
|
|
| 80 | 91 |
Sample sample = Sample.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), sampleLogbookId);
|
| 81 | 92 |
oldTrip.removeSample(sample);
|
| 82 |
- Activity newActivity = Activity.loadEntity(getApplicationLocale(), getTopiaPersistenceContext(), newActivityId);
|
|
| 83 | 93 |
//WARNING need to recreate entity, but ids are not changed :)
|
| 84 | 94 |
newActivity.setSample(getTopiaPersistenceContext().getLlLogbookSampleDao().create(sample));
|
| 85 | 95 |
if (TripServiceLocal.copyTripLogbookMetaData(oldTrip, newTrip)) {
|