Revision e28756b0
Added by Andreas Kohlbecker over 6 years ago
src/main/java/eu/etaxonomy/cdm/dataInserter/RegistrationRequiredDataInserter.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import org.apache.log4j.Logger; |
23 | 23 |
import org.joda.time.DateTime; |
24 |
import org.joda.time.DateTimeFieldType; |
|
24 | 25 |
import org.joda.time.Partial; |
25 | 26 |
import org.joda.time.format.DateTimeFormatter; |
26 | 27 |
import org.springframework.context.event.ContextRefreshedEvent; |
... | ... | |
236 | 237 |
if(wipeoutCmd != null && wipeoutCmd.matches("iapt|all")){ |
237 | 238 |
|
238 | 239 |
boolean onlyIapt = wipeoutCmd.equals("iapt"); |
239 |
List<UUID> deleteCandidates = new ArrayList<UUID>();
|
|
240 |
Set<UUID> deleteCandidates = new HashSet<UUID>();
|
|
240 | 241 |
|
241 | 242 |
TransactionStatus tx = repo.startTransaction(true); |
242 | 243 |
List<Registration> allRegs = repo.getRegistrationService().list(null, null, null, null, null); |
... | ... | |
245 | 246 |
try { |
246 | 247 |
@SuppressWarnings("unchecked") |
247 | 248 |
Set<String> extensions = reg.getName().getExtensions(getExtensionTypeIAPTRegData()); |
248 |
deleteCandidates.add(reg.getUuid()); |
|
249 |
if(reg.getUuid() != null){ |
|
250 |
deleteCandidates.add(reg.getUuid()); |
|
251 |
} |
|
249 | 252 |
} catch(NullPointerException e){ |
250 | 253 |
// IGNORE |
251 | 254 |
} |
252 | 255 |
} else { |
253 |
deleteCandidates.add(reg.getUuid()); |
|
256 |
if(reg.getUuid() != null){ |
|
257 |
deleteCandidates.add(reg.getUuid()); |
|
258 |
} |
|
254 | 259 |
} |
255 | 260 |
} |
256 | 261 |
repo.commitTransaction(tx); |
257 | 262 |
if(!deleteCandidates.isEmpty()){ |
258 |
repo.getRegistrationService().delete(deleteCandidates); |
|
263 |
try { |
|
264 |
repo.getRegistrationService().delete(deleteCandidates); |
|
265 |
} catch (Exception e) { |
|
266 |
// MySQLIntegrityConstraintViolationException happens here every second run !!! |
|
267 |
logger.error(e); |
|
268 |
} |
|
259 | 269 |
} |
260 | 270 |
} |
261 | 271 |
|
... | ... | |
275 | 285 |
List<Registration> newRegs = new ArrayList<>(pager.getRecords().size()); |
276 | 286 |
for(TaxonName name : pager.getRecords()){ |
277 | 287 |
|
288 |
|
|
289 |
|
|
278 | 290 |
Set<String> extensionValues = name.getExtensions(getExtensionTypeIAPTRegData()); |
279 | 291 |
|
280 | 292 |
// there is for sure only one |
281 | 293 |
if(extensionValues.isEmpty()){ |
282 | 294 |
continue; |
283 | 295 |
} |
296 |
|
|
297 |
logger.debug("IAPT Registration for " + name.getTitleCache() + " ..."); |
|
298 |
|
|
284 | 299 |
String iaptJson = extensionValues.iterator().next(); |
285 | 300 |
try { |
286 | 301 |
|
... | ... | |
313 | 328 |
reg.setSpecificIdentifier(iaptData.getRegId().toString()); |
314 | 329 |
reg.setInstitution(getInstitution(iaptData.getOffice())); |
315 | 330 |
|
316 |
boolean isPhycobankID = false; // Integer.valueOf(reg.getSpecificIdentifier()) >= 100000;
|
|
331 |
boolean isPhycobankID = Integer.valueOf(reg.getSpecificIdentifier()) >= 100000; |
|
317 | 332 |
|
318 | 333 |
Partial youngestDate = null; |
319 | 334 |
Reference youngestPub = null; |
... | ... | |
333 | 348 |
continue; |
334 | 349 |
} |
335 | 350 |
Partial pubdate = partial(td.getCitation().getDatePublished()); |
336 |
if(youngestDate.compareTo(pubdate) < 0){ |
|
351 |
if(pubdate != null){ |
|
352 |
if(youngestDate== null || comparePartials(youngestDate, pubdate)){ |
|
337 | 353 |
youngestDate = pubdate; |
338 | 354 |
youngestPub = td.getCitation(); |
339 | 355 |
} |
356 |
} |
|
340 | 357 |
} |
341 | 358 |
} |
342 | 359 |
} |
... | ... | |
363 | 380 |
reg.setTypeDesignations(typeDesignations); |
364 | 381 |
} |
365 | 382 |
reg.setRegistrationDate(regDate); |
366 |
logger.debug("IAPT Registration for " + name.getTitleCache()); |
|
367 | 383 |
newRegs.add(reg); |
368 | 384 |
|
369 | 385 |
} catch (JsonParseException e) { |
... | ... | |
385 | 401 |
} |
386 | 402 |
|
387 | 403 |
|
404 |
/** |
|
405 |
* @param youngestDate |
|
406 |
* @param pubdate |
|
407 |
* @return |
|
408 |
*/ |
|
409 |
protected boolean comparePartials(Partial youngestDate, Partial pubdate) { |
|
410 |
|
|
411 |
if(youngestDate.size() == pubdate.size()) { |
|
412 |
return youngestDate.compareTo(pubdate) < 0; |
|
413 |
} |
|
414 |
youngestDate = youngestDate.without(DateTimeFieldType.dayOfMonth()); |
|
415 |
pubdate = pubdate.without(DateTimeFieldType.dayOfMonth()); |
|
416 |
if(youngestDate.size() == pubdate.size()) { |
|
417 |
return youngestDate.compareTo(pubdate) < 0; |
|
418 |
} |
|
419 |
youngestDate = youngestDate.without(DateTimeFieldType.monthOfYear()); |
|
420 |
pubdate = pubdate.without(DateTimeFieldType.monthOfYear()); |
|
421 |
return youngestDate.compareTo(pubdate) < 0; |
|
422 |
|
|
423 |
} |
|
424 |
|
|
425 |
|
|
388 | 426 |
/** |
389 | 427 |
* @param datePublished |
390 | 428 |
* @return |
Also available in: Unified diff
fix #7055 completing creation of phycobank registrations from name extensions