1
|
/**
|
2
|
* Copyright (C) 2007 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.pesi.faunaEuropaea;
|
10
|
|
11
|
import java.sql.ResultSet;
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.Collection;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
import org.springframework.transaction.TransactionStatus;
|
19
|
|
20
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
21
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
22
|
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
23
|
import eu.etaxonomy.cdm.io.common.Source;
|
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
|
/**
|
30
|
* @author a.babadshanjan
|
31
|
* @created 12.05.2009
|
32
|
* @version 1.0
|
33
|
*/
|
34
|
@Component
|
35
|
public class FaunaEuropaeaAuthorImport extends FaunaEuropaeaImportBase {
|
36
|
private static final Logger logger = Logger.getLogger(FaunaEuropaeaAuthorImport.class);
|
37
|
|
38
|
private static int modCount = 1000;
|
39
|
|
40
|
|
41
|
/* (non-Javadoc)
|
42
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
43
|
*/
|
44
|
@Override
|
45
|
protected boolean doCheck(FaunaEuropaeaImportState state){
|
46
|
boolean result = true;
|
47
|
logger.warn("No checking for Authors not implemented");
|
48
|
|
49
|
return result;
|
50
|
}
|
51
|
|
52
|
/* (non-Javadoc)
|
53
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
|
54
|
*/
|
55
|
@Override
|
56
|
protected void doInvoke(FaunaEuropaeaImportState state){
|
57
|
Map<String, MapWrapper<? extends CdmBase>> stores = state.getStores();
|
58
|
MapWrapper<TeamOrPersonBase> authorStore = (MapWrapper<TeamOrPersonBase>)stores.get(ICdmIO.TEAM_STORE);
|
59
|
TransactionStatus txStatus = null;
|
60
|
|
61
|
FaunaEuropaeaImportConfigurator fauEuConfig = state.getConfig();
|
62
|
Source source = fauEuConfig.getSource();
|
63
|
|
64
|
String namespace = "AuthorTeam";
|
65
|
boolean success = true;
|
66
|
|
67
|
if(logger.isInfoEnabled()) { logger.info("Start making Authors..."); }
|
68
|
|
69
|
try {
|
70
|
|
71
|
String strQuery =
|
72
|
" SELECT * " +
|
73
|
" FROM author " ;
|
74
|
ResultSet rs = source.getResultSet(strQuery) ;
|
75
|
|
76
|
int i = 0;
|
77
|
while (rs.next()) {
|
78
|
|
79
|
if ((i++ % modCount) == 0 && i!= 1 ) {
|
80
|
if(logger.isInfoEnabled()) {
|
81
|
logger.info("Authors retrieved: " + (i-1));
|
82
|
}
|
83
|
}
|
84
|
|
85
|
int authorId = rs.getInt("aut_id");
|
86
|
String authorName = rs.getString("aut_name");
|
87
|
|
88
|
TeamOrPersonBase<Team> author = null;
|
89
|
|
90
|
try {
|
91
|
author = Team.NewInstance();
|
92
|
author.setTitleCache(authorName, true);
|
93
|
|
94
|
ImportHelper.setOriginalSource(author, fauEuConfig.getSourceReference(), authorId, namespace);
|
95
|
|
96
|
if (!authorStore.containsId(authorId)) {
|
97
|
if (author == null) {
|
98
|
logger.warn("Author is null");
|
99
|
}
|
100
|
authorStore.put(authorId, author);
|
101
|
if (logger.isDebugEnabled()) {
|
102
|
logger.debug("Stored author (" + authorId + ") " + authorName);
|
103
|
}
|
104
|
} else {
|
105
|
logger.warn("Not imported author with duplicated aut_id (" + authorId +
|
106
|
") " + authorName);
|
107
|
}
|
108
|
} catch (Exception e) {
|
109
|
logger.warn("An exception occurred when creating author with id " + authorId +
|
110
|
". Author could not be saved.");
|
111
|
}
|
112
|
}
|
113
|
|
114
|
if(logger.isInfoEnabled()) { logger.info("Saving authors ..."); }
|
115
|
|
116
|
txStatus = startTransaction();
|
117
|
|
118
|
// save authors
|
119
|
getAgentService().save((Collection)authorStore.objects());
|
120
|
|
121
|
commitTransaction(txStatus);
|
122
|
|
123
|
if(logger.isInfoEnabled()) { logger.info("End making authors ..."); }
|
124
|
|
125
|
return;
|
126
|
|
127
|
} catch (SQLException e) {
|
128
|
logger.error("SQLException:" + e);
|
129
|
state.setUnsuccessfull();
|
130
|
}
|
131
|
}
|
132
|
|
133
|
/* (non-Javadoc)
|
134
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
135
|
*/
|
136
|
protected boolean isIgnore(FaunaEuropaeaImportState state){
|
137
|
return ! state.getConfig().isDoAuthors();
|
138
|
}
|
139
|
|
140
|
}
|