1 package fr.ifremer.quadrige2.synchro.service.referential;
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.base.Joiner;
27 import com.google.common.collect.Multimap;
28 import fr.ifremer.common.synchro.config.SynchroConfiguration;
29 import fr.ifremer.common.synchro.service.SynchroContext;
30 import fr.ifremer.quadrige2.synchro.service.SynchroDirection;
31
32 import java.io.File;
33 import java.util.Set;
34
35
36
37
38
39
40
41 public class ReferentialSynchroContext extends SynchroContext {
42
43 private Integer userId;
44
45 private SynchroDirection direction;
46
47
48
49
50 protected boolean enableDelete = true;
51
52
53
54
55 protected boolean enableInsertOrUpdate = true;
56
57
58
59
60 protected Set<String> statusCodeIncludes;
61
62
63
64
65 protected File changeLogFile;
66
67
68
69
70 protected Set<String> programCodes;
71
72
73
74
75 protected Multimap<String, String> pkIncludes;
76
77
78
79
80
81
82 protected Set<String> tableNamesForced;
83
84
85
86
87
88
89 public ReferentialSynchroContext() {
90 super();
91 }
92
93
94
95
96
97
98
99
100
101
102
103 public ReferentialSynchroContext(SynchroDirection direction, Integer userId) {
104 super();
105 this.userId = userId;
106 this.direction = direction;
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121 public ReferentialSynchroContext(SynchroContext delegate, SynchroDirection direction, Integer userId) {
122 super(delegate);
123 this.direction = direction;
124 this.userId = userId;
125 }
126
127
128
129
130
131
132
133
134 public boolean isEnableDelete() {
135 return enableDelete;
136 }
137
138
139
140
141
142
143
144
145
146 public void setEnableDelete(boolean enableDelete) {
147 this.enableDelete = enableDelete;
148 }
149
150
151
152
153
154
155
156
157 public boolean isEnableInsertOrUpdate() {
158 return enableInsertOrUpdate;
159 }
160
161
162
163
164
165
166
167
168
169 public void setEnableInsertOrUpdate(boolean enableInsertOrUpdate) {
170 this.enableInsertOrUpdate = enableInsertOrUpdate;
171 }
172
173
174
175
176
177
178
179
180 public Set<String> getStatusCodeIncludes() {
181 return statusCodeIncludes;
182 }
183
184
185
186
187
188
189
190
191
192 public void setStatusCodeIncludes(Set<String> statusCodeIncludes) {
193 this.statusCodeIncludes = statusCodeIncludes;
194 }
195
196
197
198
199
200
201
202
203 public Integer getUserId() {
204 return userId;
205 }
206
207
208
209
210
211
212
213
214
215 public void setUserId(Integer userId) {
216 this.userId = userId;
217 }
218
219
220
221
222
223
224
225
226 public SynchroDirection getDirection() {
227 return direction;
228 }
229
230
231
232
233
234
235
236
237
238 public void setDirection(SynchroDirection direction) {
239 this.direction = direction;
240 }
241
242
243
244
245
246
247
248
249 public Multimap<String, String> getPkIncludes() {
250 return pkIncludes;
251 }
252
253
254
255
256
257
258
259
260
261 public void setPkIncludes(Multimap<String, String> pkIncludes) {
262 this.pkIncludes = pkIncludes;
263 }
264
265
266
267
268
269
270
271
272 public File getChangeLogFile() {
273 return changeLogFile;
274 }
275
276
277
278
279
280
281
282
283
284 public void setChangeLogFile(File changeLogFile) {
285 this.changeLogFile = changeLogFile;
286 }
287
288
289
290
291
292
293
294
295 public Set<String> getProgramCodes() {
296 return programCodes;
297 }
298
299
300
301
302
303
304
305
306
307 public void setProgramCodes(Set<String> programCodes) {
308 this.programCodes = programCodes;
309 }
310
311
312
313
314
315
316
317
318
319 public void setTableNamesForced(Set<String> tableNamesForced) {
320 this.tableNamesForced = tableNamesForced;
321 }
322
323
324
325
326
327
328
329
330 public Set<String> getTableNamesForced() {
331 return tableNamesForced;
332 }
333
334
335 @Override
336 public void copy(SynchroContext otherBean) {
337 super.copy(otherBean);
338
339 SynchroConfiguration config = SynchroConfiguration.getInstance();
340
341 if (otherBean.getTarget() != null) {
342 setTarget(new ReferentialSynchroDatabaseConfiguration(this, otherBean.getTarget()));
343 }
344 if (otherBean.getSource() != null) {
345 setSource(new ReferentialSynchroDatabaseConfiguration(this, otherBean.getSource()));
346 }
347
348 if (otherBean instanceof ReferentialSynchroContext) {
349 this.direction = ((ReferentialSynchroContext) otherBean).direction;
350 this.enableDelete = ((ReferentialSynchroContext) otherBean).enableDelete;
351 this.enableInsertOrUpdate = ((ReferentialSynchroContext) otherBean).enableInsertOrUpdate;
352 this.statusCodeIncludes = ((ReferentialSynchroContext) otherBean).statusCodeIncludes;
353 this.userId = ((ReferentialSynchroContext) otherBean).userId;
354 this.pkIncludes = ((ReferentialSynchroContext) otherBean).pkIncludes;
355 this.changeLogFile = ((ReferentialSynchroContext) otherBean).changeLogFile;
356 this.programCodes = ((ReferentialSynchroContext) otherBean).programCodes;
357 this.tableNamesForced = ((ReferentialSynchroContext) otherBean).tableNamesForced;
358 }
359 }
360
361
362 @Override
363 public String toString() {
364 return new StringBuilder()
365 .append(super.toString())
366 .append("\n direction: ").append(direction)
367 .append("\n enable update/insert: ").append(isEnableInsertOrUpdate())
368 .append("\n enable delete: ").append(isEnableDelete())
369 .append("\n programs: ").append(programCodes == null ? "all" : programCodes.toString())
370 .append("\n change log file: ").append(changeLogFile == null ? "disable" : changeLogFile.getPath())
371 .append("\n status codes: ").append(statusCodeIncludes == null ? "all" : Joiner.on('\'').join(statusCodeIncludes))
372 .append("\n user: ").append(getUserId())
373 .append("\n pkIncludes: ").append(pkIncludes == null ? "all" : pkIncludes.toString())
374 .toString();
375 }
376
377 }