View Javadoc
1   package fr.ifremer.tutti.service.referential;
2   
3   /*
4    * #%L
5    * Tutti :: Service
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.collect.ImmutableSet;
26  import fr.ifremer.adagio.core.service.technical.synchro.ReferentialSynchroContext;
27  import fr.ifremer.adagio.core.service.technical.synchro.ReferentialSynchroResult;
28  import fr.ifremer.adagio.core.service.technical.synchro.ReferentialSynchroService;
29  import fr.ifremer.tutti.persistence.service.TuttiPersistenceServiceLocator;
30  import fr.ifremer.tutti.service.AbstractTuttiService;
31  import fr.ifremer.tutti.service.TuttiServiceContext;
32  
33  import java.io.File;
34  import java.util.Set;
35  
36  /**
37   * @author Tony Chemit - chemit@codelutin.com
38   * @since 1.0
39   */
40  public class TuttiReferentialSynchronizeService extends AbstractTuttiService {
41  
42      protected ReferentialSynchroService synchroService;
43  
44      protected static Set<String> TABLE_NAMES = ImmutableSet.<String>builder().add(
45              "STATUS",
46              "QUALITY_FLAG",
47  
48              // PMFM
49              "UNIT",
50              "AGGREGATION_LEVEL",
51              "PARAMETER_GROUP",
52              "QUALITATIVE_VALUE",
53              "PARAMETER",
54              "MATRIX",
55              "FRACTION",
56              "FRACTION2MATRIX",
57              "METHOD",
58              "PMFM",
59              "PMFM2QUALITATIVE_VALUE",
60  
61              // GEAR
62              "GEAR_CLASSIFICATION",
63              "GEAR_CLASSIFICATION_ASSOCIATIO",
64              "GEAR",
65              "GEAR_ASSOCIATION",
66  
67              // LOCATION
68              "LOCATION_CLASSIFICATION",
69              "LOCATION_LEVEL",
70              "LOCATION_ASSOCIATION",
71              "LOCATION",
72              "LOCATION_HIERARCHY",
73              "LOCATION_HIERARCHY_EXCEPTION",
74  
75              // TAXON
76              "TAXONOMIC_LEVEL",
77              "REFERENCE_TAXON",
78              "TAXON_NAME",
79              "TAXON_INFORMATION",
80              "TAXON_INFORMATION_HISTORY",
81              "VIRTUAL_COMPONENT",
82              "TAXON_NAME_HISTORY",
83              "REFERENCE_DOCUMENT",
84              "AUTHOR",
85              "CITATION",
86  
87              // TAXON GROUP
88              "TAXON_GROUP_TYPE",
89              "TAXON_GROUP",
90              "TAXON_GROUP_HISTORICAL_RECORD",
91              "TAXON_GROUP_INFORMATION",
92  
93              // TRANSCRIBING
94              "TRANSCRIBING_SIDE",
95              "TRANSCRIBING_SYSTEM",
96              "TRANSCRIBING_ITEM_TYPE",
97              "TRANSCRIBING_ITEM",
98  
99              // CONVERSION
100             "ROUND_WEIGHT_CONVERSION",
101             "WEIGHT_LENGTH_CONVERSION",
102             "UNIT_CONVERSION",
103 
104             // VESSEL
105             "VESSEL_TYPE",
106             "VESSEL_REGISTRATION_PERIOD",
107             "VESSEL_FEATURES",
108             "VESSEL",
109 
110             // PERSON
111             "USER_PROFIL",
112             "DEPARTMENT",
113             "PERSON",
114             "PERSON2USER_PROFIL",
115 
116             // VESSEL_PERSON_ROLE
117             "VESSEL_PERSON_ROLE",
118             "VESSEL_PERSON",
119 
120             // ORDER
121             "ORDER_ITEM",
122 
123             // PROGRAM (since 3.3.5)
124             "PROGRAM",
125             "PROGRAM2LOCATION",
126             "PROGRAM2LOCATION_CLASSIF",
127 
128             // STRATEGY (since 3.5)
129             "ACQUISITION_LEVEL",
130             "PROGRAM_PRIVILEGE",
131             "PROGRAM2DEPARTMENT",
132             "PROGRAM2PERSON_EXCEPTION",
133             "PROGRAM2PERSON",
134             "STRATEGY",
135             "STRATEGY2MANAGER_PERSON",
136             "PMFM_APPLIED_STRATEGY",
137             "APPLIED_STRATEGY",
138             "PMFM_STRATEGY",
139             "REFERENCE_TAXON_STRATEGY",
140             "STRATEGY2GEAR",
141             // FIXME-tchemit-2014-04-19 This table fails to update
142             //"APPLIED_PERIOD",
143 
144             // OTHER
145             "PRECISION_TYPE",
146             "NUMERICAL_PRECISION",
147             "PHOTO_TYPE",
148             "OBJECT_TYPE",
149             "ORDER_TYPE",
150             "ANALYSIS_INSTRUMENT"
151     ).build();
152 
153     @Override
154     public void setServiceContext(TuttiServiceContext context) {
155         super.setServiceContext(context);
156         synchroService = TuttiPersistenceServiceLocator.getReferentialSynchroService();
157     }
158 
159     public ReferentialSynchroContext createSynchroContext(File dbDirectory) {
160         return ReferentialSynchroContext.newContext(
161                 TABLE_NAMES,
162                 dbDirectory,
163                 new ReferentialSynchroResult()
164         );
165     }
166 
167     public void prepare(ReferentialSynchroContext synchroContext) {
168         synchroService.prepare(synchroContext);
169     }
170 
171     public void synchronize(ReferentialSynchroContext synchroContext) {
172         synchroService.synchronize(synchroContext);
173     }
174 
175 
176 }