1
|
// $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
|
import eu.etaxonomy.cdm.model.agent.Team;
|
26
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
27
|
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
|
|
38
|
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
|
makeAuthors(state, RedListUtil.AUTOR_KOMB);
|
67
|
makeAuthors(state, RedListUtil.AUTOR_BASI);
|
68
|
}
|
69
|
|
70
|
|
71
|
@Override
|
72
|
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
73
|
return true;
|
74
|
}
|
75
|
|
76
|
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
|
TeamOrPersonBase teamOrPerson = null;
|
87
|
if(CdmUtils.isNotBlank(authorName)){
|
88
|
makePerson(state, authorName);
|
89
|
}
|
90
|
}
|
91
|
} catch (SQLException e) {
|
92
|
e.printStackTrace();
|
93
|
}
|
94
|
}
|
95
|
|
96
|
private void makePerson(RedListGefaesspflanzenImportState state, String authorName) {
|
97
|
//check if misapplied name
|
98
|
if(authorName.trim().equals(RedListUtil.AUCT)){
|
99
|
return;
|
100
|
}
|
101
|
TeamOrPersonBase teamOrPerson;
|
102
|
//check if there are ex authors
|
103
|
if(authorName.contains(RedListUtil.EX)){
|
104
|
String[] split = authorName.split(RedListUtil.EX);
|
105
|
for (int i = 0; i < split.length; i++) {
|
106
|
makePerson(state, split[i].trim());
|
107
|
}
|
108
|
}
|
109
|
//check if it is a team
|
110
|
if(authorName.contains("&")){
|
111
|
teamOrPerson = Team.NewInstance();
|
112
|
String[] split = authorName.split("&");
|
113
|
for (int i = 0; i < split.length; i++) {
|
114
|
((Team) teamOrPerson).addTeamMember(Person.NewTitledInstance(split[i].trim()));
|
115
|
}
|
116
|
}
|
117
|
else{
|
118
|
teamOrPerson = Person.NewTitledInstance(authorName);
|
119
|
}
|
120
|
getAgentService().saveOrUpdate(teamOrPerson);
|
121
|
state.getAuthorMap().put(authorName, teamOrPerson.getUuid());
|
122
|
}
|
123
|
|
124
|
|
125
|
@Override
|
126
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
127
|
RedListGefaesspflanzenImportState state) {
|
128
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
129
|
return result;
|
130
|
}
|
131
|
|
132
|
@Override
|
133
|
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
134
|
return false;
|
135
|
}
|
136
|
|
137
|
@Override
|
138
|
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
139
|
return false;
|
140
|
}
|
141
|
|
142
|
}
|