15
15
16
16
package au.org.ala.specieslist
17
17
18
-
18
+ import groovy.time.*
19
19
import org.hibernate.Criteria
20
20
import org.hibernate.criterion.CriteriaQuery
21
21
import org.hibernate.criterion.Order
@@ -180,9 +180,11 @@ class QueryService {
180
180
if (query){
181
181
selectedFacets << [query : key, facet : query]
182
182
} else if (key == LIST_TYPE ){
183
- def cleanedVaue = value. replaceAll(" eq:" , " " )
184
- query = listTyoeFacets. get(cleanedVaue)
185
- selectedFacets << [query : key, facet : query]
183
+ if (value) {
184
+ def cleanedValue = value. replaceAll(" eq:" , " " )
185
+ query = listTyoeFacets. get(cleanedValue)
186
+ selectedFacets << [query : key, facet : query]
187
+ }
186
188
} else if (key == WKT ){
187
189
query = WKT_QUERY
188
190
selectedFacets << [query : WKT , facet : [label :' spatialBounds.list.label' ]]
@@ -445,8 +447,38 @@ class QueryService {
445
447
order = order ?: ASC
446
448
c. order(new Order (sort, ASC . equalsIgnoreCase(order)))
447
449
}
450
+ /*
451
+ * Retrieves the species list items by given guid.
452
+ *
453
+ * @param queryParams : only supports: max, offset, sort
454
+ * @param guid
455
+ * @param isBIE
456
+ * @param lists: data resource ids
457
+ * @return
458
+ */
459
+ def getListForSpecies (guid , isBIE , lists , queryParams ) {
460
+ def speciesListProperties = getSpeciesListProperties()
461
+ def c = SpeciesListItem . createCriteria()
462
+
463
+ def results = c. list(queryParams) {
464
+ eq(GUID , guid)
465
+ if (isBIE) {
466
+ mylist {
467
+ eq(" isBIE" , isBIE. toBoolean())
468
+ }
469
+ }
470
+ if (lists) {
471
+ ' in' (DATA_RESOURCE_UID , lists)
472
+ }
473
+ }
474
+ return results
475
+ }
448
476
449
477
/**
478
+ * @Todo
479
+ * Fix bug when param: max is set
480
+ * @See issue #271
481
+ *
450
482
* retrieves the species list items that obey the supplied filters.
451
483
*
452
484
* When a distinct field is provided the values of the field are returned rather than a SpeciesListItem
@@ -461,6 +493,9 @@ class QueryService {
461
493
def speciesListProperties = getSpeciesListProperties()
462
494
def c = SpeciesListItem . createCriteria()
463
495
496
+ // params – pagination parameters (max, offset, etc...) closure – The closure to execute
497
+ // sort, max, offset
498
+ // max parameter does not work, @see #271
464
499
c. list(props + = params) {
465
500
// set the results transformer so that we don't get duplicate records because of
466
501
// the 1:many relationship between a list item and KVP
@@ -513,6 +548,7 @@ class QueryService {
513
548
}
514
549
}
515
550
}
551
+
516
552
}
517
553
}
518
554
@@ -793,12 +829,14 @@ class QueryService {
793
829
queryParameters. qCommonName = ' %' + q+ ' %'
794
830
queryParameters. qRawScientificName = ' %' + q+ ' %'
795
831
}
796
-
832
+ def timeStart = new Date ()
797
833
def results = SpeciesListItem . executeQuery(" select kvp.key, kvp.value, kvp.vocabValue, count(sli) as cnt from SpeciesListItem as sli " +
798
834
" join sli.kvpValues as kvp where sli.dataResourceUid = :druid ${ ids ? 'and sli.id in (:ids)' : ''} " +
799
835
" ${ q ? 'and (sli.matchedName like :qMatchedName or sli.commonName like :qCommonName or sli.rawScientificName like :qRawScientificName) ' : ''} " +
800
836
" group by kvp.key, kvp.value, kvp.vocabValue, kvp.itemOrder, kvp.key order by kvp.itemOrder, kvp.key, cnt desc" ,
801
837
queryParameters)
838
+ def timeStop = new Date ()
839
+ log. info(" Query KVP of " + fqs + " took " + TimeCategory . minus(timeStop, timeStart))
802
840
803
841
// obtain the families from the common list facets
804
842
def commonResults = SpeciesListItem . executeQuery(" select sli.family, count(sli) as cnt from SpeciesListItem sli " +
@@ -816,15 +854,15 @@ class QueryService {
816
854
} else {
817
855
def qParam = ' %' + q+ ' %'
818
856
def queryParameters = q ? [dataResourceUid : id, matchedName : qParam, commonName : qParam, rawScientificName : qParam] : [dataResourceUid : id]
819
-
857
+ def timeStart = new Date ()
820
858
def results = SpeciesListItem . executeQuery(' select kvp.key, kvp.value, kvp.vocabValue, count(sli) as cnt from SpeciesListItem as sli ' +
821
859
' join sli.kvpValues as kvp where sli.dataResourceUid = :dataResourceUid ' +
822
860
" ${ q ? 'and (sli.matchedName like :matchedName or sli.commonName like :commonName or sli.rawScientificName like :rawScientificName) ' : ''} " +
823
861
' group by kvp.key, kvp.value, kvp.vocabValue, kvp.itemOrder order by kvp.itemOrder, kvp.key, cnt desc' ,
824
862
queryParameters)
825
-
863
+ def timeStop = new Date ()
864
+ log. info(" Query KVP of " + id + " took " + TimeCategory . minus(timeStop, timeStart))
826
865
properties = results. findAll{it[1 ]. length()< maxLengthForFacet}. groupBy{it[0 ]}. findAll{it. value. size()> 1 }
827
-
828
866
// obtain the families from the common list facets
829
867
def commonResults = SpeciesListItem . executeQuery(' select family, count(*) as cnt from SpeciesListItem ' +
830
868
' where family is not null AND dataResourceUid = :dataResourceUid ' +
0 commit comments