1 package fr.ifremer.quadrige3.synchro.service.client; 2 3 /*- 4 * #%L 5 * Quadrige3 Core :: Quadrige3 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.quadrige3.core.ProgressionCoreModel; 27 import fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientExportResult; 28 import fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientExportToFileResult; 29 import fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientImportFromFileResult; 30 import fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientImportResult; 31 import fr.ifremer.quadrige3.synchro.vo.SynchroChangesVO; 32 import fr.ifremer.quadrige3.synchro.vo.SynchroDateOperatorVO; 33 import fr.ifremer.quadrige3.synchro.vo.SynchroImportContextVO; 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.quadrige3.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 ProgressionCoreModel progressionModel, 77 int progressionModelMaxCount); 78 79 /** 80 * Imports referential/data from server to local database. 81 * <p/> 82 * WARNING : Direct connection to Quadrige3 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 ProgressionCoreModel 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 programCodes 126 * a {@link Set} object. 127 * @param enablePhotos 128 * @param progressionModel 129 * a not null progression model 130 * @param progressionModelMaxCount 131 * the maximum increment that should be used from the importation 132 * @return export result object 133 */ 134 SynchroClientExportResult exportDataToTempDb(int userId, Set<String> programCodes, boolean enablePhotos, ProgressionCoreModel progressionModel, 135 int progressionModelMaxCount); 136 137 /** 138 * Creates a temporary database in the user export directory, exports national referential (prog/strat) to temp DB 139 * and returns a result 140 * object 141 * 142 * @param userId 143 * the user to synchronize 144 * @param programCodes 145 * a {@link Set} object. 146 * @param progressionModel 147 * a not null progression model 148 * @param progressionModelMaxCount 149 * the maximum increment that should be used from the importation 150 * @return export result object 151 */ 152 SynchroClientExportResult exportNationalProgramsToTempDb(int userId, 153 Set<String> programCodes, 154 ProgressionCoreModel progressionModel, 155 int progressionModelMaxCount); 156 157 /** 158 * Creates a temporary database, exports local data to temp DB, then export from temp to Quadrige, and returns an 159 * encapsulating result object 160 * 161 * @param userId 162 * the user to synchronize 163 * @param programCodes 164 * a {@link Set} object. 165 * @param dataRejectResolver 166 * resolver that gives the strategy to resolve rejected rows 167 * @param progressionModel 168 * a not null progression model 169 * @param progressionModelMaxCount 170 * the maximum increment that should be used from the importation 171 * @return a {@link fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientExportResult} object. 172 */ 173 SynchroClientExportResult exportToServerDatabase(int userId, Set<String> programCodes, SynchroRejectedRowResolver dataRejectResolver, 174 ProgressionCoreModel progressionModel, 175 int progressionModelMaxCount); 176 177 /** 178 * Finishes export: display rejects, deals with rejected rows re-import reverted Pks 179 * 180 * @param userId 181 * the user whose export synchronization must be finalized 182 * @param exportResult 183 * export result (coming from a direct synchroniation or a direct one) 184 * @param rejectResolver 185 * resolver that gives the strategy to resolve rejected rows 186 * @param synchroFailed 187 * if true, this method will do nothing more than displaying reject error messages (if any rejects) using 188 * the reject resolver 189 * @param runPkRevert 190 * if true, at the end of the method Pks to be reverted will be re-imported 191 * @return true if one (or more) reject messages have been displayed. if <code>true</code>, the caller method do not 192 * need to display a error again. 193 */ 194 boolean finishExportData(int userId, SynchroClientExportResult exportResult, 195 SynchroRejectedRowResolver rejectResolver, boolean synchroFailed, boolean runPkRevert); 196 197 /** 198 * Export data into a file, and returns an encapsulating result object 199 * 200 * @param userId 201 * the user to synchronize 202 * @param file 203 * Path to the file to create (should not exists). 204 * @param programCodes 205 * programs to export that gives the strategy to resolve rejected rows 206 * @param dirtyOnly 207 * a boolean. 208 * @param dateOperator 209 * a {@link SynchroDateOperatorVO} object. 210 * @param startDate 211 * a {@link Date} object. 212 * @param endDate 213 * a {@link Date} object. 214 * @param progressionModel 215 * a not null progression model 216 * @param progressionModelMaxCount 217 * the maximum increment that should be used from the importation @return 218 * @return a {@link fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientExportToFileResult} object. 219 */ 220 SynchroClientExportToFileResult exportToFile(int userId, File file, Set<String> programCodes, boolean dirtyOnly, 221 SynchroDateOperatorVO dateOperator, Date startDate, Date endDate, 222 ProgressionCoreModel progressionModel, int progressionModelMaxCount); 223 224 /** 225 * Export data into a file, and returns an encapsulating result object 226 * 227 * @param userId 228 * the user to synchronize 229 * @param file 230 * Path to the file to create (should not exists). 231 * @param programCodes 232 * programs to export that gives the strategy to resolve rejected rows 233 * @param dirtyOnly 234 * a boolean. 235 * @param includeReferential 236 * a boolean. 237 * @param dateOperator 238 * a {@link SynchroDateOperatorVO} object. 239 * @param startDate 240 * a {@link Date} object. 241 * @param endDate 242 * a {@link Date} object. 243 * @param progressionModel 244 * a not null progression model 245 * @param progressionModelMaxCount 246 * the maximum increment that should be used from the importation @return 247 * @return a {@link fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientExportToFileResult} object. 248 */ 249 SynchroClientExportToFileResult exportToFile(int userId, File file, Set<String> programCodes, boolean dirtyOnly, boolean includeReferential, 250 SynchroDateOperatorVO dateOperator, Date startDate, Date endDate, 251 ProgressionCoreModel progressionModel, int progressionModelMaxCount); 252 253 /** 254 * Export local referential into a file, and returns an encapsulating result object 255 * 256 * @param userId 257 * the user to synchronize 258 * @param file 259 * Path to the file to create (should not exists). 260 * @param programCodes 261 * programs to export that gives the strategy to resolve rejected rows 262 * @param progressionModel 263 * a not null progression model 264 * @param progressionModelMaxCount 265 * the maximum increment that should be used from the importation 266 * @return a {@link fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientExportToFileResult} object. 267 */ 268 @Deprecated 269 SynchroClientExportToFileResult exportReferentialToFile(int userId, 270 File file, 271 Set<String> programCodes, 272 ProgressionCoreModel progressionModel, 273 int progressionModelMaxCount); 274 275 /** 276 * Export all referential (local and national) into a file, and returns an encapsulating result object 277 * 278 * @param userId 279 * the user to synchronize 280 * @param file 281 * Path to the file to create (should not exists). 282 * @param progressionModel 283 * a not null progression model 284 * @param progressionModelMaxCount 285 * the maximum increment that should be used from the importation 286 * @return a {@link fr.ifremer.quadrige3.synchro.service.client.vo.SynchroClientExportToFileResult} object. 287 */ 288 SynchroClientExportToFileResult exportAllReferentialToFile(int userId, 289 File file, 290 ProgressionCoreModel progressionModel, 291 int progressionModelMaxCount); 292 293 /** 294 * Imports referential/data from a DB file. Will use a basic referential resolver, that remap all 295 * duplicated entries. 296 * 297 * @param userId 298 * the connected user 299 * @param file 300 * the DB file to import 301 * @param importContext 302 * a {@link SynchroImportContextVO} object. 303 * @param dataRejectResolver 304 * resolver that gives the strategy to resolve rejected rows, on data 305 * @param progressionModel 306 * a not null progression model 307 * @param progressionModelMaxCount 308 * the maximum increment that should be used from the importation 309 * @return the result of the importation 310 */ 311 SynchroClientImportFromFileResult importFromFile( 312 int userId, 313 File file, 314 SynchroImportContextVO importContext, 315 SynchroRejectedRowResolver dataRejectResolver, 316 ProgressionCoreModel progressionModel, 317 int progressionModelMaxCount); 318 319 /** 320 * Compute change log (for insert and update changes only) from a file to import 321 * 322 * @param userId 323 * a int. 324 * @param dbZipFile 325 * a {@link File} object. 326 * @param importContext 327 * a {@link SynchroImportContextVO} object. 328 * @param progressionModel progression model 329 * @param progressionModelMaxCount 330 * a int. 331 * @return all insert and update changes from a file 332 */ 333 @Transactional(propagation = Propagation.NEVER) 334 SynchroChangesVO getImportFileInsertAndUpdateChanges( 335 int userId, 336 File dbZipFile, 337 SynchroImportContextVO importContext, 338 ProgressionCoreModel progressionModel, 339 int progressionModelMaxCount); 340 341 /** 342 * Compute change log (for delete changes only on referential) from a file to import 343 * 344 * @param userId 345 * a int. 346 * @param dbZipFile 347 * a {@link File} object. 348 * @param importContext 349 * a {@link SynchroImportContextVO} object. 350 * @param progressionModel progression model 351 * @param progressionModelMaxCount 352 * a int. 353 * @return all delete changes from a file 354 */ 355 @Transactional(propagation = Propagation.NEVER) 356 SynchroChangesVO getImportFileReferentialDeleteChanges( 357 int userId, 358 File dbZipFile, 359 SynchroImportContextVO importContext, 360 ProgressionCoreModel progressionModel, 361 int progressionModelMaxCount); 362 363 }