1 package fr.ifremer.quadrige3.synchro.intercept.data;
2
3 /*-
4 * #%L
5 * Quadrige3 Core :: Quadrige3 Synchro 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 com.google.common.eventbus.Subscribe;
27 import fr.ifremer.common.synchro.meta.event.LoadJoinEvent;
28 import fr.ifremer.quadrige3.synchro.meta.data.DataSynchroTables;
29 import fr.ifremer.quadrige3.synchro.service.SynchroDirection;
30
31 /**
32 * <p>
33 * SampleInterceptor class.
34 * </p>
35 *
36 */
37 public class SampleInterceptor extends AbstractDataInterceptor {
38
39 /**
40 * <p>
41 * Constructor for SampleInterceptor.
42 * </p>
43 */
44 public SampleInterceptor() {
45
46 super(DataSynchroTables.SAMPLE.name(),
47 // Enable only when importing from the server
48 SynchroDirection.IMPORT_SERVER2TEMP);
49 }
50
51 /**
52 * <p>
53 * handleJoinLoad.
54 * </p>
55 *
56 * @param e
57 * a {@link fr.ifremer.common.synchro.meta.event.LoadJoinEvent} object.
58 */
59 @Subscribe
60 public void handleJoinLoad(LoadJoinEvent e) {
61
62 if (!e.join.isValid()) {
63 return;
64 }
65
66 String targetTableName = e.join.getTargetTable().getName();
67 SynchroDirection direction = getConfig().getDirection();
68
69 // Server DB -> Temp DB
70 if (direction == SynchroDirection.IMPORT_SERVER2TEMP) {
71 // Disable join to Measurement (already processed in SurveyInterceptor)
72 if (DataSynchroTables.MEASUREMENT.name().equalsIgnoreCase(targetTableName)) {
73 e.join.setIsValid(false);
74 }
75
76 // Disable join to TaxonMeasurement (already processed in SurveyInterceptor)
77 if (DataSynchroTables.TAXON_MEASUREMENT.name().equalsIgnoreCase(targetTableName)) {
78 e.join.setIsValid(false);
79 }
80
81 // Disable join to TaxonMeasurement (already processed in SurveyInterceptor)
82 if (DataSynchroTables.MEASUREMENT_FILE.name().equalsIgnoreCase(targetTableName)) {
83 e.join.setIsValid(false);
84 }
85
86 // Disable join to Photo (already processed in SurveyInterceptor)
87 if (DataSynchroTables.PHOTO.name().equalsIgnoreCase(targetTableName)) {
88 e.join.setIsValid(false);
89 }
90 }
91 }
92
93 /* -- Internal methods -- */
94
95 }