Revision 2d481abb
Added by Katja Luther almost 10 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaUsersImport.java | ||
---|---|---|
19 | 19 |
import java.util.UUID; |
20 | 20 |
|
21 | 21 |
import org.apache.log4j.Logger; |
22 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|
23 |
import org.springframework.security.core.userdetails.UserDetails; |
|
22 | 24 |
import org.springframework.stereotype.Component; |
23 | 25 |
import org.springframework.transaction.TransactionStatus; |
26 |
import org.springframework.transaction.support.DefaultTransactionDefinition; |
|
24 | 27 |
|
25 | 28 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator; |
26 | 29 |
import eu.etaxonomy.cdm.io.common.ImportHelper; |
... | ... | |
45 | 48 |
|
46 | 49 |
/* Interval for progress info message when retrieving taxa */ |
47 | 50 |
private int modCount = 10000; |
51 |
|
|
52 |
protected DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition(); |
|
48 | 53 |
|
49 | 54 |
/* (non-Javadoc) |
50 | 55 |
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator) |
... | ... | |
81 | 86 |
logger.warn("Start User doInvoke"); |
82 | 87 |
ProfilerController.memorySnapshot(); |
83 | 88 |
*/ |
89 |
|
|
84 | 90 |
TransactionStatus txStatus = null; |
85 | 91 |
Map<String, AgentBase<?>> persons = null; |
86 |
Map<Integer, User> users= null; |
|
92 |
Map<String, User> users= null; |
|
93 |
Map<Integer, Reference> references = null; |
|
87 | 94 |
Map<Integer, UUID> userUuids = new HashMap<Integer, UUID>(); |
88 | 95 |
int limit = state.getConfig().getLimitSave(); |
89 |
|
|
96 |
//this.authenticate("admin", "00000"); |
|
97 |
|
|
90 | 98 |
FaunaEuropaeaImportConfigurator fauEuConfig = state.getConfig(); |
91 | 99 |
Source source = fauEuConfig.getSource(); |
92 | 100 |
|
... | ... | |
117 | 125 |
} |
118 | 126 |
|
119 | 127 |
while (rsUser.next()){ |
120 |
int userId = rsUser.getInt("usr_id");
|
|
128 |
int refId = rsUser.getInt("usr_id");
|
|
121 | 129 |
String userTitle = rsUser.getString("usr_title"); |
122 | 130 |
String userFirstname = rsUser.getString("usr_firstname"); |
123 | 131 |
String userLastname = rsUser.getString("usr_lastname"); |
... | ... | |
136 | 144 |
if ((userTitle != null || userFirstname != null) && userLastname != null) { |
137 | 145 |
userPerson += " " + userLastname; |
138 | 146 |
} |
139 |
|
|
147 |
this.authenticate("admin", "00000"); |
|
140 | 148 |
// build year |
141 | 149 |
String year = null; |
142 | 150 |
if (createdDate != null) { |
... | ... | |
147 | 155 |
|
148 | 156 |
txStatus = startTransaction(); |
149 | 157 |
persons= new HashMap<String,AgentBase<?>>(limit); |
150 |
users = new HashMap<Integer,User>(limit); |
|
158 |
users = new HashMap<String,User>(limit); |
|
159 |
references = new HashMap<Integer, Reference>(limit); |
|
151 | 160 |
|
152 | 161 |
if(logger.isInfoEnabled()) { |
153 | 162 |
logger.info("i = " + i + " - User import transaction started"); |
... | ... | |
156 | 165 |
|
157 | 166 |
AgentBase<?> person = null; |
158 | 167 |
User user = null; |
159 |
person= Person.NewTitledInstance(userTitle); |
|
168 |
Reference reference = null; |
|
169 |
person= Person.NewTitledInstance(userPerson); |
|
160 | 170 |
user = User.NewInstance(userPerson, userPwd); |
161 |
//reference.setTitle("" + refId); // This unique key is needed to get a hand on this Reference in PesiTaxonExport |
|
162 |
//reference.setDatePublished(ImportHelper.getDatePublished(year)); |
|
171 |
reference = ReferenceFactory.newGeneric(); |
|
172 |
reference.setTitle("" + refId); // This unique key is needed to get a hand on this Reference in PesiTaxonExport |
|
173 |
reference.setDatePublished(ImportHelper.getDatePublished(year)); |
|
174 |
|
|
163 | 175 |
|
164 | 176 |
if (!persons.containsKey(userPerson)) { |
165 | 177 |
if (userPerson == null) { |
... | ... | |
175 | 187 |
} else { |
176 | 188 |
person = persons.get(userPerson); |
177 | 189 |
if (logger.isDebugEnabled()) { |
178 |
logger.debug("Not imported user with duplicated user_id (" + userId +
|
|
190 |
logger.debug("Not imported user with duplicated ref_id (" + refId +
|
|
179 | 191 |
") " + userPerson); |
180 | 192 |
} |
181 | 193 |
} |
182 | 194 |
|
183 | 195 |
// set protected titleCache |
184 |
/*StringBuilder referenceTitleCache = new StringBuilder(user.getTitleCache() + ".");
|
|
196 |
StringBuilder referenceTitleCache = new StringBuilder(person.getTitleCache() + ".");
|
|
185 | 197 |
if (year != null) { |
186 | 198 |
referenceTitleCache.append(" " + year); |
187 | 199 |
} |
188 | 200 |
reference.setTitleCache(referenceTitleCache.toString(), true); |
189 | 201 |
|
190 |
reference.setAuthorTeam(author);*/
|
|
202 |
reference.setAuthorTeam((TeamOrPersonBase)person);
|
|
191 | 203 |
|
192 | 204 |
//ImportHelper.setOriginalSource(user, fauEuConfig.getSourceReference(), userId, namespace); |
193 |
ImportHelper.setOriginalSource(person, fauEuConfig.getSourceReference(), userId, namespace);
|
|
205 |
ImportHelper.setOriginalSource(person, fauEuConfig.getSourceReference(), refId, namespace);
|
|
194 | 206 |
|
195 | 207 |
|
196 | 208 |
// Store persons |
197 |
if (!users.containsKey(userId)) {
|
|
209 |
if (!users.containsKey(userPerson)) {
|
|
198 | 210 |
|
199 | 211 |
if (user == null) { |
200 | 212 |
logger.warn("User is null"); |
201 | 213 |
} |
202 |
users.put(userId, user);
|
|
214 |
users.put(userPerson, user);
|
|
203 | 215 |
if (logger.isTraceEnabled()) { |
204 |
logger.trace("Stored user (" + userTitle + ")");
|
|
216 |
logger.trace("Stored user (" + userPerson + ")");
|
|
205 | 217 |
} |
206 | 218 |
} else { |
207 | 219 |
if (logger.isDebugEnabled()) { |
208 |
logger.debug("Duplicated user(" + userId + ", " + userTitle+ ")");
|
|
220 |
logger.debug("Duplicated user(" + userPerson +")");
|
|
209 | 221 |
} |
210 | 222 |
//continue; |
211 | 223 |
} |
212 | 224 |
|
213 | 225 |
if (((i % limit) == 0 && i > 1 ) || i == count ) { |
214 | 226 |
|
215 |
commitUsers(txStatus, persons, users, |
|
227 |
commitUsers(txStatus, persons, users, references,
|
|
216 | 228 |
userUuids, i); |
217 | 229 |
|
218 | 230 |
users = null; |
... | ... | |
221 | 233 |
|
222 | 234 |
} |
223 | 235 |
if (users != null){ |
224 |
commitUsers(txStatus, persons, users, userUuids, i); |
|
236 |
commitUsers(txStatus, persons, users, references, userUuids, i);
|
|
225 | 237 |
users = null; |
226 | 238 |
persons= null; |
227 | 239 |
} |
... | ... | |
240 | 252 |
|
241 | 253 |
private void commitUsers(TransactionStatus txStatus, |
242 | 254 |
Map<String, AgentBase<?>> persons, |
243 |
Map<Integer, User> users, |
|
255 |
Map<String, User> users, |
|
256 |
Map<Integer, Reference> references, |
|
244 | 257 |
Map<Integer, UUID> userUuids, int i) { |
258 |
|
|
245 | 259 |
Map<UUID, AgentBase> userMap =getAgentService().save((Collection)persons.values()); |
246 |
logger.info("i = " + i + " - users saved"); |
|
247 |
|
|
260 |
logger.info("i = " + i + " - persons saved"); |
|
261 |
|
|
262 |
|
|
263 |
|
|
248 | 264 |
Iterator<Entry<UUID, AgentBase>> it = userMap.entrySet().iterator(); |
249 | 265 |
while (it.hasNext()){ |
250 | 266 |
AgentBase person = it.next().getValue(); |
... | ... | |
254 | 270 |
} |
255 | 271 |
|
256 | 272 |
getUserService().save((Collection)users.values()); |
273 |
logger.info("i = " + users.size() + " - users saved"); |
|
274 |
//getReferenceService().save(references.values()); |
|
275 |
//logger.info("i = " +references.size() + " - references saved"); |
|
257 | 276 |
commitTransaction(txStatus); |
258 | 277 |
} |
259 | 278 |
|
Also available in: Unified diff
changes in Fauna Europeae Import and Index Fungorum Import and PESI Export