1 package fr.ifremer.quadrige2.synchro.service.data;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import com.google.common.collect.Multimap;
27 import fr.ifremer.common.synchro.service.SynchroContext;
28 import fr.ifremer.quadrige2.synchro.service.SynchroDirection;
29 import fr.ifremer.quadrige2.synchro.vo.SynchroDateOperatorVO;
30
31 import java.io.File;
32 import java.util.Date;
33 import java.util.Map;
34 import java.util.Set;
35
36
37
38
39
40
41
42 public class DataSynchroContext extends SynchroContext {
43
44 private Integer userId;
45
46 private SynchroDirection direction;
47
48 protected Date dataStartDate;
49
50 protected Date dataEndDate;
51
52
53
54
55 protected SynchroDateOperatorVO dateOperator;
56
57
58
59
60 protected boolean dirtyOnly;
61
62
63
64
65 protected boolean enableDelete = true;
66
67
68
69
70 protected boolean enableInsertOrUpdate = true;
71
72
73
74
75 protected Multimap<String, String> pkIncludes;
76
77
78
79
80 protected Set<String> programCodes;
81
82
83
84
85
86
87
88 protected boolean forceEditedRowOverride = false;
89
90
91
92
93 protected File changeLogFile;
94
95
96
97
98 protected boolean forceDuplication = false;
99
100
101
102
103 protected Map<String, Map<String, Map<String, Object>>> remapValues;
104
105
106
107
108
109
110 public DataSynchroContext() {
111 super();
112 this.userId = null;
113 this.direction = null;
114 }
115
116
117
118
119
120
121
122
123
124 public DataSynchroContext(DataSynchroContext otherBean) {
125 copy(otherBean);
126 }
127
128
129
130
131
132
133
134
135
136
137
138 public DataSynchroContext(SynchroDirection direction, Integer userId) {
139 super();
140 this.userId = userId;
141 this.direction = direction;
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156 public DataSynchroContext(SynchroContext delegate, SynchroDirection direction, Integer userId) {
157 super(delegate);
158 this.userId = userId;
159 this.direction = direction;
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 public DataSynchroContext(SynchroContext delegate, SynchroDirection direction, Integer userId, Integer sessionId) {
177 super(delegate);
178 this.userId = userId;
179 this.direction = direction;
180 }
181
182
183
184
185
186
187
188
189 public Integer getUserId() {
190 return userId;
191 }
192
193
194
195
196
197
198
199
200
201 public void setUserId(Integer userId) {
202 this.userId = userId;
203 }
204
205
206
207
208
209
210
211
212 public SynchroDirection getDirection() {
213 return direction;
214 }
215
216
217
218
219
220
221
222
223
224 public void setDirection(SynchroDirection direction) {
225 this.direction = direction;
226 }
227
228
229
230
231
232
233
234
235 public Date getDataStartDate() {
236 return dataStartDate;
237 }
238
239
240
241
242
243
244
245
246
247 public void setDataStartDate(Date dataStartDate) {
248 this.dataStartDate = dataStartDate;
249 }
250
251
252
253
254
255
256
257
258 public Date getDataEndDate() {
259 return dataEndDate;
260 }
261
262
263
264
265
266
267
268
269
270 public void setDataEndDate(Date dataEndDate) {
271 this.dataEndDate = dataEndDate;
272 }
273
274
275
276
277
278
279
280
281
282 public void setPkIncludes(Multimap<String, String> pkIncludes) {
283 this.pkIncludes = pkIncludes;
284 }
285
286
287
288
289
290
291
292
293 public Multimap<String, String> getPkIncludes() {
294 return this.pkIncludes;
295 }
296
297
298
299
300
301
302
303
304 public Set<String> getProgramCodes() {
305 return programCodes;
306 }
307
308
309
310
311
312
313
314
315
316 public void setProgramCodes(Set<String> programCodes) {
317 this.programCodes = programCodes;
318 }
319
320
321
322
323
324
325
326
327 public boolean isEnableDelete() {
328 return enableDelete;
329 }
330
331
332
333
334
335
336
337
338
339 public void setEnableDelete(boolean enableDelete) {
340 this.enableDelete = enableDelete;
341 }
342
343
344
345
346
347
348
349
350 public boolean isEnableInsertOrUpdate() {
351 return enableInsertOrUpdate;
352 }
353
354
355
356
357
358
359
360
361
362 public void setEnableInsertOrUpdate(boolean enableInsertOrUpdate) {
363 this.enableInsertOrUpdate = enableInsertOrUpdate;
364 }
365
366
367
368
369
370
371
372
373 public boolean isForceEditedRowOverride() {
374 return forceEditedRowOverride;
375 }
376
377
378
379
380
381
382
383
384
385 public void setForceEditedRowOverride(boolean forceEditedRowOverride) {
386 this.forceEditedRowOverride = forceEditedRowOverride;
387 }
388
389
390
391
392
393
394
395
396 public File getChangeLogFile() {
397 return changeLogFile;
398 }
399
400
401
402
403
404
405
406
407
408 public void setChangeLogFile(File changeLogFile) {
409 this.changeLogFile = changeLogFile;
410 }
411
412
413
414
415
416
417
418
419 public boolean isForceDuplication() {
420 return forceDuplication;
421 }
422
423
424
425
426
427
428
429
430
431 public void setForceDuplication(boolean forceDuplication) {
432 this.forceDuplication = forceDuplication;
433 }
434
435
436
437
438
439
440
441
442 public Map<String, Map<String, Map<String, Object>>> getRemapValues() {
443 return remapValues;
444 }
445
446
447
448
449
450
451
452
453
454 public void setRemapValues(Map<String, Map<String, Map<String, Object>>> remapValues) {
455 this.remapValues = remapValues;
456 }
457
458
459
460
461
462
463
464
465 public SynchroDateOperatorVO getDateOperator() {
466 return dateOperator;
467 }
468
469
470
471
472
473
474
475
476
477 public void setDateOperator(SynchroDateOperatorVO dateOperator) {
478 this.dateOperator = dateOperator;
479 }
480
481
482
483
484
485
486
487
488 public boolean isDirtyOnly() {
489 return dirtyOnly;
490 }
491
492
493
494
495
496
497
498
499
500 public void setDirtyOnly(boolean dirtyOnly) {
501 this.dirtyOnly = dirtyOnly;
502 }
503
504
505 @Override
506 public void copy(SynchroContext otherBean) {
507 super.copy(otherBean);
508
509
510 if (otherBean.getTarget() != null) {
511 setTarget(new DataSynchroDatabaseConfiguration(this, otherBean.getTarget()));
512 }
513 if (otherBean.getSource() != null) {
514 setSource(new DataSynchroDatabaseConfiguration(this, otherBean.getSource()));
515 }
516
517 if (otherBean instanceof DataSynchroContext) {
518 this.userId = ((DataSynchroContext) otherBean).userId;
519 this.direction = ((DataSynchroContext) otherBean).direction;
520 this.dataStartDate = ((DataSynchroContext) otherBean).dataStartDate;
521 this.dataEndDate = ((DataSynchroContext) otherBean).dataEndDate;
522 this.dateOperator = ((DataSynchroContext) otherBean).dateOperator;
523 this.dirtyOnly = ((DataSynchroContext) otherBean).dirtyOnly;
524 this.pkIncludes = ((DataSynchroContext) otherBean).pkIncludes;
525 this.programCodes = ((DataSynchroContext) otherBean).programCodes;
526 this.enableDelete = ((DataSynchroContext) otherBean).enableDelete;
527 this.enableInsertOrUpdate = ((DataSynchroContext) otherBean).enableInsertOrUpdate;
528 this.forceEditedRowOverride = ((DataSynchroContext) otherBean).forceEditedRowOverride;
529 this.forceDuplication = ((DataSynchroContext) otherBean).forceDuplication;
530 this.remapValues = ((DataSynchroContext) otherBean).remapValues;
531 this.changeLogFile = ((DataSynchroContext) otherBean).changeLogFile;
532 }
533 }
534
535
536 @Override
537 public String toString() {
538 StringBuilder sb = new StringBuilder(super.toString());
539 sb.append("\n direction: ").append(getDirection());
540 sb.append("\n user id: ").append(getUserId());
541 sb.append("\n enable insert: ").append(isEnableInsertOrUpdate());
542 sb.append("\n enable delete: ").append(isEnableDelete());
543 sb.append("\n override dirty")
544 .append("\n rows silently: ").append(forceEditedRowOverride);
545 sb.append("\n force duplicates: ").append(forceDuplication);
546 sb.append("\n only dirty data: ").append(dirtyOnly);
547
548 if (getDataStartDate() != null) {
549 sb.append("\n start date: ").append(getDataStartDate());
550 sb.append("\n end date: ").append(getDataEndDate());
551 if (getDateOperator() != null) {
552 sb.append("\n operator: ").append(getDateOperator());
553 }
554 }
555 if (getProgramCodes() != null) {
556 sb.append("\n programs: ").append(programCodes == null ? "all" : programCodes.toString());
557 }
558 if (getPkIncludes() != null) {
559 sb.append("\n PK includes: ").append(getPkIncludes().toString());
560 }
561
562 return sb.toString();
563 }
564
565 }