| ... |
... |
@@ -22,10 +22,8 @@ package fr.ird.observe.entities.tree; |
|
22
|
22
|
* #L%
|
|
23
|
23
|
*/
|
|
24
|
24
|
|
|
25
|
|
-import com.google.common.collect.ArrayListMultimap;
|
|
26
|
25
|
import com.google.common.collect.ImmutableMap;
|
|
27
|
26
|
import com.google.common.collect.ImmutableSet;
|
|
28
|
|
-import com.google.common.collect.Maps;
|
|
29
|
27
|
import fr.ird.observe.dto.data.ps.common.TripReference;
|
|
30
|
28
|
import fr.ird.observe.dto.decoration.DecoratorServiceSupport;
|
|
31
|
29
|
import fr.ird.observe.dto.referential.ReferentialDto;
|
| ... |
... |
@@ -33,6 +31,7 @@ import fr.ird.observe.dto.referential.ReferentialLocale; |
|
33
|
31
|
import fr.ird.observe.dto.referential.common.PersonReference;
|
|
34
|
32
|
import fr.ird.observe.dto.referential.common.ProgramReference;
|
|
35
|
33
|
import fr.ird.observe.dto.referential.common.VesselReference;
|
|
|
34
|
+import fr.ird.observe.entities.Entity;
|
|
36
|
35
|
import fr.ird.observe.entities.ObserveTopiaPersistenceContextSupport;
|
|
37
|
36
|
import fr.ird.observe.entities.referential.common.Person;
|
|
38
|
37
|
import fr.ird.observe.entities.referential.common.Program;
|
| ... |
... |
@@ -44,6 +43,7 @@ import fr.ird.observe.spi.module.ObserveBusinessProject; |
|
44
|
43
|
import fr.ird.observe.spi.module.ps.BusinessModule;
|
|
45
|
44
|
import fr.ird.observe.tree.ToolkitTreeNode;
|
|
46
|
45
|
import fr.ird.observe.tree.ToolkitTreeNodeBean;
|
|
|
46
|
+import fr.ird.observe.tree.ToolkitTreeNodeBuildChildrenInterceptor;
|
|
47
|
47
|
import fr.ird.observe.tree.io.ToolkitTreeFlatModel;
|
|
48
|
48
|
import fr.ird.observe.tree.io.ToolkitTreeFlatModelRootRequest;
|
|
49
|
49
|
import fr.ird.observe.tree.io.ToolkitTreeFlatModelWriter;
|
| ... |
... |
@@ -57,6 +57,8 @@ import java.util.Map; |
|
57
|
57
|
import java.util.TreeMap;
|
|
58
|
58
|
import java.util.stream.Collectors;
|
|
59
|
59
|
|
|
|
60
|
+import static io.ultreia.java4all.i18n.I18n.t;
|
|
|
61
|
+
|
|
60
|
62
|
/**
|
|
61
|
63
|
* Created on 12/04/2021.
|
|
62
|
64
|
*
|
| ... |
... |
@@ -95,40 +97,35 @@ class TreeBuilderSupport implements WithPermission { |
|
95
|
97
|
fr.ird.observe.spi.module.ll.BusinessModule llBusinessModule = project.getLlBusinessModule();
|
|
96
|
98
|
boolean acceptPsModule = request.acceptedModule(psBusinessModule);
|
|
97
|
99
|
boolean acceptLlModule = request.acceptedModule(llBusinessModule);
|
|
98
|
|
- List<ProgramReference> programList = Program.toReferenceSet(referentialLocale, Program.getDao(persistenceContext).getProgramList(request, tripCountByProgram, acceptPsModule, acceptLlModule).stream(), now).toList();
|
|
99
|
|
- programById = Maps.uniqueIndex(programList, ProgramReference::getId);
|
|
|
100
|
+ List<Program> programList = Program.getDao(persistenceContext).getProgramList(request, tripCountByProgram, acceptPsModule, acceptLlModule);
|
|
|
101
|
+ programById = Program.uniqueIndex(referentialLocale, persistenceContext);
|
|
100
|
102
|
personById = Person.uniqueIndex(referentialLocale, persistenceContext);
|
|
101
|
103
|
vesselById = Vessel.uniqueIndex(referentialLocale, persistenceContext);
|
|
102
|
|
- decoratorService.installDecorator(ProgramReference.class, programList.stream());
|
|
103
|
104
|
if (acceptPsModule) {
|
|
104
|
|
- List<ProgramReference> psProgramList = programList.stream().filter(psBusinessModule::accept).collect(Collectors.toList());
|
|
|
105
|
+ List<Program> psProgramList = programList.stream().filter(p -> psBusinessModule.accept(p.getGearType())).collect(Collectors.toList());
|
|
105
|
106
|
log.info(String.format("Found %d PS program(s).", psProgramList.size()));
|
|
106
|
|
- for (ProgramReference program : psProgramList) {
|
|
107
|
|
- builder.addReference("ps:", program).put("$$tripCount", tripCountByProgram.get(program.getId()));
|
|
|
107
|
+ for (Program program : psProgramList) {
|
|
|
108
|
+ String id = program.getTopiaId();
|
|
|
109
|
+ addEntity(builder, "ps:", program).put("$$tripCount", tripCountByProgram.get(id));
|
|
108
|
110
|
if (loadTrip) {
|
|
109
|
|
- ArrayListMultimap<String, TripReference> psTripByProgram = ArrayListMultimap.create();
|
|
110
|
|
- List<TripReference> trips = fr.ird.observe.entities.data.ps.common.Trip.SPI.getDao(persistenceContext).getChildren(referentialLocale, program.getId(), programById, personById, vesselById);
|
|
111
|
|
- trips.forEach(t -> psTripByProgram.put(t.getProgram().getId(), t));
|
|
|
111
|
+ List<TripReference> trips = fr.ird.observe.entities.data.ps.common.Trip.SPI.getDao(persistenceContext).getChildren(referentialLocale, id, programById, personById, vesselById);
|
|
112
|
112
|
decoratorService.installDecorator(TripReference.class, trips.stream());
|
|
113
|
|
- String prefix = "ps:" + program.getId();
|
|
114
|
|
- List<TripReference> tripList = psTripByProgram.get(program.getId());
|
|
115
|
|
- tripList.forEach(r -> builder.addReference(prefix, r));
|
|
|
113
|
+ String prefix = "ps:" + id;
|
|
|
114
|
+ trips.forEach(r -> builder.addReference(prefix, r));
|
|
116
|
115
|
}
|
|
117
|
116
|
}
|
|
118
|
117
|
}
|
|
119
|
118
|
if (acceptLlModule) {
|
|
120
|
|
- List<ProgramReference> llProgramList = programList.stream().filter(llBusinessModule::accept).collect(Collectors.toList());
|
|
|
119
|
+ List<Program> llProgramList = programList.stream().filter(p -> llBusinessModule.accept(p.getGearType())).collect(Collectors.toList());
|
|
121
|
120
|
log.info(String.format("Found %d LL program(s).", llProgramList.size()));
|
|
122
|
|
- for (ProgramReference program : llProgramList) {
|
|
123
|
|
- builder.addReference("ll:", program).put("$$tripCount", tripCountByProgram.get(program.getId()));
|
|
|
121
|
+ for (Program program : llProgramList) {
|
|
|
122
|
+ String id = program.getTopiaId();
|
|
|
123
|
+ addEntity(builder, "ll:", program).put("$$tripCount", tripCountByProgram.get(id));
|
|
124
|
124
|
if (loadTrip) {
|
|
125
|
|
- ArrayListMultimap<String, fr.ird.observe.dto.data.ll.common.TripReference> llTripByProgram = ArrayListMultimap.create();
|
|
126
|
|
- List<fr.ird.observe.dto.data.ll.common.TripReference> trips = fr.ird.observe.entities.data.ll.common.Trip.SPI.getDao(persistenceContext).getChildren(referentialLocale, program.getId(), programById, personById, vesselById);
|
|
|
125
|
+ List<fr.ird.observe.dto.data.ll.common.TripReference> trips = fr.ird.observe.entities.data.ll.common.Trip.SPI.getDao(persistenceContext).getChildren(referentialLocale, id, programById, personById, vesselById);
|
|
127
|
126
|
decoratorService.installDecorator(fr.ird.observe.dto.data.ll.common.TripReference.class, trips.stream());
|
|
128
|
|
- trips.forEach(t -> llTripByProgram.put(t.getProgram().getId(), t));
|
|
129
|
|
- String prefix = "ll:" + program.getId();
|
|
130
|
|
- List<fr.ird.observe.dto.data.ll.common.TripReference> tripList = llTripByProgram.get(program.getId());
|
|
131
|
|
- tripList.forEach(r -> builder.addReference(prefix, r));
|
|
|
127
|
+ String prefix = "ll:" + id;
|
|
|
128
|
+ trips.forEach(r -> builder.addReference(prefix, r));
|
|
132
|
129
|
}
|
|
133
|
130
|
}
|
|
134
|
131
|
}
|
| ... |
... |
@@ -143,6 +140,13 @@ class TreeBuilderSupport implements WithPermission { |
|
143
|
140
|
return builder.build();
|
|
144
|
141
|
}
|
|
145
|
142
|
|
|
|
143
|
+
|
|
|
144
|
+ public Map<String, Object> addEntity(ToolkitTreeFlatModelWriter builder, String prefix, Entity entity) {
|
|
|
145
|
+ Map<String, Object> states = builder.addShortId(prefix, entity.getTopiaId(), entity.getLastUpdateDate());
|
|
|
146
|
+ states.put(ToolkitTreeNodeBuildChildrenInterceptor.$$_DATA, entity);
|
|
|
147
|
+ return states;
|
|
|
148
|
+ }
|
|
|
149
|
+
|
|
146
|
150
|
protected Long countReferential(Class<? extends ReferentialDto> dtoType) {
|
|
147
|
151
|
return PersistenceBusinessProject.fromReferentialDto(dtoType).getDao(persistenceContext).count();
|
|
148
|
152
|
}
|
| ... |
... |
@@ -156,15 +160,16 @@ class TreeBuilderSupport implements WithPermission { |
|
156
|
160
|
|
|
157
|
161
|
protected void interceptProgram(ToolkitTreeNode node) {
|
|
158
|
162
|
ToolkitTreeNodeBean userObject = node.getUserObject();
|
|
159
|
|
- ProgramReference reference = userObject.popState("$$reference");
|
|
160
|
|
- userObject.copy(reference.toShortDto());
|
|
|
163
|
+ Program entity = userObject.popState(ToolkitTreeNodeBuildChildrenInterceptor.$$_DATA);
|
|
161
|
164
|
Integer tripCount = userObject.popState("$$tripCount");
|
|
162
|
|
- userObject.addState(ToolkitTreeNodeBean.STATE_TEXT, reference.getLongLabel());
|
|
|
165
|
+ String label = String.format("[%s] %s %s", entity.getGearType().getPrefix(), t("observe.data.Data.program"), entity.getLabel(referentialLocale));
|
|
|
166
|
+ userObject.addState(ToolkitTreeNodeBean.STATE_TEXT, label);
|
|
163
|
167
|
userObject.addState(ToolkitTreeNodeBean.STATE_COUNT, tripCount == null ? 0 : tripCount);
|
|
164
|
|
- userObject.addState(ToolkitTreeNodeBean.STATE_ENABLED, reference.isEnabled());
|
|
|
168
|
+ userObject.addState(ToolkitTreeNodeBean.STATE_ENABLED, entity.isEnabled());
|
|
165
|
169
|
userObject.addState(ToolkitTreeNodeBean.STATE_EDITABLE, canWriteData());
|
|
166
|
170
|
}
|
|
167
|
171
|
|
|
|
172
|
+
|
|
168
|
173
|
@Override
|
|
169
|
174
|
public final Permission getCredentials() {
|
|
170
|
175
|
return permission.getCredentials();
|