Revision 67426b79
Added by Andreas Müller over 4 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiSourceExport.java | ||
---|---|---|
11 | 11 |
import java.sql.SQLException; |
12 | 12 |
import java.util.ArrayList; |
13 | 13 |
import java.util.EnumSet; |
14 |
import java.util.HashSet; |
|
15 | 14 |
import java.util.List; |
16 | 15 |
import java.util.Set; |
17 | 16 |
|
... | ... | |
35 | 34 |
import eu.etaxonomy.cdm.model.common.ExtensionType; |
36 | 35 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
37 | 36 |
import eu.etaxonomy.cdm.model.reference.Reference; |
38 |
import eu.etaxonomy.cdm.model.reference.ReferenceType; |
|
39 | 37 |
|
40 | 38 |
/** |
41 | 39 |
* The export class for {@link eu.etaxonomy.cdm.model.reference.Reference References}.<p> |
... | ... | |
299 | 297 |
String result = null; |
300 | 298 |
|
301 | 299 |
try { |
302 |
if (reference != null) { |
|
303 |
Set<IdentifiableSource> sourceAll = reference.getSources(); |
|
304 |
Set<IdentifiableSource> sourceCandidates = filterOriginalPesiDbSources(sourceAll);
|
|
305 |
|
|
306 |
if (sourceCandidates.size() == 1) { |
|
307 |
result = sourceCandidates.iterator().next().getIdInSource(); |
|
308 |
} else if (sourceCandidates.size() > 1) { |
|
309 |
logger.warn("Reference for RefIdInSource has multiple IdentifiableSources which are candidates for a PESI originalDbSource. RefIdInSource can't be determined correctly and will be left out: " + reference.getUuid() + " (" + reference.getTitleCache() + ")"); |
|
310 |
int count = 1; |
|
311 |
// for (IdentifiableSource source : sources) { |
|
312 |
// result += source.getIdInSource(); |
|
313 |
// if (count < sources.size()) { |
|
314 |
// result += "; "; |
|
315 |
// } |
|
316 |
// count++; |
|
317 |
// } |
|
318 |
} |
|
319 |
} |
|
300 |
if (reference != null) {
|
|
301 |
Set<IdentifiableSource> sourceAll = reference.getSources();
|
|
302 |
Set<IdentifiableSource> sourceCandidates = filterPesiSources(sourceAll);
|
|
303 |
|
|
304 |
if (sourceCandidates.size() == 1) {
|
|
305 |
result = sourceCandidates.iterator().next().getIdInSource();
|
|
306 |
} else if (sourceCandidates.size() > 1) {
|
|
307 |
logger.warn("Reference for RefIdInSource has multiple IdentifiableSources which are candidates for a PESI originalDbSource. RefIdInSource can't be determined correctly and will be left out: " + reference.getUuid() + " (" + reference.getTitleCache() + ")");
|
|
308 |
int count = 1;
|
|
309 |
// for (IdentifiableSource source : sources) {
|
|
310 |
// result += source.getIdInSource();
|
|
311 |
// if (count < sources.size()) {
|
|
312 |
// result += "; ";
|
|
313 |
// }
|
|
314 |
// count++;
|
|
315 |
// }
|
|
316 |
}
|
|
317 |
}
|
|
320 | 318 |
} catch (Exception e) { |
321 | 319 |
e.printStackTrace(); |
322 | 320 |
} |
... | ... | |
324 | 322 |
return result; |
325 | 323 |
} |
326 | 324 |
|
327 |
private static Set<IdentifiableSource> filterOriginalPesiDbSources( |
|
328 |
Set<IdentifiableSource> sourceAll) { |
|
329 |
Set<IdentifiableSource> sourceCandidates = new HashSet<>(); |
|
330 |
for (IdentifiableSource source : sourceAll){ |
|
331 |
if (isOriginalPesiDbSource(source)){ |
|
332 |
sourceCandidates.add(source); |
|
333 |
} |
|
334 |
} |
|
335 |
return sourceCandidates; |
|
336 |
} |
|
337 |
|
|
338 |
private static boolean isOriginalPesiDbSource(IdentifiableSource source) { |
|
339 |
return (source.getCitation() != null) && |
|
340 |
source.getCitation().getType().equals(ReferenceType.Database); |
|
341 |
} |
|
325 |
// private static Set<IdentifiableSource> filterOriginalPesiDbSources(
|
|
326 |
// Set<IdentifiableSource> sourceAll) {
|
|
327 |
// Set<IdentifiableSource> sourceCandidates = new HashSet<>();
|
|
328 |
// for (IdentifiableSource source : sourceAll){
|
|
329 |
// if (isOriginalPesiDbSource(source)){
|
|
330 |
// sourceCandidates.add(source);
|
|
331 |
// }
|
|
332 |
// }
|
|
333 |
// return sourceCandidates;
|
|
334 |
// }
|
|
335 |
// |
|
336 |
// private static boolean isOriginalPesiDbSource(IdentifiableSource source) {
|
|
337 |
// return (source.getCitation() != null) &&
|
|
338 |
// source.getCitation().getType().equals(ReferenceType.Database);
|
|
339 |
// }
|
|
342 | 340 |
|
343 | 341 |
/** |
344 | 342 |
* Returns the <code>OriginalDB</code> attribute. |
Also available in: Unified diff
ref #2717 adapt PesiExport to EuroMed requirements and adapt PesiExportActivatorEM