Revision c1641f79
Added by Patrick Plitzner about 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportAuthor.java | ||
---|---|---|
13 | 13 |
import java.sql.SQLException; |
14 | 14 |
import java.util.HashMap; |
15 | 15 |
import java.util.Map; |
16 |
import java.util.Map.Entry; |
|
17 | 16 |
import java.util.UUID; |
18 | 17 |
|
19 | 18 |
import org.apache.log4j.Logger; |
20 | 19 |
import org.springframework.stereotype.Component; |
21 | 20 |
|
22 | 21 |
import eu.etaxonomy.cdm.common.CdmUtils; |
22 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
23 | 23 |
import eu.etaxonomy.cdm.io.common.DbImportBase; |
24 | 24 |
import eu.etaxonomy.cdm.io.common.IPartitionedIO; |
25 |
import eu.etaxonomy.cdm.io.common.ImportHelper; |
|
26 | 25 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
27 |
import eu.etaxonomy.cdm.model.agent.AgentBase; |
|
28 | 26 |
import eu.etaxonomy.cdm.model.agent.Person; |
29 | 27 |
import eu.etaxonomy.cdm.model.agent.Team; |
28 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
30 | 29 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
31 | 30 |
|
32 | 31 |
/** |
... | ... | |
43 | 42 |
|
44 | 43 |
private static final String pluralString = "authors"; |
45 | 44 |
|
46 |
private static final String AUTHOR_KOMB_NAMESPACE = "author_komb"; |
|
47 |
private static final String AUTHOR_BASI_NAMESPACE = "author_basi"; |
|
48 |
|
|
49 | 45 |
public RedListGefaesspflanzenImportAuthor() { |
50 | 46 |
super(tableName, pluralString); |
51 | 47 |
} |
... | ... | |
75 | 71 |
@Override |
76 | 72 |
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) { |
77 | 73 |
ResultSet rs = partitioner.getResultSet(); |
78 |
Map<String, AgentBase> teamsOrPersonToSave = new HashMap<String, AgentBase>();
|
|
74 |
Map<String, TeamOrPersonBase> teamsOrPersonToSave = new HashMap<String, TeamOrPersonBase>();
|
|
79 | 75 |
try { |
80 | 76 |
while (rs.next()){ |
81 | 77 |
makeSingleAuthor(state, rs, teamsOrPersonToSave); |
... | ... | |
85 | 81 |
e.printStackTrace(); |
86 | 82 |
} |
87 | 83 |
|
88 |
getAgentService().saveOrUpdate(teamsOrPersonToSave.values()); |
|
89 |
//add partition to state map |
|
90 |
for (Entry<String, AgentBase> entry: teamsOrPersonToSave.entrySet()) { |
|
91 |
state.getAgentMap().put(entry.getKey(), entry.getValue().getUuid()); |
|
92 |
} |
|
84 |
// getAgentService().saveOrUpdate(teamsOrPersonToSave.values()); |
|
93 | 85 |
return true; |
94 | 86 |
} |
95 | 87 |
|
96 |
private void makeSingleAuthor(RedListGefaesspflanzenImportState state, ResultSet rs, Map<String, AgentBase> teamsOrPersonToSave)
|
|
88 |
private void makeSingleAuthor(RedListGefaesspflanzenImportState state, ResultSet rs, Map<String, TeamOrPersonBase> teamsOrPersonToSave)
|
|
97 | 89 |
throws SQLException { |
98 | 90 |
long id = rs.getLong("NAMNR"); |
99 | 91 |
String authorName = rs.getString("AUTOR"); |
... | ... | |
102 | 94 |
|
103 | 95 |
//check null values |
104 | 96 |
if(CdmUtils.isBlank(authorName) && CdmUtils.isBlank(authorBasiName) && CdmUtils.isBlank(authorKombName)){ |
105 |
logger.info("NAMNR "+id+": No author found for NAMNR "+id);
|
|
97 |
logger.info("NAMNR "+id+": No author found!");
|
|
106 | 98 |
return; |
107 | 99 |
} |
108 |
AgentBase authorKomb = null; |
|
109 |
AgentBase authorBasi = null; |
|
110 |
AgentBase author = null; |
|
100 |
TeamOrPersonBase authorKomb = null; |
|
101 |
TeamOrPersonBase authorBasi = null; |
|
111 | 102 |
|
112 |
authorKomb = importPerson(state, teamsOrPersonToSave, id, authorKombName, AUTHOR_KOMB_NAMESPACE); |
|
113 |
authorBasi = importPerson(state, teamsOrPersonToSave, id, authorBasiName, AUTHOR_BASI_NAMESPACE); |
|
103 |
authorKomb = importPerson(state, teamsOrPersonToSave, id, authorKombName); |
|
104 |
if(authorKomb!=null){ |
|
105 |
state.getAuthorKombMap().put(id, authorKomb.getUuid()); |
|
106 |
} |
|
107 |
authorBasi = importPerson(state, teamsOrPersonToSave, id, authorBasiName); |
|
108 |
if(authorKomb!=null){ |
|
109 |
state.getAuthorBasiMap().put(id, authorBasi.getUuid()); |
|
110 |
} |
|
114 | 111 |
|
115 | 112 |
//check if missapplied name |
116 | 113 |
if(authorName.equals("auct.")){ |
... | ... | |
122 | 119 |
} |
123 | 120 |
else if(authorBasi==null && authorKomb==null){ |
124 | 121 |
logger.warn("NAMNR "+id+": Author not atomised in authorKomb and authorBasi. Author: "+authorName); |
125 |
importPerson(state, teamsOrPersonToSave, id, authorName, AUTHOR_KOMB_NAMESPACE); |
|
122 |
TeamOrPersonBase team = importPerson(state, teamsOrPersonToSave, id, authorName); |
|
123 |
state.getAuthorKombMap().put(id, team.getUuid()); |
|
126 | 124 |
} |
127 | 125 |
// //check author column consistency |
128 | 126 |
// String authorCheckString = ""; |
... | ... | |
143 | 141 |
|
144 | 142 |
} |
145 | 143 |
|
146 |
private AgentBase importPerson(RedListGefaesspflanzenImportState state, Map<String, AgentBase> teamsOrPersonToSave,
|
|
147 |
long id, String agentName, String namespace) {
|
|
148 |
AgentBase agent = null;
|
|
144 |
private TeamOrPersonBase importPerson(RedListGefaesspflanzenImportState state, Map<String, TeamOrPersonBase> teamsOrPersonToSave,
|
|
145 |
long id, String agentName) { |
|
146 |
TeamOrPersonBase agent = null;
|
|
149 | 147 |
//check if agent already exists |
150 |
AgentBase notYetPersistedAgent = teamsOrPersonToSave.get(agentName);
|
|
151 |
UUID existingAgentUuid = state.getAgentMap().get(agentName);
|
|
148 |
TeamOrPersonBase notYetPersistedAgent = teamsOrPersonToSave.get(agentName);
|
|
149 |
UUID existingAgentUuid = state.getAuthorKombMap().get(agentName);
|
|
152 | 150 |
if(notYetPersistedAgent!=null){ |
153 | 151 |
agent = notYetPersistedAgent; |
154 | 152 |
} |
155 | 153 |
else if(existingAgentUuid!=null){ |
156 |
agent = getAgentService().load(existingAgentUuid);
|
|
154 |
agent = HibernateProxyHelper.deproxy(getAgentService().load(existingAgentUuid), TeamOrPersonBase.class);
|
|
157 | 155 |
} |
158 | 156 |
else if(!CdmUtils.isBlank(agentName)){ |
159 | 157 |
//check if it is a team |
... | ... | |
168 | 166 |
agent = Person.NewTitledInstance(agentName); |
169 | 167 |
} |
170 | 168 |
teamsOrPersonToSave.put(agentName, agent); |
171 |
state.getAgentMap().put(agentName, agent.getUuid()); |
|
172 |
ImportHelper.setOriginalSource(agent, state.getTransactionalSourceReference(), id, namespace); |
|
169 |
// ImportHelper.setOriginalSource(agent, state.getTransactionalSourceReference(), id, namespace); |
|
173 | 170 |
} |
174 | 171 |
return agent; |
175 | 172 |
} |
Also available in: Unified diff
Improved author and name import (unstable)