Project

General

Profile

« Previous | Next » 

Revision e965dc89

Added by Patrick Plitzner almost 8 years ago

error handling for name import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java
14 14
import java.util.HashMap;
15 15
import java.util.Map;
16 16
import java.util.Map.Entry;
17
import java.util.UUID;
17 18

  
18 19
import org.apache.log4j.Logger;
19 20
import org.springframework.stereotype.Component;
......
25 26
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
26 27
import eu.etaxonomy.cdm.model.agent.AgentBase;
27 28
import eu.etaxonomy.cdm.model.agent.Person;
29
import eu.etaxonomy.cdm.model.agent.Team;
28 30
import eu.etaxonomy.cdm.model.common.CdmBase;
29 31

  
30 32
/**
......
97 99
        String authorName = rs.getString("AUTOR");
98 100
        String authorBasiName = rs.getString("AUTOR_BASI");
99 101
        String authorKombName = rs.getString("AUTOR_KOMB");
100
        String zusatz = rs.getString("ZUSATZ");
101 102

  
102 103
        //check null values
103 104
        if(CdmUtils.isBlank(authorName) && CdmUtils.isBlank(authorBasiName) && CdmUtils.isBlank(authorKombName)){
104
            logger.error("No author found for NAMNR "+id);
105
            logger.info("NAMNR "+id+": No author found for NAMNR "+id);
105 106
            return;
106 107
        }
107
        Person authorKomb = null;
108
        Person authorBasi = null;
109
        Person author = null;
110
        authorKomb = importPerson(state, teamsOrPersonToSave, id, authorKombName, AUTHOR_KOMB_NAMESPACE);
108
        AgentBase authorKomb = null;
109
        AgentBase authorBasi = null;
110
        AgentBase author = null;
111 111

  
112
        authorKomb = importPerson(state, teamsOrPersonToSave, id, authorKombName, AUTHOR_KOMB_NAMESPACE);
112 113
        authorBasi = importPerson(state, teamsOrPersonToSave, id, authorBasiName, AUTHOR_BASI_NAMESPACE);
113 114

  
114
//        if(authorBasi!=null && authorKomb!=null){
115
//            Team team = Team.NewInstance();
116
//            team.addTeamMember(authorBasi);
117
//            team.addTeamMember(authorKomb);
118
//            teamsOrPersonToSave.add(team);
119
//            ImportHelper.setOriginalSource(team, state.getTransactionalSourceReference(), id, AUTHOR_NAMESPACE);
120
//        }
121
        if(authorBasi==null && authorKomb==null){
122
            logger.warn("Author not atomised in authorKomb and authorBasi");
123
            author = Person.NewTitledInstance(authorName);
124
            teamsOrPersonToSave.put(authorName, author);
125
            ImportHelper.setOriginalSource(author, state.getTransactionalSourceReference(), id, AUTHOR_KOMB_NAMESPACE);
126
        }
127
        //check author column consistency
128
        String authorCheckString = "";
129
        if(!CdmUtils.isBlank(authorKombName)){
130
            authorCheckString = "("+authorBasiName+")"+" "+authorKombName;
131
        }
132
        else{
133
            authorCheckString = authorBasiName;
115
        //check if missapplied name
116
        if(authorName.equals("auct.")){
117

  
134 118
        }
135
        boolean isAuthorStringCorrect = false;
136
        if(authorName.startsWith(authorCheckString)){
137
            isAuthorStringCorrect = true;
138
            if(!CdmUtils.isBlank(zusatz) && !authorName.contains(zusatz)){
139
                isAuthorStringCorrect = false;
140
            }
119
        //check if pro parte synonym
120
        else if(authorName.equals("p .p.")){
121

  
141 122
        }
142
        if(!isAuthorStringCorrect){
143
            String errorString = "ID: "+id+", Author string not consistent! Is \""+authorName+"\" Should start with \""+authorCheckString+"\"";
144
            if(!CdmUtils.isBlank(zusatz)){
145
                errorString +=" and contain \""+zusatz+"\"";
146
            }
147
            logger.error(errorString);
123
        else if(authorBasi==null && authorKomb==null){
124
            logger.warn("NAMNR "+id+": Author not atomised in authorKomb and authorBasi. Author: "+authorName);
125
            importPerson(state, teamsOrPersonToSave, id, authorName, AUTHOR_KOMB_NAMESPACE);
148 126
        }
127
//        //check author column consistency
128
//        String authorCheckString = "";
129
//        if(!CdmUtils.isBlank(authorKombName)){
130
//            authorCheckString = "("+authorBasiName+")"+" "+authorKombName;
131
//        }
132
//        else{
133
//            authorCheckString = authorBasiName;
134
//        }
135
//        boolean isAuthorStringCorrect = false;
136
//        if(authorName.startsWith(authorCheckString)){
137
//            isAuthorStringCorrect = true;
138
//        }
139
//        if(!isAuthorStringCorrect){
140
//            String errorString = "NAMNR "+id+": Author string not consistent! Is \""+authorName+"\" Should start with \""+authorCheckString+"\"";
141
//            logger.error(errorString);
142
//        }
149 143

  
150 144
    }
151 145

  
152
    private Person importPerson(RedListGefaesspflanzenImportState state, Map<String, AgentBase> teamsOrPersonToSave,
146
    private AgentBase importPerson(RedListGefaesspflanzenImportState state, Map<String, AgentBase> teamsOrPersonToSave,
153 147
            long id, String agentName, String namespace) {
154
        Person person = null;
155
        if(!CdmUtils.isBlank(agentName) && !state.getAgentMap().containsKey(agentName)){
156
            person = Person.NewTitledInstance(agentName);
157
            teamsOrPersonToSave.put(agentName, person);
158
            state.getAgentMap().put(agentName, person.getUuid());
159
            ImportHelper.setOriginalSource(person, state.getTransactionalSourceReference(), id, namespace);
148
        AgentBase agent = null;
149
        //check if agent already exists
150
        AgentBase notYetPersistedAgent = teamsOrPersonToSave.get(agentName);
151
        UUID existingAgentUuid = state.getAgentMap().get(agentName);
152
        if(notYetPersistedAgent!=null){
153
            agent = notYetPersistedAgent;
154
        }
155
        else if(existingAgentUuid!=null){
156
            agent = getAgentService().load(existingAgentUuid);
157
        }
158
        else if(!CdmUtils.isBlank(agentName)){
159
            //check if it is a team
160
            if(agentName.contains("&")){
161
                agent = Team.NewInstance();
162
                String[] split = agentName.split("&");
163
                for (int i = 0; i < split.length; i++) {
164
                    ((Team) agent).addTeamMember(Person.NewTitledInstance(split[i].trim()));
165
                }
166
            }
167
            else{
168
                agent = Person.NewTitledInstance(agentName);
169
            }
170
            teamsOrPersonToSave.put(agentName, agent);
171
            state.getAgentMap().put(agentName, agent.getUuid());
172
            ImportHelper.setOriginalSource(agent, state.getTransactionalSourceReference(), id, namespace);
160 173
        }
161
        return person;
174
        return agent;
162 175
    }
163 176

  
164 177
    @Override

Also available in: Unified diff