View Javadoc
1   package fr.ifremer.quadrige2.synchro.service.client;
2   
3   /*-
4    * #%L
5    * Quadrige2 Core :: Quadrige2 Client Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 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.common.synchro.service.SynchroResult;
27  import fr.ifremer.quadrige2.core.exception.BadUpdateDtException;
28  import fr.ifremer.quadrige2.core.exception.DataLockedException;
29  import fr.ifremer.quadrige2.core.exception.Quadrige2BusinessException;
30  import fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException;
31  import fr.ifremer.quadrige2.core.security.AuthenticationInfo;
32  import fr.ifremer.quadrige2.core.vo.administration.program.ProgramVO;
33  import fr.ifremer.quadrige2.core.vo.administration.user.QuserVO;
34  import fr.ifremer.quadrige2.core.vo.data.survey.CampaignVO;
35  import fr.ifremer.quadrige2.core.vo.system.rule.RuleListVO;
36  import fr.ifremer.quadrige2.synchro.vo.SynchroExportContextVO;
37  import fr.ifremer.quadrige2.synchro.vo.SynchroImportContextVO;
38  import fr.ifremer.quadrige2.synchro.vo.SynchroProgressionVO;
39  import org.apache.http.impl.client.CloseableHttpClient;
40  import org.nuiton.jaxx.application.type.ApplicationProgressionModel;
41  import org.springframework.cache.annotation.Cacheable;
42  import org.springframework.transaction.annotation.Propagation;
43  import org.springframework.transaction.annotation.Transactional;
44  
45  import java.io.File;
46  import java.util.Collection;
47  import java.util.List;
48  
49  /**
50   * <p>
51   * SynchroRestClientService interface.
52   * </p>
53   *
54   */
55  @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED)
56  public interface SynchroRestClientService {
57  
58  	/** Constant <code>REMOTE_WRITABLE_PROGRAMS_FOR_USER_CACHE="remoteWritableProgramsForUser"</code> */
59  	String REMOTE_WRITABLE_PROGRAMS_FOR_USER_CACHE = "remoteWritableProgramsForUser";
60  
61  	/**
62  	 * Return the HTTP client
63  	 *
64  	 * @param authenticationInfo
65  	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
66  	 * @return a valid HTTP client
67  	 */
68  	CloseableHttpClient getHttpClient(AuthenticationInfo authenticationInfo);
69  
70  	/**
71  	 * Return data on the authenticated person
72  	 *
73  	 * @param authenticationInfo
74  	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
75  	 * @return could be null if network error
76  	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
77  	 *             if network problem
78  	 */
79  	QuserVO getUser(AuthenticationInfo authenticationInfo) throws Quadrige2TechnicalException;
80  
81  	/**
82  	 * Return user's programs (programs with read/write access rights)
83  	 *
84  	 * @param authenticationInfo
85  	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
86  	 * @return could be null if network error
87  	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
88  	 *             if network problem
89  	 */
90  	@Cacheable(value = REMOTE_WRITABLE_PROGRAMS_FOR_USER_CACHE, key = "#authenticationInfo.login")
91  	List<ProgramVO> getWritableProgramsForUser(AuthenticationInfo authenticationInfo) throws Quadrige2TechnicalException;
92  
93  	/**
94  	 * Return a remote programs
95  	 *
96  	 * @param authenticationInfo
97  	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
98  	 * @param progCd
99  	 *            program code
100 	 * @return could be null if network error
101 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
102 	 *             if network problem
103 	 */
104 	ProgramVO getProgramByCode(AuthenticationInfo authenticationInfo, String progCd) throws Quadrige2TechnicalException;
105 
106 	/**
107 	 * Check is there is updates on referential data
108 	 *
109 	 * @param authenticationInfo
110 	 *            User authentication data
111 	 * @param importContextVO
112 	 *            the context to check
113 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
114 	 *             if network problem
115 	 * @return a new context with updated attributes (<code>withReferential</code> and <code>withData</code>)
116 	 */
117 	SynchroImportContextVO checkImportContext(AuthenticationInfo authenticationInfo, SynchroImportContextVO importContextVO)
118 			throws Quadrige2TechnicalException;
119 
120 	/**
121 	 * Check that the given version is compatible with the synchronization server version. If not, throw a
122 	 * ObsbebBusinessException
123 	 *
124 	 * @param authenticationInfo
125 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
126 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2BusinessException
127 	 *             if version is not compatible
128 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
129 	 *             if network problem
130 	 */
131 	void checkVersion(AuthenticationInfo authenticationInfo) throws Quadrige2TechnicalException, Quadrige2BusinessException;
132 
133 	/**
134 	 * Check synchro version is compatible with the synchronization server version.
135 	 *
136 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2BusinessException
137 	 *             if version is not compatible
138 	 * @param httpClient
139 	 *            a {@link org.apache.http.impl.client.CloseableHttpClient} object.
140 	 */
141 	void checkVersion(CloseableHttpClient httpClient);
142 
143 	/**
144 	 * Send an acknowledge to the remote server (e.g. to delete temporary files, ...)
145 	 *
146 	 * @param authenticationInfo
147 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
148 	 * @param importContextVO
149 	 *            a {@link fr.ifremer.quadrige2.synchro.vo.SynchroImportContextVO} object.
150 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
151 	 *             if any.
152 	 */
153 	void acknowledgeImport(AuthenticationInfo authenticationInfo, SynchroImportContextVO importContextVO) throws Quadrige2TechnicalException;
154 
155 	/**
156 	 * Send a file to server
157 	 *
158 	 * @param authenticationInfo
159 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
160 	 * @param fileToUpload
161 	 *            a {@link java.io.File} object.
162 	 * @param progressionModel
163 	 *            a {@link org.nuiton.jaxx.application.type.ApplicationProgressionModel} object.
164 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
165 	 *             if any.
166 	 */
167 	void uploadExportFile(AuthenticationInfo authenticationInfo, File fileToUpload, ApplicationProgressionModel progressionModel)
168 			throws Quadrige2TechnicalException;
169 
170 	/**
171 	 * Start a new importation on the server
172 	 *
173 	 * @param authenticationInfo
174 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
175 	 * @param importContextVO
176 	 *            a {@link fr.ifremer.quadrige2.synchro.vo.SynchroImportContextVO} object.
177 	 * @param progressionModel
178 	 *            a {@link org.nuiton.jaxx.application.type.ApplicationProgressionModel} object.
179 	 * @throws java.lang.Exception
180 	 *             if any.
181 	 * @return a {@link fr.ifremer.quadrige2.synchro.vo.SynchroProgressionVO} object.
182 	 */
183 	SynchroProgressionVO startImport(AuthenticationInfo authenticationInfo,
184 									 SynchroImportContextVO importContextVO,
185 									 ApplicationProgressionModel progressionModel) throws Exception;
186 
187 	/**
188 	 * Stop a importation running on server
189 	 *
190 	 * @param authenticationInfo
191 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
192 	 * @param importJobId
193 	 *            a {@link java.lang.String} object.
194 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
195 	 * @throws java.lang.Exception
196 	 *             if any.
197 	 */
198 	void stopImport(AuthenticationInfo authenticationInfo, String importJobId) throws Exception;
199 
200 	/**
201 	 * <p>
202 	 * start export on server, then wait the end.
203 	 * </p>
204 	 *
205 	 * @param authenticationInfo
206 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
207 	 * @param exportContextVO
208 	 *            a {@link fr.ifremer.quadrige2.synchro.vo.SynchroExportContextVO} object.
209 	 * @param progressionModel
210 	 *            a {@link org.nuiton.jaxx.application.type.ApplicationProgressionModel} object.
211 	 * @return a {@link fr.ifremer.quadrige2.synchro.vo.SynchroProgressionVO} object.
212 	 * @throws java.lang.Exception
213 	 *             if any.
214 	 */
215 	SynchroProgressionVO startExport(AuthenticationInfo authenticationInfo,
216 									 SynchroExportContextVO exportContextVO,
217 									 ApplicationProgressionModel progressionModel)
218 			throws Exception;
219 
220 	/**
221 	 * <p>
222 	 * Wait end of a started export on server.
223 	 * </p>
224 	 *
225 	 * @param authenticationInfo
226 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
227 	 * @param exportJobId
228 	 *            the job id
229 	 * @param progressionModel
230 	 *            a {@link org.nuiton.jaxx.application.type.ApplicationProgressionModel} object.
231 	 * @return a {@link fr.ifremer.quadrige2.synchro.vo.SynchroProgressionVO} object.
232 	 * @throws java.lang.Exception
233 	 *             if any.
234 	 */
235 	SynchroProgressionVO getExportLastStatus(AuthenticationInfo authenticationInfo,
236 											 String exportJobId,
237 											 ApplicationProgressionModel progressionModel) throws Exception;
238 
239 	/**
240 	 * <p>
241 	 * downloadExportResult.
242 	 * </p>
243 	 *
244 	 * @param authenticationInfo
245 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
246 	 * @param context
247 	 *            a {@link fr.ifremer.quadrige2.synchro.vo.SynchroExportContextVO} object.
248 	 * @param progressionModel
249 	 *            a {@link org.nuiton.jaxx.application.type.ApplicationProgressionModel} object.
250 	 * @return a {@link fr.ifremer.common.synchro.service.SynchroResult} object.
251 	 * @throws java.lang.Exception
252 	 *             if any.
253 	 */
254 	SynchroResult downloadExportResult(AuthenticationInfo authenticationInfo,
255 									   SynchroExportContextVO context,
256 									   ApplicationProgressionModel progressionModel) throws Exception;
257 
258 	/**
259 	 * Stop a exportation running on server
260 	 *
261 	 * @param authenticationInfo
262 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
263 	 * @param exportJobId
264 	 *            a {@link java.lang.String} object.
265 	 * @throws fr.ifremer.quadrige2.core.exception.Quadrige2TechnicalException
266 	 * @throws java.lang.Exception
267 	 *             if any.
268 	 */
269 	void stopExport(AuthenticationInfo authenticationInfo, String exportJobId) throws Exception;
270 
271 	/**
272 	 * <p>
273 	 * acknowledgeExport.
274 	 * </p>
275 	 *
276 	 * @param authenticationInfo
277 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
278 	 * @param context
279 	 *            a {@link fr.ifremer.quadrige2.synchro.vo.SynchroExportContextVO} object.
280 	 * @throws java.lang.Exception
281 	 *             if any.
282 	 */
283 	void acknowledgeExport(AuthenticationInfo authenticationInfo, SynchroExportContextVO context) throws Exception;
284 
285 	/**
286 	 * Save programs remotely
287 	 *
288 	 * @param programs
289 	 *            a {@link java.util.List} object.
290 	 * @param authenticationInfo
291 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
292 	 * @return a {@link java.util.List} object.
293 	 */
294 	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
295 	List<ProgramVO> savePrograms(AuthenticationInfo authenticationInfo, List<ProgramVO> programs);
296 
297 	/**
298 	 * Save campaign remotely
299 	 *
300 	 * @param campaigns
301 	 *            a {@link java.util.List} object.
302 	 * @param authenticationInfo
303 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
304 	 * @return a {@link java.util.List} object.
305 	 * @throws BadUpdateDtException
306 	 *             if any.
307 	 * @throws fr.ifremer.quadrige2.core.exception.DataLockedException
308 	 *             if any.
309 	 */
310 	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
311 	List<CampaignVO> saveCampaigns(AuthenticationInfo authenticationInfo, Collection<CampaignVO> campaigns);
312 
313 	/**
314 	 * Delete campaign remotely
315 	 *
316 	 * @param campaignIds
317 	 *            a {@link java.util.List} object.
318 	 * @param authenticationInfo
319 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
320 	 * @throws DataLockedException
321 	 *             if any.
322 	 */
323 	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
324 	void deleteCampaigns(AuthenticationInfo authenticationInfo, Collection<Integer> campaignIds);
325 
326 	/**
327 	 * Save rule lists remotely
328 	 *
329 	 * @param ruleLists
330 	 *            a {@link java.util.List} object.
331 	 * @param authenticationInfo
332 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
333 	 * @return a {@link java.util.List} object.
334 	 * @throws BadUpdateDtException
335 	 *             if any.
336 	 * @throws DataLockedException
337 	 *             if any.
338 	 */
339 	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
340 	List<RuleListVO> saveRuleLists(AuthenticationInfo authenticationInfo, Collection<RuleListVO> ruleLists);
341 
342 	/**
343 	 * Delete rule lists remotely
344 	 *
345 	 * @param ruleListCds
346 	 *            a {@link java.util.List} object.
347 	 * @param authenticationInfo
348 	 *            a {@link fr.ifremer.quadrige2.core.security.AuthenticationInfo} object.
349 	 * @throws DataLockedException
350 	 *             if any.
351 	 */
352 	@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
353 	void deleteRuleLists(AuthenticationInfo authenticationInfo, Collection<String> ruleListCds);
354 }