1 |
e8c5db35
|
Patrick Plitzner
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2016 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.redlist.gefaesspflanzen;
|
11 |
|
|
|
12 |
|
|
import java.sql.ResultSet;
|
13 |
|
|
import java.sql.SQLException;
|
14 |
|
|
import java.util.HashMap;
|
15 |
|
|
import java.util.Map;
|
16 |
|
|
|
17 |
|
|
import org.apache.log4j.Logger;
|
18 |
|
|
import org.springframework.stereotype.Component;
|
19 |
|
|
|
20 |
|
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
21 |
|
|
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
22 |
|
|
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
|
23 |
|
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
24 |
|
|
import eu.etaxonomy.cdm.model.agent.Person;
|
25 |
e965dc89
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.agent.Team;
|
26 |
c1641f79
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
27 |
e8c5db35
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
28 |
|
|
|
29 |
|
|
/**
|
30 |
|
|
* @author pplitzner
|
31 |
|
|
* @date Feb 29, 2016
|
32 |
|
|
*
|
33 |
|
|
*/
|
34 |
|
|
@Component
|
35 |
|
|
@SuppressWarnings("serial")
|
36 |
|
|
public class RedListGefaesspflanzenImportAuthor extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
|
37 |
b37b6a0f
|
Patrick Plitzner
|
|
38 |
e8c5db35
|
Patrick Plitzner
|
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportAuthor.class);
|
39 |
|
|
|
40 |
|
|
private static final String tableName = "Rote Liste Gefäßpflanzen";
|
41 |
|
|
|
42 |
|
|
private static final String pluralString = "authors";
|
43 |
|
|
|
44 |
|
|
public RedListGefaesspflanzenImportAuthor() {
|
45 |
|
|
super(tableName, pluralString);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
@Override
|
49 |
|
|
protected String getIdQuery(RedListGefaesspflanzenImportState state) {
|
50 |
|
|
return "SELECT NAMNR "
|
51 |
|
|
+ "FROM V_TAXATLAS_D20_EXPORT t "
|
52 |
|
|
+ " ORDER BY NAMNR";
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
@Override
|
56 |
|
|
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
|
57 |
|
|
String result = " SELECT * "
|
58 |
|
|
+ " FROM V_TAXATLAS_D20_EXPORT t "
|
59 |
|
|
+ " WHERE t.NAMNR IN (@IDSET)";
|
60 |
|
|
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
|
61 |
|
|
return result;
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
@Override
|
65 |
|
|
protected void doInvoke(RedListGefaesspflanzenImportState state) {
|
66 |
4fe9a46d
|
Patrick Plitzner
|
makeAuthors(state, RedListUtil.AUTOR_KOMB);
|
67 |
|
|
makeAuthors(state, RedListUtil.AUTOR_BASI);
|
68 |
e8c5db35
|
Patrick Plitzner
|
}
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
@Override
|
72 |
|
|
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
73 |
|
|
return true;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
7319c528
|
Patrick Plitzner
|
private void makeAuthors(RedListGefaesspflanzenImportState state, String columnName) {
|
77 |
|
|
|
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 |
27d23ab7
|
Patrick Plitzner
|
if(CdmUtils.isNotBlank(authorName)){
|
87 |
b4b7ae12
|
Patrick Plitzner
|
makePerson(state, authorName);
|
88 |
e965dc89
|
Patrick Plitzner
|
}
|
89 |
|
|
}
|
90 |
7319c528
|
Patrick Plitzner
|
} catch (SQLException e) {
|
91 |
|
|
e.printStackTrace();
|
92 |
e8c5db35
|
Patrick Plitzner
|
}
|
93 |
|
|
}
|
94 |
|
|
|
95 |
b4b7ae12
|
Patrick Plitzner
|
private void makePerson(RedListGefaesspflanzenImportState state, String authorName) {
|
96 |
94adeb1d
|
Patrick Plitzner
|
//check if misapplied name
|
97 |
b37b6a0f
|
Patrick Plitzner
|
if(authorName.trim().equals(RedListUtil.AUCT)){
|
98 |
94adeb1d
|
Patrick Plitzner
|
return;
|
99 |
|
|
}
|
100 |
b3b2515e
|
Patrick Plitzner
|
TeamOrPersonBase<?> teamOrPerson;
|
101 |
b4b7ae12
|
Patrick Plitzner
|
//check if there are ex authors
|
102 |
4fe9a46d
|
Patrick Plitzner
|
if(authorName.contains(RedListUtil.EX)){
|
103 |
|
|
String[] split = authorName.split(RedListUtil.EX);
|
104 |
b4b7ae12
|
Patrick Plitzner
|
for (int i = 0; i < split.length; i++) {
|
105 |
|
|
makePerson(state, split[i].trim());
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
//check if it is a team
|
109 |
|
|
if(authorName.contains("&")){
|
110 |
|
|
teamOrPerson = Team.NewInstance();
|
111 |
|
|
String[] split = authorName.split("&");
|
112 |
|
|
for (int i = 0; i < split.length; i++) {
|
113 |
|
|
((Team) teamOrPerson).addTeamMember(Person.NewTitledInstance(split[i].trim()));
|
114 |
|
|
}
|
115 |
|
|
}
|
116 |
|
|
else{
|
117 |
|
|
teamOrPerson = Person.NewTitledInstance(authorName);
|
118 |
|
|
}
|
119 |
|
|
getAgentService().saveOrUpdate(teamOrPerson);
|
120 |
|
|
state.getAuthorMap().put(authorName, teamOrPerson.getUuid());
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
|
124 |
e8c5db35
|
Patrick Plitzner
|
@Override
|
125 |
|
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
126 |
|
|
RedListGefaesspflanzenImportState state) {
|
127 |
|
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
128 |
|
|
return result;
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
@Override
|
132 |
|
|
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
133 |
|
|
return false;
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
@Override
|
137 |
|
|
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
138 |
|
|
return false;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
}
|