Revision 7319c528
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.UUID; |
|
17 | 16 |
|
18 | 17 |
import org.apache.log4j.Logger; |
19 | 18 |
import org.springframework.stereotype.Component; |
20 | 19 |
|
21 | 20 |
import eu.etaxonomy.cdm.common.CdmUtils; |
22 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
|
23 | 21 |
import eu.etaxonomy.cdm.io.common.DbImportBase; |
24 | 22 |
import eu.etaxonomy.cdm.io.common.IPartitionedIO; |
25 | 23 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
... | ... | |
64 | 62 |
|
65 | 63 |
@Override |
66 | 64 |
protected void doInvoke(RedListGefaesspflanzenImportState state) { |
67 |
super.doInvoke(state); |
|
65 |
makeAuthors(state, "AUTOR_KOMB"); |
|
66 |
makeAuthors(state, "AUTOR_BASI"); |
|
68 | 67 |
} |
69 | 68 |
|
70 | 69 |
|
71 | 70 |
@Override |
72 | 71 |
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) { |
73 |
ResultSet rs = partitioner.getResultSet(); |
|
74 |
Map<String, TeamOrPersonBase> teamsOrPersonToSave = new HashMap<String, TeamOrPersonBase>(); |
|
75 |
try { |
|
76 |
while (rs.next()){ |
|
77 |
makeSingleAuthor(state, rs, teamsOrPersonToSave); |
|
78 |
|
|
79 |
} |
|
80 |
} catch (SQLException e) { |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
83 |
|
|
84 |
// getAgentService().saveOrUpdate(teamsOrPersonToSave.values()); |
|
85 | 72 |
return true; |
86 | 73 |
} |
87 | 74 |
|
88 |
private void makeSingleAuthor(RedListGefaesspflanzenImportState state, ResultSet rs, Map<String, TeamOrPersonBase> teamsOrPersonToSave) |
|
89 |
throws SQLException { |
|
90 |
long id = rs.getLong("NAMNR"); |
|
91 |
String authorName = rs.getString("AUTOR"); |
|
92 |
String authorBasiName = rs.getString("AUTOR_BASI"); |
|
93 |
String authorKombName = rs.getString("AUTOR_KOMB"); |
|
94 |
|
|
95 |
//check null values |
|
96 |
if(CdmUtils.isBlank(authorName) && CdmUtils.isBlank(authorBasiName) && CdmUtils.isBlank(authorKombName)){ |
|
97 |
logger.info("NAMNR "+id+": No author found!"); |
|
98 |
return; |
|
99 |
} |
|
100 |
TeamOrPersonBase authorKomb = null; |
|
101 |
TeamOrPersonBase authorBasi = null; |
|
102 |
|
|
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 |
} |
|
111 |
|
|
112 |
//check if missapplied name |
|
113 |
if(authorName.equals("auct.")){ |
|
114 |
|
|
115 |
} |
|
116 |
//check if pro parte synonym |
|
117 |
else if(authorName.equals("p .p.")){ |
|
118 |
|
|
119 |
} |
|
120 |
else if(authorBasi==null && authorKomb==null){ |
|
121 |
logger.warn("NAMNR "+id+": Author not atomised in authorKomb and authorBasi. Author: "+authorName); |
|
122 |
TeamOrPersonBase team = importPerson(state, teamsOrPersonToSave, id, authorName); |
|
123 |
state.getAuthorKombMap().put(id, team.getUuid()); |
|
124 |
} |
|
125 |
// //check author column consistency |
|
126 |
// String authorCheckString = ""; |
|
127 |
// if(!CdmUtils.isBlank(authorKombName)){ |
|
128 |
// authorCheckString = "("+authorBasiName+")"+" "+authorKombName; |
|
129 |
// } |
|
130 |
// else{ |
|
131 |
// authorCheckString = authorBasiName; |
|
132 |
// } |
|
133 |
// boolean isAuthorStringCorrect = false; |
|
134 |
// if(authorName.startsWith(authorCheckString)){ |
|
135 |
// isAuthorStringCorrect = true; |
|
136 |
// } |
|
137 |
// if(!isAuthorStringCorrect){ |
|
138 |
// String errorString = "NAMNR "+id+": Author string not consistent! Is \""+authorName+"\" Should start with \""+authorCheckString+"\""; |
|
139 |
// logger.error(errorString); |
|
140 |
// } |
|
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
private TeamOrPersonBase importPerson(RedListGefaesspflanzenImportState state, Map<String, TeamOrPersonBase> teamsOrPersonToSave, |
|
145 |
long id, String agentName) { |
|
146 |
TeamOrPersonBase agent = null; |
|
147 |
//check if agent already exists |
|
148 |
TeamOrPersonBase notYetPersistedAgent = teamsOrPersonToSave.get(agentName); |
|
149 |
UUID existingAgentUuid = state.getAuthorKombMap().get(agentName); |
|
150 |
if(notYetPersistedAgent!=null){ |
|
151 |
agent = notYetPersistedAgent; |
|
152 |
} |
|
153 |
else if(existingAgentUuid!=null){ |
|
154 |
agent = HibernateProxyHelper.deproxy(getAgentService().load(existingAgentUuid), TeamOrPersonBase.class); |
|
155 |
} |
|
156 |
else if(!CdmUtils.isBlank(agentName)){ |
|
157 |
//check if it is a team |
|
158 |
if(agentName.contains("&")){ |
|
159 |
agent = Team.NewInstance(); |
|
160 |
String[] split = agentName.split("&"); |
|
161 |
for (int i = 0; i < split.length; i++) { |
|
162 |
((Team) agent).addTeamMember(Person.NewTitledInstance(split[i].trim())); |
|
75 |
private void makeAuthors(RedListGefaesspflanzenImportState state, String columnName) { |
|
76 |
|
|
77 |
//--- combination authors --- |
|
78 |
String query = "select distinct "+columnName+" from V_TAXATLAS_D20_EXPORT t" |
|
79 |
+ " WHERE TRIM(t."+columnName+") <>''"; |
|
80 |
|
|
81 |
ResultSet rs = state.getConfig().getSource().getResultSet(query); |
|
82 |
|
|
83 |
try{ |
|
84 |
while(rs.next()){ |
|
85 |
String authorName = rs.getString(columnName); |
|
86 |
TeamOrPersonBase teamOrPerson = null; |
|
87 |
if(!CdmUtils.isBlank(authorName)){ |
|
88 |
//check if it is a team |
|
89 |
if(authorName.contains("&")){ |
|
90 |
teamOrPerson = Team.NewInstance(); |
|
91 |
String[] split = authorName.split("&"); |
|
92 |
for (int i = 0; i < split.length; i++) { |
|
93 |
((Team) teamOrPerson).addTeamMember(Person.NewTitledInstance(split[i].trim())); |
|
94 |
} |
|
95 |
} |
|
96 |
else{ |
|
97 |
teamOrPerson = Person.NewTitledInstance(authorName); |
|
98 |
} |
|
99 |
getAgentService().saveOrUpdate(teamOrPerson); |
|
100 |
state.getAuthorMap().put(authorName, teamOrPerson.getUuid()); |
|
163 | 101 |
} |
164 | 102 |
} |
165 |
else{ |
|
166 |
agent = Person.NewTitledInstance(agentName); |
|
167 |
} |
|
168 |
teamsOrPersonToSave.put(agentName, agent); |
|
169 |
// ImportHelper.setOriginalSource(agent, state.getTransactionalSourceReference(), id, namespace); |
|
103 |
} catch (SQLException e) { |
|
104 |
e.printStackTrace(); |
|
170 | 105 |
} |
171 |
return agent; |
|
172 | 106 |
} |
173 | 107 |
|
174 | 108 |
@Override |
Also available in: Unified diff
Refactor name-author mapping