View Javadoc
1   package fr.ifremer.dali.service.administration.program;
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.service.DaliTechnicalException;
27  import fr.ifremer.quadrige3.core.exception.SaveForbiddenException;
28  import fr.ifremer.quadrige3.core.security.AuthenticationInfo;
29  import fr.ifremer.quadrige3.core.service.administration.program.ProgramService;
30  import fr.ifremer.dali.dto.configuration.programStrategy.PmfmStrategyDTO;
31  import fr.ifremer.dali.dto.configuration.programStrategy.ProgStratDTO;
32  import fr.ifremer.dali.dto.configuration.programStrategy.ProgramDTO;
33  import fr.ifremer.dali.dto.configuration.programStrategy.StrategyDTO;
34  import fr.ifremer.dali.dto.data.survey.SurveyDTO;
35  import fr.ifremer.dali.dto.referential.DepartmentDTO;
36  import fr.ifremer.dali.dto.referential.pmfm.PmfmDTO;
37  import fr.ifremer.dali.service.StatusFilter;
38  import org.springframework.security.access.prepost.PreAuthorize;
39  import org.springframework.transaction.annotation.Propagation;
40  import org.springframework.transaction.annotation.Transactional;
41  
42  import java.time.LocalDate;
43  import java.util.*;
44  
45  /**
46   * Les services pour la configuration.
47   */
48  @Transactional(readOnly = true)
49  public interface ProgramStrategyService extends ProgramService {
50  
51      /**
52       * Duplicate strategy.
53       *
54       * @param strategy             Strategy.
55       * @param targetProgram        a {@link fr.ifremer.dali.dto.configuration.programStrategy.ProgramDTO} object.
56       * @param skipLocalReferential a boolean.
57       * @return Strategy
58       */
59      @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
60      StrategyDTO duplicateStrategy(StrategyDTO strategy, ProgramDTO targetProgram, boolean skipLocalReferential);
61  
62      /**
63       * Get all programs with write rights fot current user
64       *
65       * @return programs list
66       */
67      List<ProgramDTO> getWritablePrograms();
68  
69      /**
70       * Recherche un programme suivant son identifiant.
71       *
72       * @param programCode l'identifiant du programme
73       * @return Le programme recherche
74       */
75      ProgramDTO getWritableProgramByCode(final String programCode);
76  
77      /**
78       * Retrieve programs by status (ALL, LOCAL, ...). See StatusFilter enumeration.
79       *
80       * @param statusFilter the filter to apply
81       * @return list of programs found
82       */
83      List<ProgramDTO> getWritableProgramsByStatus(StatusFilter statusFilter);
84  
85      List<ProgramDTO> getWritableProgramsByLocationAndDate(int locationId, Date date);
86  
87      /**
88       * Retrieve active programs with access rights for the given user
89       *
90       * @param userId       identifier of the user
91       * @return list of programs found
92       */
93      List<ProgramDTO> getWritableProgramsByUser(int userId);
94  
95      /**
96       * Retrieve programs by status (ALL, LOCAL, ...), and with access rights for the given user
97       *
98       * @param userId       identifier of the user
99       * @param statusFilter the filter to apply
100      * @return list of programs found
101      */
102     List<ProgramDTO> getWritableProgramsByUser(int userId, StatusFilter statusFilter);
103 
104     /**
105      * Retrieve active programs with manager rights for the current user
106      *
107      * @return list of programs found
108      */
109     List<ProgramDTO> getManagedPrograms();
110 
111     /**
112      * Retrieve active programs with manager rights for the given user
113      *
114      * @param userId       identifier of the user
115      * @return list of programs found
116      */
117     List<ProgramDTO> getManagedProgramsByUser(int userId);
118 
119     /**
120      * Retrieve programs by status (ALL, LOCAL, ...), and with manager rights for the given user
121      *
122      * @param userId       identifier of the user
123      * @param statusFilter the filter to apply
124      * @return list of programs found
125      */
126     List<ProgramDTO> getManagedProgramsByUser(int userId, StatusFilter statusFilter);
127 
128     /**
129      * Will load (if necessary) program's strategies and locations
130      *
131      * @param program a not null program
132      */
133     void loadStrategiesAndLocations(final ProgramDTO program);
134 
135     /**
136      * Will load (if necessary) strategy's applied periods, AND add all other program's locations
137      *
138      * @param program  a not null program
139      * @param strategy a not null strategy
140      */
141     void loadAppliedPeriodsAndPmfmStrategies(ProgramDTO program, StrategyDTO strategy);
142 
143     /**
144      * Get the list of all PMFM strategies for the survey
145      *
146      * @param survey a {@link SurveyDTO} object.
147      * @return a {@link java.util.List} object.
148      */
149     List<PmfmStrategyDTO> getPmfmStrategiesBySurvey(SurveyDTO survey);
150 
151     /**
152      * Get the list of all PMFM strategies for programs and applicable in date range
153      *
154      * @param programCodes program codes
155      * @param startDate    start date
156      * @param endDate      end date
157      * @return a {@link java.util.List} object.
158      */
159     Set<PmfmStrategyDTO> getPmfmStrategiesByProgramsAndDates(Collection<String> programCodes, LocalDate startDate, LocalDate endDate);
160 
161     /**
162      * Get the first not null sampling department from applied strategy
163      *
164      * @param survey a {@link fr.ifremer.dali.dto.data.survey.SurveyDTO} object.
165      * @return a {@link fr.ifremer.dali.dto.referential.DepartmentDTO} object.
166      */
167     DepartmentDTO getSamplingDepartmentOfAppliedStrategyBySurvey(SurveyDTO survey);
168 
169     /**
170      * Get the first not null analysis department from applied strategy
171      *
172      * @param survey a {@link fr.ifremer.dali.dto.data.survey.SurveyDTO} object.
173      * @return a {@link fr.ifremer.dali.dto.referential.DepartmentDTO} object.
174      */
175     DepartmentDTO getAnalysisDepartmentOfAppliedStrategyBySurvey(SurveyDTO survey);
176 
177     /**
178      * Get the list of PMFMS used to populate the sampling operation table
179      *
180      * @param survey the survey from where the program, location and date are used to populate the list
181      * @return a List of PmfmDTO
182      */
183     List<PmfmDTO> getPmfmsForSurvey(SurveyDTO survey);
184 
185     /**
186      * Get the list of grouped PMFMS used to populate the sampling operation table
187      *
188      * @param survey the survey from where the program, location and date are used to populate the list
189      * @return a List of PmfmDTO
190      */
191     List<PmfmDTO> getGroupedPmfmsForSurvey(SurveyDTO survey);
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> getPmfmsForSamplingOperationBySurvey(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> getGroupedPmfmsForSamplingOperationBySurvey(SurveyDTO survey);
208 
209     /**
210      * Save a list of local program
211      *
212      * @param programs a {@link java.util.List} object.
213      * @throws DaliTechnicalException if one program is not local (add argument authenticationInfo to save it remotely)
214      */
215     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {
216             RuntimeException.class,
217             SaveForbiddenException.class
218     })
219     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
220     void savePrograms(List<? extends ProgramDTO> programs);
221 
222     /**
223      * Save a list of remote program will be saved to remote server
224      *
225      * @param programs           a {@link java.util.List} object.
226      * @param authenticationInfo a {@link fr.ifremer.quadrige3.core.security.AuthenticationInfo} object.
227      */
228     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {
229             RuntimeException.class,
230             SaveForbiddenException.class
231     })
232     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
233     void savePrograms(AuthenticationInfo authenticationInfo, List<? extends ProgramDTO> programs);
234 
235     /**
236      * Recherche les strategies pour un lieu
237      *
238      * @param locationId Identifiant du lieu
239      * @return La liste de strategies
240      */
241     List<ProgStratDTO> getStrategyUsageByLocationId(Integer locationId);
242 
243     /**
244      * Recherche les strategies pour un programme et un lieu
245      *
246      * @param programCode Identifiant programme
247      * @param locationId  Identifiant lieu
248      * @return La liste de strategies
249      */
250     List<ProgStratDTO> getStrategyUsageByProgramAndLocationId(final String programCode, final Integer locationId);
251 
252     /**
253      * <p>saveStrategiesByProgramAndLocation.</p>
254      *
255      * @param strategies a {@link java.util.List} object.
256      * @param locationId a int.
257      */
258     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {
259             RuntimeException.class,
260             SaveForbiddenException.class
261     })
262     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
263     void saveStrategiesByProgramAndLocation(AuthenticationInfo authenticationInfo, List<ProgStratDTO> strategies, int locationId);
264 
265     /**
266      * Get list a program for user (with read/write access rights), from the remote synchro server
267      *
268      * @param authenticationInfo Authentication info, to connect to remote server
269      * @return a {@link java.util.List} object.
270      */
271     @Transactional(propagation = Propagation.NOT_SUPPORTED)
272     List<ProgramDTO> getRemoteProgramsByUser(AuthenticationInfo authenticationInfo);
273 
274     /**
275      * Get if a user has some read/write access rights on at least on program, from the remote synchro server
276      *
277      * @param authenticationInfo authentication info, to connect to remote server
278      * @return a boolean.
279      */
280     @Transactional(propagation = Propagation.NOT_SUPPORTED)
281     boolean hasRemoteAccessRightOnProgram(AuthenticationInfo authenticationInfo);
282 
283     List<ProgramDTO> getProgramsByCodes(List<String> programCodes);
284 }
285 
286