15
15
package au.org.ala.specieslist
16
16
17
17
import au.org.ala.web.AuthService
18
+ import au.org.ala.names.ws.api.SearchStyle
18
19
import com.opencsv.CSVReader
19
20
import grails.converters.JSON
20
21
import grails.gorm.transactions.Transactional
@@ -30,6 +31,7 @@ class SpeciesListController {
30
31
private static final String [] ACCEPTED_CONTENT_TYPES = [" text/plain" , " text/csv" ]
31
32
32
33
HelperService helperService
34
+ ColumnMatchingService columnMatchingService
33
35
AuthService authService
34
36
BieService bieService
35
37
BiocacheService biocacheService
@@ -164,6 +166,8 @@ class SpeciesListController {
164
166
formParams. category,
165
167
formParams. generalisation,
166
168
formParams. sdsType,
169
+ formParams. looseSearch== null || formParams. looseSearch. isEmpty() ? null : Boolean . parseBoolean(formParams. looseSearch),
170
+ formParams. searchStyle == null || formParams. searchStyle. isEmpty() ? null : SearchStyle . valueOf(formParams. searchStyle),
167
171
header. split(" ," ),
168
172
vocabs)
169
173
@@ -472,6 +476,7 @@ class SpeciesListController {
472
476
while (offset < totalRows) {
473
477
List items
474
478
List guidBatch = [], sliBatch = []
479
+ Map<SpeciesList , List<SpeciesListItem > > batches = new HashMap<> ()
475
480
List<SpeciesListItem > searchBatch = new ArrayList<SpeciesListItem > ()
476
481
if (id) {
477
482
items = SpeciesListItem . findAllByDataResourceUid(id, [max : BATCH_SIZE , offset : offset])
@@ -481,23 +486,30 @@ class SpeciesListController {
481
486
482
487
SpeciesListItem . withSession { session ->
483
488
items. eachWithIndex { SpeciesListItem item , Integer i ->
489
+ SpeciesList speciesList = item. mylist
490
+ List<SpeciesListItem > batch = batches. get(speciesList)
491
+ if (batch == null ) {
492
+ batch = new ArrayList<> ();
493
+ batches. put(speciesList, batch)
494
+ }
484
495
String rawName = item. rawScientificName
485
- log. debug i + " . Rematching: " + rawName
496
+ log. debug i + " . Rematching: " + rawName + " / " + speciesList . dataResourceUid
486
497
if (rawName && rawName. length() > 0 ) {
487
- searchBatch . add(item)
498
+ batch . add(item)
488
499
} else {
489
500
item. guid = null
490
501
if (! item. save(flush : true )) {
491
502
log. error " Error saving item (" + rawName + " ): " + item. errors()
492
503
}
493
504
}
494
505
}
495
-
496
- helperService. matchAll(searchBatch)
497
- searchBatch. each {SpeciesListItem item ->
498
- if (item. guid) {
499
- guidBatch. push(item. guid)
500
- sliBatch. push(item)
506
+ batches. each { list , batch ->
507
+ helperService. matchAll(batch, list)
508
+ batch. each {SpeciesListItem item ->
509
+ if (item. guid) {
510
+ guidBatch. push(item. guid)
511
+ sliBatch. push(item)
512
+ }
501
513
}
502
514
}
503
515
@@ -522,7 +534,7 @@ class SpeciesListController {
522
534
private parseDataFromCSV (CSVReader csvReader , String separator ) {
523
535
def rawHeader = csvReader. readNext()
524
536
log. debug(rawHeader. toList()?. toString())
525
- def parsedHeader = helperService . parseHeader(rawHeader) ?: helperService. parseData(rawHeader)
537
+ def parsedHeader = columnMatchingService . parseHeader(rawHeader) ?: helperService. parseData(rawHeader)
526
538
def processedHeader = parsedHeader. header
527
539
log. debug(processedHeader?. toString())
528
540
def dataRows = new ArrayList<String []> ()
@@ -531,7 +543,7 @@ class SpeciesListController {
531
543
dataRows. add(helperService. parseRow(currentLine. toList()))
532
544
currentLine = csvReader. readNext()
533
545
}
534
- def nameColumns = helperService . speciesNameColumns + helperService . commonNameColumns
546
+ def nameColumns = columnMatchingService . speciesNameMatcher . names + columnMatchingService . commonNameMatcher . names
535
547
if (processedHeader. find {
536
548
it == " scientific name" || it == " vernacular name" || it == " common name" || it == " ambiguous name"
537
549
} && processedHeader. size() > 0 ) {
0 commit comments