1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import org.w3c.dom.Element;
|
14
|
import org.w3c.dom.NodeList;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
17
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
18
|
import eu.etaxonomy.cdm.model.agent.Person;
|
19
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
20
|
|
21
|
/**
|
22
|
* @author pplitzner
|
23
|
* @date 16.06.2015
|
24
|
*
|
25
|
*/
|
26
|
public class AbcdPersonParser {
|
27
|
|
28
|
private final String prefix;
|
29
|
|
30
|
private final SpecimenImportReport report;
|
31
|
|
32
|
private final ICdmApplicationConfiguration cdmAppController;
|
33
|
|
34
|
|
35
|
public AbcdPersonParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {
|
36
|
this.prefix = prefix;
|
37
|
this.report = report;
|
38
|
this.cdmAppController = cdmAppController;
|
39
|
}
|
40
|
|
41
|
|
42
|
public AgentBase<?> parse(Element item) {
|
43
|
AgentBase<?> agentBase = null;
|
44
|
NodeList fullNameList = item.getElementsByTagName(prefix+"FullName");
|
45
|
String fullName = AbcdParseUtility.parseFirstTextContent(fullNameList);
|
46
|
if(fullName!=null){
|
47
|
List<AgentBase> matchingAgents = cdmAppController.getAgentService().findByTitle(AgentBase.class, fullName, MatchMode.EXACT, null, null, null, null, null).getRecords();
|
48
|
if(matchingAgents.size()==1){
|
49
|
agentBase = matchingAgents.iterator().next();
|
50
|
}
|
51
|
else{
|
52
|
agentBase = Person.NewTitledInstance(fullName);
|
53
|
}
|
54
|
}
|
55
|
return agentBase;
|
56
|
}
|
57
|
|
58
|
|
59
|
}
|