@@ -507,13 +507,24 @@ class SpeciesListController {
507
507
/**
508
508
* Rematches the scientific names in the supplied list
509
509
*/
510
- @Transactional
511
510
def rematch () {
511
+ long beforeId = 0
512
512
if (params. id && ! params. id. startsWith(" dr" )) {
513
513
params. id = SpeciesList . get(params. id)?. dataResourceUid
514
514
log. info(" Rematching for " + params. id)
515
515
} else {
516
- log. error(" Rematching for ALL" )
516
+ String msg = " Rematching for ALL"
517
+ if (params. beforeId) {
518
+ try {
519
+ beforeId = Long . parseLong(params. beforeId)
520
+ if ( beforeId > 0 ) {
521
+ msg = " Continue to rematch the rest of species before id: " + beforeId
522
+ }
523
+ }catch (Exception e){
524
+ }
525
+ }
526
+
527
+ log. warn(msg)
517
528
}
518
529
Integer totalRows, offset = 0 ;
519
530
String id = params. id
@@ -523,66 +534,7 @@ class SpeciesListController {
523
534
return
524
535
}
525
536
526
- if (id) {
527
- totalRows = SpeciesListItem . countByDataResourceUid(id)
528
- } else {
529
- totalRows = SpeciesListItem . count();
530
- }
531
-
532
- while (offset < totalRows) {
533
- List items
534
- List guidBatch = [], sliBatch = []
535
- Map<SpeciesList , List<SpeciesListItem > > batches = new HashMap<> ()
536
- List<SpeciesListItem > searchBatch = new ArrayList<SpeciesListItem > ()
537
- if (id) {
538
- items = SpeciesListItem . findAllByDataResourceUid(id, [max : BATCH_SIZE , offset : offset])
539
- } else {
540
- items = SpeciesListItem . list(max : BATCH_SIZE , offset : offset)
541
- }
542
-
543
- SpeciesListItem . withSession { session ->
544
- items. eachWithIndex { SpeciesListItem item , Integer i ->
545
- SpeciesList speciesList = item. mylist
546
- List<SpeciesListItem > batch = batches. get(speciesList)
547
- if (batch == null ) {
548
- batch = new ArrayList<> ();
549
- batches. put(speciesList, batch)
550
- }
551
- String rawName = item. rawScientificName
552
- log. debug i + " . Rematching: " + rawName + " /" + speciesList. dataResourceUid
553
- if (rawName && rawName. length() > 0 ) {
554
- batch. add(item)
555
- } else {
556
- item. guid = null
557
- if (! item. save(flush : true )) {
558
- log. error " Error saving item (" + rawName + " ): " + item. errors()
559
- }
560
- }
561
- }
562
- batches. each { list , batch ->
563
- helperService. matchAll(batch, list)
564
- batch. each {SpeciesListItem item ->
565
- if (item. guid) {
566
- guidBatch. push(item. guid)
567
- sliBatch. push(item)
568
- }
569
- }
570
- }
571
-
572
- if (! guidBatch. isEmpty()) {
573
- helperService. getCommonNamesAndUpdateRecords(sliBatch, guidBatch)
574
- }
575
-
576
- session. flush()
577
- session. clear()
578
- }
579
-
580
- offset + = BATCH_SIZE ;
581
- log. info(" Rematched ${ offset} of ${ totalRows} - ${ Math.round(offset * 100 / totalRows)} % complete" )
582
- if (offset > totalRows) {
583
- log. error(" Rematched ${ offset} of ${ totalRows} - ${ Math.round(offset * 100 / totalRows)} % complete" )
584
- }
585
- }
537
+ helperService. rematch(id,beforeId)
586
538
587
539
render(text : " ${ message(code: 'admin.lists.page.button.rematch.messages', default: 'Rematch complete')} " )
588
540
}
0 commit comments