Project

General

Profile

Download (1.76 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
11

    
12
import java.util.List;
13

    
14
import org.w3c.dom.Element;
15
import org.w3c.dom.NodeList;
16

    
17
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.agent.Person;
20
import eu.etaxonomy.cdm.persistence.query.MatchMode;
21

    
22
/**
23
 * @author pplitzner
24
 * @date 16.06.2015
25
 *
26
 */
27
public class AbcdPersonParser {
28

    
29
    private final String prefix;
30

    
31
    private final Abcd206ImportReport report;
32

    
33
    private final ICdmApplicationConfiguration cdmAppController;
34

    
35

    
36
    public AbcdPersonParser(String prefix, Abcd206ImportReport report, ICdmApplicationConfiguration cdmAppController) {
37
        this.prefix = prefix;
38
        this.report = report;
39
        this.cdmAppController = cdmAppController;
40
    }
41

    
42

    
43
    public AgentBase<?> parse(Element item) {
44
        AgentBase<?> agentBase = null;
45
        NodeList fullNameList = item.getElementsByTagName(prefix+"FullName");
46
        String fullName = AbcdParseUtility.parseFirstTextContent(fullNameList);
47
        if(fullName!=null){
48
            List<AgentBase> matchingAgents = cdmAppController.getAgentService().findByTitle(AgentBase.class, fullName, MatchMode.EXACT, null, null, null, null, null).getRecords();
49
            if(matchingAgents.size()==1){
50
                agentBase = matchingAgents.iterator().next();
51
            }
52
            else{
53
                agentBase = Person.NewTitledInstance(fullName);
54
            }
55
        }
56
        return agentBase;
57
    }
58

    
59

    
60
}
(9-9/11)