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.quadrige2.synchro.service.client.vo.SynchroClientExportResult;
27 import fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientExportToFileResult;
28 import fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientImportFromFileResult;
29 import fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientImportResult;
30 import fr.ifremer.quadrige2.synchro.vo.SynchroChangesVO;
31 import fr.ifremer.quadrige2.synchro.vo.SynchroDateOperatorVO;
32 import fr.ifremer.quadrige2.synchro.vo.SynchroImportContextVO;
33 import org.nuiton.jaxx.application.type.ApplicationProgressionModel;
34 import org.springframework.transaction.annotation.Propagation;
35 import org.springframework.transaction.annotation.Transactional;
36
37 import java.io.File;
38 import java.util.Date;
39 import java.util.Set;
40
41 /**
42 * <p>
43 * SynchroClientService interface.
44 * </p>
45 *
46 */
47 @Transactional(propagation = Propagation.REQUIRED)
48 public interface SynchroClientService {
49
50 /**
51 * Run the importation, from a temporary DB to the local DB.
52 *
53 * The transaction is not created here. The method will execute
54 * SynchroClientInternalService.importFromTempDbTransactional
55 * see Mantis #29900
56 *
57 * @param userId
58 * the connected user
59 * @param dbDirToImport
60 * the temporary DB directory
61 * @param importContext
62 * import context
63 * @param dataRejectResolver
64 * resolver that gives the strategy to resolve rejected rows
65 * @param progressionModel
66 * a not null progression model
67 * @param progressionModelMaxCount
68 * the maximum increment that should be used from the importation
69 * @return a {@link fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientImportResult} object.
70 */
71 @Transactional(propagation = Propagation.NEVER)
72 SynchroClientImportResult importFromTempDb(int userId,
73 File dbDirToImport,
74 SynchroImportContextVO importContext,
75 SynchroRejectedRowResolver dataRejectResolver,
76 ApplicationProgressionModel progressionModel,
77 int progressionModelMaxCount);
78
79 /**
80 * Imports referential/data from server to local database.
81 * <p/>
82 * WARNING : Direct connection to Quadrige2 database (synchronization server will not be used).
83 *
84 * The transaction is not created here. The method will execute
85 * SynchroClientInternalService.importFromServerDatabaseTransactional see Mantis #29900
86 *
87 * @param userId
88 * the user to synchronize
89 * @param importContext
90 * import context
91 * @param dataRejectResolver
92 * resolver that gives the strategy to resolve rejected rows
93 * @param progressionModel
94 * a not null progression model
95 * @param progressionModelMaxCount
96 * the maximum increment that should be used from the importation
97 * @return the result of the importation
98 */
99 @Transactional(propagation = Propagation.NEVER)
100 SynchroClientImportResult importFromServerDatabase(
101 int userId,
102 SynchroImportContextVO importContext,
103 SynchroRejectedRowResolver dataRejectResolver,
104 ApplicationProgressionModel progressionModel,
105 int progressionModelMaxCount);
106
107 /**
108 * Clean unused data and files :
109 * <ul>
110 * <li>data synchronized AND outside user access rights, and )</li>
111 * <li>files from user not connected since [today - N years>]</li>
112 * </ul>
113 *
114 * @param userId
115 * The connected user id
116 */
117 void cleanUpUnusedData(int userId);
118
119 /**
120 * Creates a temporary database in the user export directory, exports local data to temp DB and returns a result
121 * object
122 *
123 * @param userId
124 * the user to synchronize
125 * @param progressionModel
126 * a not null progression model
127 * @param progressionModelMaxCount
128 * the maximum increment that should be used from the importation
129 * @return export result object
130 * @param programCodes
131 * a {@link java.util.Set} object.
132 */
133 SynchroClientExportResult exportDataToTempDb(int userId, Set<String> programCodes, ApplicationProgressionModel progressionModel,
134 int progressionModelMaxCount);
135
136 /**
137 * Creates a temporary database in the user export directory, exports national referential (prog/strat) to temp DB
138 * and returns a result
139 * object
140 *
141 * @param userId
142 * the user to synchronize
143 * @param progressionModel
144 * a not null progression model
145 * @param progressionModelMaxCount
146 * the maximum increment that should be used from the importation
147 * @return export result object
148 * @param programCodes
149 * a {@link java.util.Set} object.
150 */
151 SynchroClientExportResult exportNationalProgramsToTempDb(int userId,
152 Set<String> programCodes,
153 ApplicationProgressionModel progressionModel,
154 int progressionModelMaxCount);
155
156 /**
157 * Creates a temporary database, exports local data to temp DB, then export from temp to Quadrige2, and returns an
158 * encapsulating result object
159 *
160 * @param userId
161 * the user to synchronize
162 * @param dataRejectResolver
163 * resolver that gives the strategy to resolve rejected rows
164 * @param progressionModel
165 * a not null progression model
166 * @param progressionModelMaxCount
167 * the maximum increment that should be used from the importation
168 * @param programCodes
169 * a {@link java.util.Set} object.
170 * @return a {@link fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientExportResult} object.
171 */
172 SynchroClientExportResult exportToServerDatabase(int userId, Set<String> programCodes, SynchroRejectedRowResolver dataRejectResolver,
173 ApplicationProgressionModel progressionModel,
174 int progressionModelMaxCount);
175
176 /**
177 * Finishes export: display rejects, deals with rejected rows re-import reverted Pks
178 *
179 * @param userId
180 * the user whose export synchronization must be finalized
181 * @param exportResult
182 * export result (coming from a direct synchroniation or a direct one)
183 * @param rejectResolver
184 * resolver that gives the strategy to resolve rejected rows
185 * @param synchroFailed
186 * if true, this method will do nothing more than displaying reject error messages (if any rejects) using
187 * the reject resolver
188 * @param runPkRevert
189 * if true, at the end of the method Pks to be reverted will be re-imported
190 * @return true if one (or more) reject messages have been displayed. if <code>true</code>, the caller method do not
191 * need to display a error again.
192 */
193 boolean finishExportData(int userId, SynchroClientExportResult exportResult,
194 SynchroRejectedRowResolver rejectResolver, boolean synchroFailed, boolean runPkRevert);
195
196 /**
197 * Export data into a file, and returns an encapsulating result object
198 *
199 * @param userId
200 * the user to synchronize
201 * @param file
202 * Path to the file to create (should not exists).
203 * @param programCodes
204 * programs to export that gives the strategy to resolve rejected rows
205 * @param dirtyOnly
206 * a boolean.
207 * @param dateOperator
208 * a {@link fr.ifremer.quadrige2.synchro.vo.SynchroDateOperatorVO} object.
209 * @param startDate
210 * a {@link java.util.Date} object.
211 * @param endDate
212 * a {@link java.util.Date} object.
213 * @param progressionModel
214 * a not null progression model
215 * @param progressionModelMaxCount
216 * the maximum increment that should be used from the importation @return
217 * @return a {@link fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientExportToFileResult} object.
218 */
219 SynchroClientExportToFileResult exportToFile(int userId, File file, Set<String> programCodes, boolean dirtyOnly,
220 SynchroDateOperatorVO dateOperator, Date startDate, Date endDate,
221 ApplicationProgressionModel progressionModel, int progressionModelMaxCount);
222
223 /**
224 * Export local referential into a file, and returns an encapsulating result object
225 *
226 * @param userId
227 * the user to synchronize
228 * @param file
229 * Path to the file to create (should not exists).
230 * @param programCodes
231 * programs to export that gives the strategy to resolve rejected rows
232 * @param progressionModel
233 * a not null progression model
234 * @param progressionModelMaxCount
235 * the maximum increment that should be used from the importation
236 * @return a {@link fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientExportToFileResult} object.
237 */
238 SynchroClientExportToFileResult exportReferentialToFile(int userId,
239 File file,
240 Set<String> programCodes,
241 ApplicationProgressionModel progressionModel,
242 int progressionModelMaxCount);
243
244 /**
245 * Export all referential (local and national) into a file, and returns an encapsulating result object
246 *
247 * @param userId
248 * the user to synchronize
249 * @param file
250 * Path to the file to create (should not exists).
251 * @param progressionModel
252 * a not null progression model
253 * @param progressionModelMaxCount
254 * the maximum increment that should be used from the importation
255 * @return a {@link fr.ifremer.quadrige2.synchro.service.client.vo.SynchroClientExportToFileResult} object.
256 */
257 SynchroClientExportToFileResult exportAllReferentialToFile(int userId,
258 File file,
259 ApplicationProgressionModel progressionModel,
260 int progressionModelMaxCount);
261
262 /**
263 * Imports referential/data from a DB file. Will use a basic referential resolver, that remap all
264 * duplicated entries.
265 *
266 * @param userId
267 * the connected user
268 * @param file
269 * the DB file to import
270 * @param dataRejectResolver
271 * resolver that gives the strategy to resolve rejected rows, on data
272 * @param progressionModel
273 * a not null progression model
274 * @param progressionModelMaxCount
275 * the maximum increment that should be used from the importation
276 * @return the result of the importation
277 * @param importContext
278 * a {@link fr.ifremer.quadrige2.synchro.vo.SynchroImportContextVO} object.
279 */
280 SynchroClientImportFromFileResult importFromFile(
281 int userId,
282 File file,
283 SynchroImportContextVO importContext,
284 SynchroRejectedRowResolver dataRejectResolver,
285 ApplicationProgressionModel progressionModel,
286 int progressionModelMaxCount);
287
288 /**
289 * Compute change log (for insert and update changes only) from a file to import
290 *
291 * @param userId
292 * a int.
293 * @param dbZipFile
294 * a {@link java.io.File} object.
295 * @param importContext
296 * a {@link fr.ifremer.quadrige2.synchro.vo.SynchroImportContextVO} object.
297 * @param progressionModel
298 * @param progressionModelMaxCount
299 * a int.
300 * @return all insert and update changes from a file
301 */
302 @Transactional(propagation = Propagation.NEVER)
303 SynchroChangesVO getImportFileInsertAndUpdateChanges(
304 int userId,
305 File dbZipFile,
306 SynchroImportContextVO importContext,
307 ApplicationProgressionModel progressionModel,
308 int progressionModelMaxCount);
309
310 /**
311 * Compute change log (for delete changes only on referential) from a file to import
312 *
313 * @param userId
314 * a int.
315 * @param dbZipFile
316 * a {@link java.io.File} object.
317 * @param importContext
318 * a {@link fr.ifremer.quadrige2.synchro.vo.SynchroImportContextVO} object.
319 * @param progressionModel
320 * @param progressionModelMaxCount
321 * a int.
322 * @return all delete changes from a file
323 */
324 @Transactional(propagation = Propagation.NEVER)
325 SynchroChangesVO getImportFileReferentialDeleteChanges(
326 int userId,
327 File dbZipFile,
328 SynchroImportContextVO importContext,
329 ApplicationProgressionModel progressionModel,
330 int progressionModelMaxCount);
331
332 }