View Javadoc
1   package fr.ifremer.reefdb.service.administration.program;
2   
3   /*
4    * #%L
5    * Reef DB :: 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.quadrige3.core.security.AuthenticationInfo;
27  import fr.ifremer.quadrige3.core.service.administration.program.ProgramService;
28  import fr.ifremer.reefdb.dto.configuration.programStrategy.PmfmStrategyDTO;
29  import fr.ifremer.reefdb.dto.configuration.programStrategy.ProgStratDTO;
30  import fr.ifremer.reefdb.dto.configuration.programStrategy.ProgramDTO;
31  import fr.ifremer.reefdb.dto.configuration.programStrategy.StrategyDTO;
32  import fr.ifremer.reefdb.dto.data.survey.SurveyDTO;
33  import fr.ifremer.reefdb.dto.referential.DepartmentDTO;
34  import fr.ifremer.reefdb.dto.referential.pmfm.PmfmDTO;
35  import fr.ifremer.reefdb.service.StatusFilter;
36  import org.springframework.security.access.prepost.PreAuthorize;
37  import org.springframework.transaction.annotation.Propagation;
38  import org.springframework.transaction.annotation.Transactional;
39  
40  import java.util.*;
41  
42  /**
43   * Les services pour la configuration.
44   */
45  @Transactional(readOnly = true)
46  public interface ProgramStrategyService extends ProgramService {
47  
48      /**
49       * Duplicate strategy.
50       *
51       * @param strategy             Strategy.
52       * @param targetProgram a {@link fr.ifremer.reefdb.dto.configuration.programStrategy.ProgramDTO} object.
53       * @param skipLocalReferential a boolean.
54       * @return Strategy
55       */
56      @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).LOCAL_ADMIN)")
57      StrategyDTO duplicateStrategy(StrategyDTO strategy, ProgramDTO targetProgram, boolean skipLocalReferential);
58  
59  
60      List<ProgramDTO> getProgramsByCodes(List<String> programCodes);
61  
62  
63      /**
64       * Retrieve programs by status (NATIONAL, LOCAL, ...). See StatusFilter enumeration.
65       *
66       * @param statusFilter the filter to apply
67       * @return list of programs found
68       */
69      @Deprecated
70      List<ProgramDTO> getProgramsByStatus(StatusFilter statusFilter);
71  
72      /**
73       * Retrieve programs by status (NATIONAL, LOCAL, ...), and with access rights for the given user
74       *
75       * @param userId       identifier of the user
76       * @param statusFilter the filter to apply
77       * @return list of programs found
78       */
79      List<ProgramDTO> getWritableProgramsByUserAndStatus(int userId, StatusFilter statusFilter);
80  
81      List<ProgramDTO> getWritableProgramsByCampaignId(Integer campaignId);
82  
83      List<ProgramDTO> getWritablePrograms();
84  
85      List<ProgramDTO> getWritableProgramsByLocationAndDate(Integer locationId, Date date);
86  
87      ProgramDTO getWritableProgramByCode(String programCode);
88  
89      /**
90       * Retrieve active programs with manager rights for the current user
91       *
92       * @return list of programs found
93       */
94      List<ProgramDTO> getManagedPrograms();
95  
96      /**
97       * Retrieve active programs with manager rights for the given user
98       *
99       * @param userId       identifier of the user
100      * @return list of programs found
101      */
102     List<ProgramDTO> getManagedProgramsByUser(int userId);
103 
104     /**
105      * Retrieve programs by status (NATIONAL, LOCAL, ...), and with manager rights for the given user
106      *
107      * @param userId       identifier of the user
108      * @param statusFilter the filter to apply
109      * @return list of programs found
110      */
111     List<ProgramDTO> getManagedProgramsByUserAndStatus(int userId, StatusFilter statusFilter);
112 
113     /**
114      * <p>isProgramUsedByRuleList.</p>
115      *
116      * @param programCode a {@link java.lang.String} object.
117      * @return a boolean.
118      */
119     boolean isProgramUsedByRuleList(String programCode);
120 
121     /**
122      * <p>isProgramUsedByExtraction.</p>
123      *
124      * @param programCode a {@link java.lang.String} object.
125      * @return a boolean.
126      */
127     boolean isProgramUsedByExtraction(String programCode);
128 
129     /**
130      * <p>isProgramUsedByFilter.</p>
131      *
132      * @param programCode a {@link java.lang.String} object.
133      * @return a boolean.
134      */
135     boolean isProgramUsedByFilter(String programCode);
136 
137     /**
138      * Will load (if necessary) program's strategies and locations
139      *
140      * @param program a not null program
141      */
142     void loadStrategiesAndLocations(final ProgramDTO program);
143 
144     /**
145      * Will load (if necessary) strategy's applied periods, AND add all other program's locations
146      *
147      * @param program  a not null program
148      * @param strategy a not null strategy
149      */
150     void loadAppliedPeriods(ProgramDTO program, StrategyDTO strategy);
151 
152     /**
153      * Get the list of all PMFM strategies for the survey
154      *
155      * @param survey a {@link SurveyDTO} object.
156      * @return a {@link java.util.List} object.
157      */
158     List<PmfmStrategyDTO> getPmfmStrategiesBySurvey(SurveyDTO survey);
159 
160     /**
161      * Get the first not null department from applied strategy
162      *
163      * @param survey a {@link fr.ifremer.reefdb.dto.data.survey.SurveyDTO} object.
164      * @return a {@link fr.ifremer.reefdb.dto.referential.DepartmentDTO} object.
165      */
166     DepartmentDTO getDepartmentOfAppliedStrategyBySurvey(SurveyDTO survey);
167 
168     /**
169      * Get analysis departments by pmfm id, for the given survey
170      *
171      * @param survey a {@link fr.ifremer.reefdb.dto.data.survey.SurveyDTO} object.
172      * @return a {@link java.util.Map} object.
173      */
174     Map<Integer, DepartmentDTO> getAnalysisDepartmentsByPmfmMapBySurvey(SurveyDTO survey);
175 
176     /**
177      * Get the first not null analysis department from applied strategy
178      *
179      * @param survey a {@link fr.ifremer.reefdb.dto.data.survey.SurveyDTO} object.
180      * @return a {@link fr.ifremer.reefdb.dto.referential.DepartmentDTO} object.
181      */
182     DepartmentDTO getAnalysisDepartmentOfAppliedStrategyBySurvey(SurveyDTO survey);
183 
184     /**
185      * Get the analysis department from applied strategy and pmfm
186      *
187      * @param survey a {@link SurveyDTO} object.
188      * @param pmfms collection of pmfm
189      * @return analyst department
190      */
191     DepartmentDTO getAnalysisDepartmentOfAppliedStrategyBySurvey(SurveyDTO survey, Collection<PmfmDTO> pmfms);
192 
193     /**
194      * Get the list of PMFMS used to populate the sampling operation table
195      *
196      * @param survey the survey from where the program, location and date are used to populate the list
197      * @return a List of PmfmDTO
198      */
199     List<PmfmDTO> getPmfmsForSurvey(SurveyDTO survey);
200 
201     /**
202      * Get the list of grouped PMFMS used to populate the sampling operation table
203      *
204      * @param survey the survey from where the program, location and date are used to populate the list
205      * @return a List of PmfmDTO
206      */
207     List<PmfmDTO> getGroupedPmfmsForSurvey(SurveyDTO survey);
208 
209     /**
210      * Get the list of PMFMS used to populate the sampling operation table
211      *
212      * @param survey the survey from where the program, location and date are used to populate the list
213      * @return a List of PmfmDTO
214      */
215     List<PmfmDTO> getPmfmsForSamplingOperationBySurvey(SurveyDTO survey);
216 
217     /**
218      * Get the list of grouped PMFMS used to populate the sampling operation table
219      *
220      * @param survey the survey from where the program, location and date are used to populate the list
221      * @return a List of PmfmDTO
222      */
223     List<PmfmDTO> getGroupedPmfmsForSamplingOperationBySurvey(SurveyDTO survey);
224 
225     /**
226      * Suppression des programmes.
227      *
228      * @param programCodes Identifiants des programmes
229      */
230     @Transactional(propagation = Propagation.REQUIRED)
231     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).LOCAL_ADMIN)")
232     void deletePrograms(List<String> programCodes);
233 
234     /**
235      * Will load (if necessary) strategy's pmfm(s) and
236      *
237      * @param strategy not null
238      */
239     void loadPmfmStrategy(StrategyDTO strategy);
240 
241     /**
242      * Save a list of local program
243      *
244      * @param programs a {@link java.util.List} object.
245      * @throws fr.ifremer.reefdb.service.ReefDbTechnicalException if one program is not local (add argument authenticationInfo to save it remotely)
246      */
247     @Transactional(propagation = Propagation.REQUIRED)
248     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).LOCAL_ADMIN)")
249     void savePrograms(List<? extends ProgramDTO> programs);
250 
251     /**
252      * Save a list of . Remote program will be saved to remote server
253      *
254      * @param programs a {@link java.util.List} object.
255      * @param authenticationInfo a {@link fr.ifremer.quadrige3.core.security.AuthenticationInfo} object.
256      */
257     @Transactional(propagation = Propagation.REQUIRED)
258     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).LOCAL_ADMIN)")
259     void savePrograms(AuthenticationInfo authenticationInfo, List<? extends ProgramDTO> programs);
260 
261     /**
262      * <p>searchPrograms.</p>
263      *
264      * @param programCode a {@link java.lang.String} object.
265      * @param programName a {@link java.lang.String} object.
266      * @param statusFilter a {@link fr.ifremer.reefdb.service.StatusFilter} object.
267      * @return a {@link java.util.List} object.
268      */
269     List<ProgramDTO> searchPrograms(String programCode, String programName, StatusFilter statusFilter);
270 
271     /**
272      * Recherche les strategies pour un lieu
273      *
274      * @param locationId Identifiant du lieu
275      * @return La liste de strategies
276      */
277     List<ProgStratDTO> getStrategyUsageByLocationId(Integer locationId);
278 
279     /**
280      * Recherche les strategies pour un programme et un lieu
281      *
282      * @param programCode Identifiant programme
283      * @param locationId  Identifiant lieu
284      * @return La liste de strategies
285      */
286     List<ProgStratDTO> getStrategyUsageByProgramAndLocationId(final String programCode, final Integer locationId);
287 
288     /**
289      * <p>saveStrategiesByProgramAndLocation.</p>
290      *
291      * @param strategies a {@link java.util.List} object.
292      * @param locationId a int.
293      */
294     @Transactional(propagation = Propagation.REQUIRED)
295     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).LOCAL_ADMIN)")
296     void saveStrategiesByProgramAndLocation(List<ProgStratDTO> strategies, int locationId);
297 
298     /**
299      * Get list a program for user (with read/write access rights), from the remote synchro server
300      *
301      * @param authenticationInfo Authentication info, to connect to remote server
302      * @return a {@link java.util.List} object.
303      */
304     @Transactional(propagation = Propagation.NOT_SUPPORTED)
305     List<ProgramDTO> getRemoteProgramsByUser(AuthenticationInfo authenticationInfo);
306 
307     /**
308      * Get if a user has some read/write access rights on at least on program, from the remote synchro server
309      *
310      * @param authenticationInfo authentication info, to connect to remote server
311      * @return a boolean.
312      */
313     @Transactional(propagation = Propagation.NOT_SUPPORTED)
314     boolean hasRemoteAccessRightOnProgram(AuthenticationInfo authenticationInfo);
315 
316     /**
317      * Check if the program code exists in database, and return the found program
318      * @param programCode the program code to find
319      * @return the existing program or null if not found
320      */
321     ProgramDTO isProgramExists(String programCode);
322 }
323 
324