30 |
30 |
import eu.etaxonomy.cdm.io.common.Source;
|
31 |
31 |
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32 |
32 |
import eu.etaxonomy.cdm.model.common.Language;
|
|
33 |
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
33 |
34 |
import eu.etaxonomy.cdm.model.description.Feature;
|
34 |
35 |
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
35 |
36 |
import eu.etaxonomy.cdm.model.description.TextData;
|
... | ... | |
66 |
67 |
return result;
|
67 |
68 |
}
|
68 |
69 |
|
|
70 |
private TermVocabulary<Feature> getFeatureVocabulary(){
|
|
71 |
try {
|
|
72 |
//TODO work around until service method works
|
|
73 |
TermVocabulary<Feature> featureVocabulary = BerlinModelTransformer.factCategory2Feature(1).getVocabulary();
|
|
74 |
//TermVocabulary<Feature> vocabulary = getTermService().getVocabulary(vocabularyUuid);
|
|
75 |
return featureVocabulary;
|
|
76 |
} catch (UnknownCdmTypeException e) {
|
|
77 |
logger.error("Feature vocabulary not available. New vocabulary created");
|
|
78 |
return new TermVocabulary<Feature>() ;
|
|
79 |
}
|
|
80 |
}
|
|
81 |
|
69 |
82 |
private MapWrapper<Feature> invokeFactCategories(BerlinModelImportConfigurator bmiConfig){
|
70 |
83 |
|
71 |
84 |
// Map<Integer, Feature> featureMap = new HashMap<Integer, Feature>();
|
... | ... | |
82 |
95 |
" WHERE (1=1)";
|
83 |
96 |
ResultSet rs = source.getResultSet(strQuery) ;
|
84 |
97 |
|
|
98 |
|
|
99 |
TermVocabulary<Feature> featureVocabulary = getFeatureVocabulary();
|
85 |
100 |
int i = 0;
|
86 |
101 |
//for each reference
|
87 |
102 |
while (rs.next()){
|
... | ... | |
91 |
106 |
int factCategoryId = rs.getInt("factCategoryId");
|
92 |
107 |
String factCategory = rs.getString("factCategory");
|
93 |
108 |
|
|
109 |
|
94 |
110 |
Feature feature;
|
95 |
111 |
try {
|
96 |
112 |
feature = BerlinModelTransformer.factCategory2Feature(factCategoryId);
|
97 |
113 |
} catch (UnknownCdmTypeException e) {
|
98 |
114 |
logger.warn("New Feature (FactCategoryId: " + factCategoryId + ")");
|
99 |
115 |
feature = Feature.NewInstance(factCategory, factCategory, null);
|
|
116 |
feature.setVocabulary(featureVocabulary);
|
100 |
117 |
feature.setSupportsTextData(true);
|
101 |
118 |
//TODO
|
102 |
119 |
// MaxFactNumber int Checked
|
... | ... | |
127 |
144 |
@Override
|
128 |
145 |
protected boolean doInvoke(IImportConfigurator config,
|
129 |
146 |
Map<String, MapWrapper<? extends CdmBase>> stores){
|
130 |
|
|
|
147 |
boolean result = true;
|
|
148 |
|
131 |
149 |
MapWrapper<TaxonBase> taxonMap = (MapWrapper<TaxonBase>)stores.get(ICdmIO.TAXON_STORE);
|
132 |
150 |
MapWrapper<ReferenceBase> referenceMap = (MapWrapper<ReferenceBase>)stores.get(ICdmIO.REFERENCE_STORE);
|
133 |
151 |
MapWrapper<ReferenceBase> nomRefMap = (MapWrapper<ReferenceBase>)stores.get(ICdmIO.NOMREF_STORE);
|
... | ... | |
158 |
176 |
int i = 0;
|
159 |
177 |
//for each reference
|
160 |
178 |
while (rs.next()){
|
161 |
|
|
162 |
|
if ((i++ % modCount) == 0){ logger.info("Facts handled: " + (i-1));}
|
163 |
|
|
164 |
|
int taxonId = rs.getInt("taxonId");
|
165 |
|
int factId = rs.getInt("factId");
|
166 |
|
Integer factRefFk = rs.getInt("factRefFk");
|
167 |
|
String details = rs.getString("Details");
|
168 |
|
// int ptDesignationRefFk = rs.getInt("PTDesignationRefFk");
|
169 |
|
// String ptDesignation details = rs.getInt("PTDesignationRefDetailFk");
|
170 |
|
Integer categoryFk = rs.getInt("factCategoryFk");
|
171 |
|
String fact = CdmUtils.Nz(rs.getString("Fact"));
|
172 |
|
String notes = CdmUtils.Nz(rs.getString("notes"));
|
173 |
|
|
174 |
|
TaxonBase taxonBase = taxonMap.get(taxonId);
|
175 |
|
Feature feature;
|
176 |
|
if (categoryFk != null){
|
177 |
|
feature = featureMap.get(categoryFk);
|
178 |
|
}else{
|
179 |
|
feature = null;
|
180 |
|
}
|
181 |
|
|
182 |
|
if (taxonBase != null){
|
183 |
|
Taxon taxon;
|
184 |
|
if ( taxonBase instanceof Taxon ) {
|
185 |
|
taxon = (Taxon) taxonBase;
|
186 |
|
}else{
|
187 |
|
logger.warn("TaxonBase " + taxonId + " for Fact " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
|
188 |
|
continue;
|
189 |
|
}
|
|
179 |
try{
|
|
180 |
if ((i++ % modCount) == 0){ logger.info("Facts handled: " + (i-1));}
|
190 |
181 |
|
191 |
|
TaxonDescription taxonDescription;
|
192 |
|
Set<TaxonDescription> descriptionSet= taxon.getDescriptions();
|
193 |
|
if (descriptionSet.size() > 0) {
|
194 |
|
taxonDescription = descriptionSet.iterator().next();
|
195 |
|
}else{
|
196 |
|
taxonDescription = TaxonDescription.NewInstance();
|
197 |
|
taxon.addDescription(taxonDescription);
|
198 |
|
}
|
|
182 |
//Map<String, Object> valueMap = getValueMap(rs);
|
199 |
183 |
|
200 |
|
//textData
|
201 |
|
TextData textData = TextData.NewInstance();
|
202 |
|
//TODO textData.putText(fact, bmiConfig.getFactLanguage()); //doesn't work because bmiConfig.getFactLanguage() is not not a persistent Language Object
|
203 |
|
//throws in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language
|
|
184 |
int factId = rs.getInt("factId");
|
204 |
185 |
|
205 |
|
//for diptera database
|
206 |
|
if (categoryFk == 99 && notes.contains("<OriginalName>")){
|
207 |
|
notes = notes.replaceAll("<OriginalName>", "");
|
208 |
|
notes = notes.replaceAll("</OriginalName>", "");
|
209 |
|
fact = notes + ": " + fact ;
|
210 |
|
}
|
211 |
|
textData.putText(fact, Language.DEFAULT());
|
212 |
|
textData.setType(feature);
|
213 |
186 |
|
214 |
|
//
|
215 |
|
ReferenceBase citation = null;
|
216 |
|
if (factRefFk != null){
|
217 |
|
citation = referenceMap.get(factRefFk);
|
218 |
|
}
|
219 |
|
if (citation == null){
|
220 |
|
citation = nomRefMap.get(factRefFk);
|
|
187 |
Object taxonIdObj = rs.getObject("taxonId");
|
|
188 |
int taxonId = rs.getInt("taxonId");
|
|
189 |
Object factRefFkObj = rs.getObject("factRefFk");
|
|
190 |
int factRefFk = rs.getInt("factRefFk");
|
|
191 |
Object categoryFkObj = rs.getObject("factCategoryFk");
|
|
192 |
Integer categoryFk = rs.getInt("factCategoryFk");
|
|
193 |
|
|
194 |
String details = rs.getString("Details");
|
|
195 |
// int ptDesignationRefFk = rs.getInt("PTDesignationRefFk");
|
|
196 |
// String ptDesignation details = rs.getInt("PTDesignationRefDetailFk");
|
|
197 |
String fact = CdmUtils.Nz(rs.getString("Fact"));
|
|
198 |
String notes = CdmUtils.Nz(rs.getString("notes"));
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
TaxonBase taxonBase;
|
|
203 |
if (taxonIdObj != null){
|
|
204 |
taxonBase = taxonMap.get(taxonId);
|
|
205 |
}else{
|
|
206 |
taxonBase = null;
|
221 |
207 |
}
|
222 |
|
if (citation == null && factRefFk != 0){
|
223 |
|
logger.warn("Citation not found in referenceMap: " + CdmUtils.Nz(factRefFk));
|
|
208 |
Feature feature;
|
|
209 |
if (categoryFkObj != null){
|
|
210 |
feature = featureMap.get(categoryFk);
|
|
211 |
}else{
|
|
212 |
feature = null;
|
224 |
213 |
}
|
225 |
|
|
226 |
214 |
|
227 |
|
textData.setCitation(citation);
|
228 |
|
textData.setCitationMicroReference(details);
|
229 |
|
taxonDescription.addElement(textData);
|
230 |
|
|
231 |
|
if (categoryFk == FACT_DESCRIPTION){
|
232 |
|
//;
|
233 |
|
}else if (categoryFk == FACT_OBSERVATION){
|
234 |
|
//;
|
235 |
|
}else if (categoryFk == FACT_DISTRIBUTION_EM){
|
|
215 |
if (taxonBase != null){
|
|
216 |
Taxon taxon;
|
|
217 |
if ( taxonBase instanceof Taxon ) {
|
|
218 |
taxon = (Taxon) taxonBase;
|
|
219 |
}else{
|
|
220 |
logger.warn("TaxonBase " + (taxonIdObj==null?"(null)":taxonIdObj) + " for Fact " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
|
|
221 |
continue;
|
|
222 |
}
|
|
223 |
|
|
224 |
TaxonDescription taxonDescription;
|
|
225 |
Set<TaxonDescription> descriptionSet= taxon.getDescriptions();
|
|
226 |
if (descriptionSet.size() > 0) {
|
|
227 |
taxonDescription = descriptionSet.iterator().next();
|
|
228 |
}else{
|
|
229 |
taxonDescription = TaxonDescription.NewInstance();
|
|
230 |
taxon.addDescription(taxonDescription);
|
|
231 |
}
|
|
232 |
|
|
233 |
//textData
|
|
234 |
TextData textData = TextData.NewInstance();
|
|
235 |
//TODO textData.putText(fact, bmiConfig.getFactLanguage()); //doesn't work because bmiConfig.getFactLanguage() is not not a persistent Language Object
|
|
236 |
//throws in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: eu.etaxonomy.cdm.model.common.Language
|
|
237 |
|
|
238 |
//for diptera database
|
|
239 |
if (categoryFk == 99 && notes.contains("<OriginalName>")){
|
|
240 |
notes = notes.replaceAll("<OriginalName>", "");
|
|
241 |
notes = notes.replaceAll("</OriginalName>", "");
|
|
242 |
fact = notes + ": " + fact ;
|
|
243 |
}
|
|
244 |
textData.putText(fact, Language.DEFAULT());
|
|
245 |
textData.setType(feature);
|
|
246 |
|
236 |
247 |
//
|
237 |
|
}else {
|
|
248 |
ReferenceBase citation;
|
|
249 |
if (factRefFkObj != null){
|
|
250 |
citation = referenceMap.get(factRefFk);
|
|
251 |
if (citation == null){
|
|
252 |
citation = nomRefMap.get(factRefFk);
|
|
253 |
}
|
|
254 |
if (citation == null && (factRefFk != 0)){
|
|
255 |
logger.warn("Citation not found in referenceMap: " + factRefFk);
|
|
256 |
}
|
|
257 |
}else{
|
|
258 |
citation = null;
|
|
259 |
}
|
|
260 |
|
|
261 |
|
|
262 |
textData.setCitation(citation);
|
|
263 |
textData.setCitationMicroReference(details);
|
|
264 |
taxonDescription.addElement(textData);
|
|
265 |
|
|
266 |
|
|
267 |
// if (categoryFkObj == FACT_DESCRIPTION){
|
|
268 |
// //;
|
|
269 |
// }else if (categoryFkObj == FACT_OBSERVATION){
|
|
270 |
// //;
|
|
271 |
// }else if (categoryFkObj == FACT_DISTRIBUTION_EM){
|
|
272 |
// //
|
|
273 |
// }else {
|
|
274 |
// //TODO
|
|
275 |
// //logger.warn("FactCategory " + categoryFk + " not yet implemented");
|
|
276 |
// }
|
|
277 |
|
238 |
278 |
//TODO
|
239 |
|
//logger.warn("FactCategory " + categoryFk + " not yet implemented");
|
|
279 |
//References
|
|
280 |
//etc.
|
|
281 |
|
|
282 |
//TODO created, notes
|
|
283 |
//doIdCreatedUpdatedNotes(bmiConfig, textData, rs, factId);
|
|
284 |
|
|
285 |
|
|
286 |
taxonStore.add(taxon);
|
|
287 |
}else{
|
|
288 |
//TODO
|
|
289 |
logger.warn("Taxon for Fact " + factId + " does not exist in store");
|
240 |
290 |
}
|
241 |
|
|
242 |
|
//TODO
|
243 |
|
//References
|
244 |
|
//etc.
|
245 |
|
|
246 |
|
//TODO created, notes
|
247 |
|
//doIdCreatedUpdatedNotes(bmiConfig, textData, rs, factId);
|
248 |
|
|
249 |
|
|
250 |
|
taxonStore.add(taxon);
|
251 |
|
}else{
|
252 |
|
//TODO
|
253 |
|
logger.warn("Taxon for Fact " + factId + " does not exist in store");
|
|
291 |
} catch (RuntimeException re){
|
|
292 |
logger.error("A runtime exception occurred during the facts import");
|
|
293 |
result = false;
|
|
294 |
throw re;
|
254 |
295 |
}
|
255 |
296 |
//put
|
256 |
297 |
}
|
... | ... | |
259 |
300 |
getTaxonService().saveTaxonAll(taxonStore);
|
260 |
301 |
|
261 |
302 |
logger.info("end makeFacts ...");
|
262 |
|
return true;
|
|
303 |
return result;
|
263 |
304 |
} catch (SQLException e) {
|
264 |
305 |
logger.error("SQLException:" + e);
|
265 |
306 |
return false;
|
bug in berlin model facts and deproxy bug in TaxonX