1 package fr.ifremer.dali.service.system;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import fr.ifremer.dali.dto.FunctionDTO;
27 import fr.ifremer.dali.dto.SearchDateDTO;
28 import fr.ifremer.dali.dto.StateDTO;
29 import fr.ifremer.dali.dto.SynchronizationStatusDTO;
30 import fr.ifremer.dali.dto.configuration.control.ControlElementDTO;
31 import fr.ifremer.dali.dto.configuration.control.ControlFeatureDTO;
32 import fr.ifremer.dali.dto.enums.*;
33 import fr.ifremer.quadrige3.core.dao.system.synchronization.SynchronizationStatus;
34 import fr.ifremer.quadrige3.ui.core.dto.MonthDTO;
35 import fr.ifremer.quadrige3.ui.core.dto.month.MonthValues;
36 import org.springframework.stereotype.Service;
37
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.List;
41 import java.util.stream.Collectors;
42
43
44
45
46 @Service("daliSystemService")
47 public class SystemServiceImpl implements SystemService {
48
49 private List<SynchronizationStatusDTO> synchronizationStatusList = null;
50 private List<FunctionDTO> functionControlList = null;
51 private List<ControlElementDTO> elementControlList = null;
52 private List<ControlFeatureDTO> featureControlMeasurementList = null;
53 private List<ControlFeatureDTO> featureControlTaxonMeasurementList = null;
54 private List<ControlFeatureDTO> featureControlObservationList = null;
55 private List<ControlFeatureDTO> featureControlSamplingOperationList = null;
56 private List<SearchDateDTO> searchDateList = null;
57 private List<StateDTO> stateList = null;
58 private List<MonthDTO> monthList = null;
59
60
61
62
63 @Override
64 public List<SearchDateDTO> getSearchDates() {
65
66
67 if (searchDateList == null) {
68 searchDateList = Arrays.stream(SearchDateValues.values()).map(SearchDateValues::toSearchDateDTO).collect(Collectors.toList());
69 }
70 return searchDateList;
71 }
72
73
74
75
76 @Override
77 public List<StateDTO> getStates() {
78
79
80 if (stateList == null) {
81 stateList = Arrays.stream(StateValues.values()).map(StateValues::toStateDTO).collect(Collectors.toList());
82 }
83 return stateList;
84 }
85
86
87
88
89 @Override
90 public SynchronizationStatusDTO getLocalShare() {
91 return SynchronizationStatusValues.toSynchronizationStatusDTO(SynchronizationStatus.DIRTY.getValue());
92 }
93
94
95
96
97 @Override
98 public List<SynchronizationStatusDTO> getAllSynchronizationStatus(boolean withReadyToSyncStatus) {
99
100
101 if (synchronizationStatusList == null) {
102 synchronizationStatusList = Arrays.stream(SynchronizationStatusValues.values())
103 .filter(value -> withReadyToSyncStatus || value != SynchronizationStatusValues.READY_TO_SYNCHRONIZE)
104 .map(SynchronizationStatusValues::toSynchronizationStatusDTO)
105 .collect(Collectors.toList());
106 }
107 return synchronizationStatusList;
108 }
109
110
111
112
113 @Override
114 public List<FunctionDTO> getFunctionsControlSystem() {
115
116
117 if (functionControlList == null) {
118
119 functionControlList = Arrays.stream(ControlFunctionValues.values())
120 .map(ControlFunctionValues::toFunctionDTO)
121 .collect(Collectors.toList());
122 }
123 return functionControlList;
124 }
125
126
127
128
129 @Override
130 public List<ControlElementDTO> getControlElements() {
131
132
133 if (elementControlList == null) {
134 elementControlList = Arrays.stream(ControlElementValues.values())
135
136
137 .filter(value -> value != ControlElementValues.TAXON_MEASUREMENT)
138
139 .map(ControlElementValues::toControlElementDTO)
140 .collect(Collectors.toList());
141 }
142 return elementControlList;
143 }
144
145
146
147
148 @Override
149 public List<ControlFeatureDTO> getControlFeatures(final ControlElementDTO controlElementDTO) {
150
151
152 final ControlElementValues elementControl = ControlElementValues.getByCode(controlElementDTO.getCode());
153 List<ControlFeatureDTO> features = new ArrayList<>();
154
155 if (elementControl == null) {
156 return features;
157 }
158
159 switch (elementControl) {
160 case MEASUREMENT:
161 return getFeatureControlMeasurementList();
162
163
164
165 case SURVEY:
166 return getFeatureControlObservationList();
167 case SAMPLING_OPERATION:
168 return getFeatureControlSamplingOperationList();
169 default:
170 return features;
171 }
172
173 }
174
175 @Override
176 public List<MonthDTO> getMonths() {
177
178 if (monthList == null) {
179 monthList = Arrays.stream(MonthValues.values()).map(MonthValues::toDTO).collect(Collectors.toList());
180 }
181 return monthList;
182 }
183
184 @Override
185 public void clearCaches() {
186
187 synchronizationStatusList = null;
188 functionControlList = null;
189 elementControlList = null;
190 featureControlMeasurementList = null;
191 featureControlTaxonMeasurementList = null;
192 featureControlObservationList = null;
193 featureControlSamplingOperationList = null;
194 searchDateList = null;
195 stateList = null;
196 }
197
198
199
200
201
202
203 private List<ControlFeatureDTO> getFeatureControlMeasurementList() {
204
205
206 if (featureControlMeasurementList == null) {
207 featureControlMeasurementList = Arrays.stream(ControlFeatureMeasurementValues.values())
208 .map(ControlFeatureMeasurementValues::toControlFeatureDTO)
209 .collect(Collectors.toList());
210 }
211 return featureControlMeasurementList;
212 }
213
214 private List<ControlFeatureDTO> getFeatureControlTaxonMeasurementList() {
215
216
217 if (featureControlTaxonMeasurementList == null) {
218 featureControlTaxonMeasurementList = Arrays.stream(ControlFeatureTaxonMeasurementValues.values())
219 .map(ControlFeatureTaxonMeasurementValues::toControlFeatureDTO)
220 .collect(Collectors.toList());
221 }
222 return featureControlTaxonMeasurementList;
223 }
224
225
226
227
228
229
230 private List<ControlFeatureDTO> getFeatureControlObservationList() {
231
232
233 if (featureControlObservationList == null) {
234 featureControlObservationList = Arrays.stream(ControlFeatureSurveyValues.values())
235 .map(ControlFeatureSurveyValues::toControlFeatureDTO)
236 .collect(Collectors.toList());
237 }
238 return featureControlObservationList;
239 }
240
241
242
243
244
245
246 private List<ControlFeatureDTO> getFeatureControlSamplingOperationList() {
247
248
249 if (featureControlSamplingOperationList == null) {
250 featureControlSamplingOperationList = Arrays.stream(ControlFeatureSamplingOperationValues.values())
251 .map(ControlFeatureSamplingOperationValues::toControlFeatureDTO)
252 .collect(Collectors.toList());
253 }
254 return featureControlSamplingOperationList;
255 }
256 }