Revision 892efc69
Added by Andreas Kohlbecker almost 14 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiSourceExport.java | ||
---|---|---|
23 | 23 |
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper; |
24 | 24 |
import eu.etaxonomy.cdm.io.common.Source; |
25 | 25 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES; |
26 |
import eu.etaxonomy.cdm.io.erms.ErmsTransformer; |
|
27 | 26 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
28 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
29 | 27 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
30 |
import eu.etaxonomy.cdm.model.common.Extension; |
|
31 | 28 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
32 | 29 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
33 | 30 |
|
... | ... | |
85 | 82 |
// PESI: Clear the database table Source. |
86 | 83 |
doDelete(state); |
87 | 84 |
|
85 |
// Create the database table that hosts state information |
|
86 |
state.createStateTables(); |
|
87 |
|
|
88 |
// CDM: Get the number of all available references. |
|
89 |
// int maxCount = getReferenceService().count(null); |
|
90 |
// logger.error("Total amount of " + maxCount + " " + pluralString + " will be exported."); |
|
91 |
|
|
88 | 92 |
// Get specific mappings: (CDM) Reference -> (PESI) Source |
89 | 93 |
PesiExportMapping mapping = getMapping(); |
90 | 94 |
|
... | ... | |
92 | 96 |
mapping.initialize(state); |
93 | 97 |
|
94 | 98 |
// PESI: Create the Sources |
99 |
// TODO: Store CDM2PESI identifier pairs for later use in other export classes - PesiExportState |
|
95 | 100 |
int count = 0; |
96 | 101 |
int pastCount = 0; |
97 | 102 |
TransactionStatus txStatus = null; |
... | ... | |
172 | 177 |
*/ |
173 | 178 |
@SuppressWarnings("unused") |
174 | 179 |
private static Integer getIMIS_Id(ReferenceBase<?> reference) { |
175 |
Integer result = null; |
|
176 |
if (reference != null) { |
|
177 |
Set<Extension> extensions = reference.getExtensions(); |
|
178 |
for (Extension extension : extensions) { |
|
179 |
try { |
|
180 |
if (extension.getType().getUuid().equals(ErmsTransformer.IMIS_UUID)) { |
|
181 |
// IMIS_ID found |
|
182 |
result = Integer.parseInt(extension.getValue().trim()); |
|
183 |
} |
|
184 |
} catch (NumberFormatException e) { |
|
185 |
logger.warn("String could not be parsed to int: " + extension.getValue() + " / Reference: " + reference.getUuid() + " (" + reference.getTitleCache() + ")"); |
|
186 |
result = null; |
|
187 |
} |
|
188 |
} |
|
189 |
} |
|
190 |
return result; |
|
180 |
// TODO |
|
181 |
// Where is the IMIS_Id from an ERMS import stored in CDM? |
|
182 |
return null; |
|
191 | 183 |
} |
192 | 184 |
|
193 | 185 |
/** |
... | ... | |
220 | 212 |
*/ |
221 | 213 |
@SuppressWarnings("unused") |
222 | 214 |
private static String getName(ReferenceBase<?> reference) { |
223 |
return reference.getTitle(); |
|
215 |
if (reference != null) { |
|
216 |
return reference.getTitle(); |
|
217 |
} else { |
|
218 |
return null; |
|
219 |
} |
|
224 | 220 |
} |
225 | 221 |
|
226 | 222 |
/** |
... | ... | |
231 | 227 |
*/ |
232 | 228 |
@SuppressWarnings("unused") |
233 | 229 |
private static String getAuthorString(ReferenceBase<?> reference) { |
234 |
TeamOrPersonBase team = reference.getAuthorTeam(); |
|
235 |
if (team != null) { |
|
236 |
// return team.getTitleCache(); |
|
237 |
return team.getNomenclaturalTitle(); |
|
238 |
} else { |
|
239 |
return null; |
|
230 |
String result = null; |
|
231 |
|
|
232 |
if (reference != null) { |
|
233 |
TeamOrPersonBase team = reference.getAuthorTeam(); |
|
234 |
if (team != null) { |
|
235 |
// result = team.getTitleCache(); |
|
236 |
result = team.getNomenclaturalTitle(); |
|
237 |
} else { |
|
238 |
result = null; |
|
239 |
} |
|
240 | 240 |
} |
241 |
|
|
242 |
return result; |
|
241 | 243 |
} |
242 | 244 |
|
243 | 245 |
/** |
... | ... | |
248 | 250 |
*/ |
249 | 251 |
@SuppressWarnings("unused") |
250 | 252 |
private static String getNomRefCache(ReferenceBase<?> reference) { |
251 |
return reference.getTitleCache(); |
|
253 |
if (reference != null) { |
|
254 |
return reference.getTitleCache(); |
|
255 |
} else { |
|
256 |
return null; |
|
257 |
} |
|
252 | 258 |
} |
253 | 259 |
|
254 | 260 |
/** |
... | ... | |
260 | 266 |
@SuppressWarnings("unused") |
261 | 267 |
private static String getNotes(ReferenceBase<?> reference) { |
262 | 268 |
// TODO |
263 |
String result = null; |
|
264 |
if (reference != null) { |
|
265 |
Set<Annotation> annotations = reference.getAnnotations(); |
|
266 |
if (annotations.size() == 1) { |
|
267 |
result = annotations.iterator().next().getText(); |
|
268 |
} else { |
|
269 |
logger.warn("Reference has more than one Annotation: " + reference.getUuid() + " (" + reference.getTitleCache() + ")"); |
|
270 |
} |
|
271 |
} |
|
272 |
return result; |
|
269 |
return null; |
|
273 | 270 |
} |
274 | 271 |
|
275 | 272 |
/** |
... | ... | |
281 | 278 |
@SuppressWarnings("unused") |
282 | 279 |
private static String getRefIdInSource(ReferenceBase<?> reference) { |
283 | 280 |
String result = null; |
284 |
Set<IdentifiableSource> sources = reference.getSources(); |
|
285 |
if (sources.size() == 1) { |
|
286 |
result = sources.iterator().next().getIdInSource(); |
|
287 |
} else { |
|
288 |
logger.warn("Reference has more than one source: " + reference.getUuid() + " (" + reference.getTitleCache() + ")"); |
|
281 |
|
|
282 |
if (reference != null) { |
|
283 |
Set<IdentifiableSource> sources = reference.getSources(); |
|
284 |
if (sources.size() == 1) { |
|
285 |
result = sources.iterator().next().getIdInSource(); |
|
286 |
} else if (sources.size() > 1) { |
|
287 |
logger.warn("Reference has multiple IdentifiableSources: " + reference.getUuid() + " (" + reference.getTitleCache() + ")"); |
|
288 |
int count = 1; |
|
289 |
for (IdentifiableSource source : sources) { |
|
290 |
result += source.getIdInSource(); |
|
291 |
if (count < sources.size()) { |
|
292 |
result += "; "; |
|
293 |
} |
|
294 |
count++; |
|
295 |
} |
|
296 |
} |
|
289 | 297 |
} |
298 |
|
|
290 | 299 |
return result; |
291 | 300 |
} |
292 | 301 |
|
... | ... | |
298 | 307 |
*/ |
299 | 308 |
@SuppressWarnings("unused") |
300 | 309 |
private static String getOriginalDB(ReferenceBase<?> reference) { |
301 |
String result = null; |
|
310 |
String result = ""; |
|
311 |
|
|
302 | 312 |
if (reference != null) { |
303 |
for (IdentifiableSource source : reference.getSources()) { |
|
304 |
ReferenceBase citation = source.getCitation(); |
|
305 |
if (source != null && citation != null) { |
|
306 |
result = citation.getTitleCache(); //or just title |
|
313 |
Set<IdentifiableSource> sources = reference.getSources(); |
|
314 |
if (sources.size() == 1) { |
|
315 |
ReferenceBase citation = sources.iterator().next().getCitation(); |
|
316 |
if (citation != null) { |
|
317 |
result = PesiTransformer.databaseString2Abbreviation(citation.getTitleCache()); //or just title |
|
318 |
} else { |
|
319 |
logger.warn("OriginalDB can not be determined because the citation of this source is NULL: " + sources.iterator().next().getUuid()); |
|
320 |
} |
|
321 |
} else if (sources.size() > 1) { |
|
322 |
logger.warn("Taxon has multiple IdentifiableSources: " + reference.getUuid() + " (" + reference.getTitleCache() + ")"); |
|
323 |
int count = 1; |
|
324 |
for (IdentifiableSource source : sources) { |
|
325 |
ReferenceBase citation = source.getCitation(); |
|
326 |
if (citation != null) { |
|
327 |
result += PesiTransformer.databaseString2Abbreviation(citation.getTitleCache()); |
|
328 |
if (count < sources.size()) { |
|
329 |
result += "; "; |
|
330 |
} |
|
331 |
count++; |
|
332 |
} |
|
307 | 333 |
} |
334 |
} else { |
|
335 |
result = null; |
|
308 | 336 |
} |
309 | 337 |
} |
338 |
|
|
310 | 339 |
return result; |
311 | 340 |
} |
312 | 341 |
|
Also available in: Unified diff
merging /branches/cdmlib/SPRINT-Chichorieae1/ to trunk