1
|
/**
|
2
|
* Copyright (C) 2016 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.io.redlist.gefaesspflanzen;
|
10
|
|
11
|
import java.sql.ResultSet;
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
|
19
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
20
|
import eu.etaxonomy.cdm.io.common.DbImportBase;
|
21
|
import eu.etaxonomy.cdm.io.common.IPartitionedIO;
|
22
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
23
|
import eu.etaxonomy.cdm.model.agent.Person;
|
24
|
import eu.etaxonomy.cdm.model.agent.Team;
|
25
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
|
28
|
/**
|
29
|
* @author pplitzner
|
30
|
* @date Feb 29, 2016
|
31
|
*
|
32
|
*/
|
33
|
@Component
|
34
|
@SuppressWarnings("serial")
|
35
|
public class RedListGefaesspflanzenImportAuthor extends DbImportBase<RedListGefaesspflanzenImportState, RedListGefaesspflanzenImportConfigurator> {
|
36
|
|
37
|
private static final Logger logger = Logger.getLogger(RedListGefaesspflanzenImportAuthor.class);
|
38
|
|
39
|
private static final String tableName = "Rote Liste Gefäßpflanzen";
|
40
|
|
41
|
private static final String pluralString = "authors";
|
42
|
|
43
|
public RedListGefaesspflanzenImportAuthor() {
|
44
|
super(tableName, pluralString);
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
protected String getIdQuery(RedListGefaesspflanzenImportState state) {
|
49
|
return "SELECT SEQNUM "
|
50
|
+ "FROM V_TAXATLAS_D20_EXPORT t "
|
51
|
+ " ORDER BY SEQNUM";
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
|
56
|
String result = " SELECT * "
|
57
|
+ " FROM V_TAXATLAS_D20_EXPORT t "
|
58
|
+ " WHERE t.SEQNUM IN (@IDSET)";
|
59
|
result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
|
60
|
return result;
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
protected void doInvoke(RedListGefaesspflanzenImportState state) {
|
65
|
makeAuthors(state, RedListUtil.AUTOR_KOMB);
|
66
|
makeAuthors(state, RedListUtil.AUTOR_BASI);
|
67
|
}
|
68
|
|
69
|
|
70
|
@Override
|
71
|
public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
|
72
|
return true;
|
73
|
}
|
74
|
|
75
|
private void makeAuthors(RedListGefaesspflanzenImportState state, String columnName) {
|
76
|
|
77
|
String query = "select distinct "+columnName+" from V_TAXATLAS_D20_EXPORT t"
|
78
|
+ " WHERE TRIM(t."+columnName+") <>''";
|
79
|
|
80
|
ResultSet rs = state.getConfig().getSource().getResultSet(query);
|
81
|
|
82
|
try{
|
83
|
while(rs.next()){
|
84
|
String authorName = rs.getString(columnName);
|
85
|
if(CdmUtils.isNotBlank(authorName)){
|
86
|
makePerson(state, authorName);
|
87
|
}
|
88
|
}
|
89
|
} catch (SQLException e) {
|
90
|
e.printStackTrace();
|
91
|
}
|
92
|
}
|
93
|
|
94
|
private void makePerson(RedListGefaesspflanzenImportState state, String authorName) {
|
95
|
//check if misapplied name
|
96
|
if(authorName.trim().equals(RedListUtil.AUCT)){
|
97
|
return;
|
98
|
}
|
99
|
TeamOrPersonBase<?> teamOrPerson;
|
100
|
//check if there are ex authors
|
101
|
if(authorName.contains(RedListUtil.EX)){
|
102
|
String author = RedListUtil.getAuthorOfExAuthorshipString(authorName);
|
103
|
String exAuthor = RedListUtil.getExAuthorOfExAuthorshipString(authorName);
|
104
|
makePerson(state, author);
|
105
|
makePerson(state, exAuthor);
|
106
|
}
|
107
|
//check if it is a team
|
108
|
if(authorName.contains("&")){
|
109
|
teamOrPerson = Team.NewInstance();
|
110
|
String[] split = authorName.split("&");
|
111
|
for (int i = 0; i < split.length; i++) {
|
112
|
((Team) teamOrPerson).addTeamMember(Person.NewTitledInstance(split[i].trim()));
|
113
|
}
|
114
|
}
|
115
|
else{
|
116
|
teamOrPerson = Person.NewTitledInstance(authorName);
|
117
|
}
|
118
|
getAgentService().saveOrUpdate(teamOrPerson);
|
119
|
state.getAuthorMap().put(authorName, teamOrPerson.getUuid());
|
120
|
}
|
121
|
|
122
|
|
123
|
@Override
|
124
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs,
|
125
|
RedListGefaesspflanzenImportState state) {
|
126
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
|
127
|
return result;
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
protected boolean doCheck(RedListGefaesspflanzenImportState state) {
|
132
|
return false;
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
protected boolean isIgnore(RedListGefaesspflanzenImportState state) {
|
137
|
return false;
|
138
|
}
|
139
|
|
140
|
}
|