View Javadoc
1   package fr.ifremer.dali.service.system;
2   
3   /*
4    * #%L
5    * Dali :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
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   * SystemService implementation.
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       * {@inheritDoc}
62       */
63      @Override
64      public List<SearchDateDTO> getSearchDates() {
65  
66          // If list not exist, create it
67          if (searchDateList == null) {
68              searchDateList = Arrays.stream(SearchDateValues.values()).map(SearchDateValues::toSearchDateDTO).collect(Collectors.toList());
69          }
70          return searchDateList;
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public List<StateDTO> getStates() {
78  
79          // If list not exist, create it
80          if (stateList == null) {
81              stateList = Arrays.stream(StateValues.values()).map(StateValues::toStateDTO).collect(Collectors.toList());
82          }
83          return stateList;
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public SynchronizationStatusDTO getLocalShare() {
91          return SynchronizationStatusValues.toSynchronizationStatusDTO(SynchronizationStatus.DIRTY.getValue());
92      }
93  
94      /**
95       * {@inheritDoc}
96       */
97      @Override
98      public List<SynchronizationStatusDTO> getAllSynchronizationStatus(boolean withReadyToSyncStatus) {
99  
100         // If list not exist, create it
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      * {@inheritDoc}
112      */
113     @Override
114     public List<FunctionDTO> getFunctionsControlSystem() {
115 
116         // If list not exist, create it
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      * {@inheritDoc}
128      */
129     @Override
130     public List<ControlElementDTO> getControlElements() {
131 
132         // If list not exist, create it
133         if (elementControlList == null) {
134             elementControlList = Arrays.stream(ControlElementValues.values())
135 
136                     // TODO Les mesures sur taxons ne sont pas encore prises en charge
137                     .filter(value -> value != ControlElementValues.TAXON_MEASUREMENT)
138 
139                     .map(ControlElementValues::toControlElementDTO)
140                     .collect(Collectors.toList());
141         }
142         return elementControlList;
143     }
144 
145     /**
146      * {@inheritDoc}
147      */
148     @Override
149     public List<ControlFeatureDTO> getControlFeatures(final ControlElementDTO controlElementDTO) {
150 
151         // Element control
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             // TODO Les mesures sur taxons ne sont pas encore prises en charge
163 //			case TAXON_MEASUREMENT:
164 //				return getFeatureControlTaxonMeasurementList();
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         // If list not exist, create it
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      * Only one list of counting.
200      *
201      * @return ControlFeatureDTO measures list
202      */
203     private List<ControlFeatureDTO> getFeatureControlMeasurementList() {
204 
205         // If list not exist, create it
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         // If list not exist, create it
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      * Only one list of counting.
227      *
228      * @return ControlFeatureDTO observation list
229      */
230     private List<ControlFeatureDTO> getFeatureControlObservationList() {
231 
232         // If list not exist, create it
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      * Only one list of counting.
243      *
244      * @return ControlFeatureDTO prelevement list
245      */
246     private List<ControlFeatureDTO> getFeatureControlSamplingOperationList() {
247 
248         // If list not exist, create it
249         if (featureControlSamplingOperationList == null) {
250             featureControlSamplingOperationList = Arrays.stream(ControlFeatureSamplingOperationValues.values())
251                     .map(ControlFeatureSamplingOperationValues::toControlFeatureDTO)
252                     .collect(Collectors.toList());
253         }
254         return featureControlSamplingOperationList;
255     }
256 }