Skip to content

Commit ccf928d

Browse files
committed
Release 4.4.0
#273 fix deletion of a list which has a large mount of KVP records fix bugs on params and optimise the list-item query
1 parent d64f451 commit ccf928d

File tree

10 files changed

+92
-36
lines changed

10 files changed

+92
-36
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ out
66
/.slcache
77
/logs
88
*.iml
9+
grails-app/.DS_Store
10+
grails-app/controllers/.DS_Store
11+
grails-app/controllers/au/.DS_Store
12+
grails-app/controllers/au/org/.DS_Store
13+
grails-app/controllers/au/org/ala/.DS_Store
14+
grails-app/services/.DS_Store
15+
grails-app/services/au/.DS_Store
16+
grails-app/services/au/org/.DS_Store
17+
grails-app/services/au/org/ala/.DS_Store

build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ plugins {
1616
id "com.gorylenko.gradle-git-properties" version "2.4.1"
1717
}
1818

19-
version "4.1.3"
19+
20+
version "4.4.0"
21+
2022
group "au.org.ala"
2123

2224
apply plugin:"eclipse"

grails-app/conf/application.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
---
2+
3+
logging:
4+
config: /data/specieslist-webapp/config/logback.xml
5+
26
grails:
37
profile: web
48
codegen:
@@ -135,7 +139,7 @@ dataSource:
135139
environments:
136140
development:
137141
grails:
138-
serverURL: "http://dev.ala.org.au:8080"
142+
serverURL: "http://localhost:8080"
139143
dataSource:
140144
dbCreate: none
141145
url: jdbc:mysql://localhost/specieslist?autoReconnect=true&connectTimeout=0&useUnicode=true&characterEncoding=UTF-8

grails-app/conf/logback.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
55
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
6+
<logger name="org.hibernate" level="ERROR"/>
7+
<logger name="org.grails.config" level="ERROR"/>
8+
69

710
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
811
<encoder>
@@ -11,7 +14,7 @@
1114
</encoder>
1215
</appender>
1316

14-
<root level="warn">
17+
<root level="INFO">
1518
<appender-ref ref="STDOUT" />
1619
</root>
1720
</configuration>

grails-app/controllers/au/org/ala/specieslist/SpeciesListController.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ class SpeciesListController {
8383
def sl = SpeciesList.get(params.id)
8484
if(sl){
8585
helperService.deleteDataResourceForList(sl.dataResourceUid)
86-
sl.delete(flush: true)
86+
SpeciesListItem.executeUpdate("delete from SpeciesListItem where dataResourceUid = :dataResourceUid", ["dataResourceUid": sl.dataResourceUid])
87+
SpeciesListKVP.executeUpdate("delete from SpeciesListKVP where dataResourceUid = :dataResourceUid", ["dataResourceUid": sl.dataResourceUid])
88+
SpeciesList.executeUpdate("delete from SpeciesList where dataResourceUid = :dataResourceUid", ["dataResourceUid": sl.dataResourceUid])
8789
}
8890
redirect(action: 'list')
8991
}

grails-app/controllers/au/org/ala/specieslist/WebServiceController.groovy

100644100755
+18-20
Original file line numberDiff line numberDiff line change
@@ -187,42 +187,35 @@ class WebServiceController {
187187
def getListItemsForSpecies() {
188188
def guid = params.guid.replaceFirst("https:/", "https://")
189189
def lists = params.dr?.split(",")
190-
def isBIE = params.boolean('isBIE')
191-
def props = [fetch: [kvpValues: 'join', mylist: 'join']]
192-
193-
def results = queryService.getFilterListItemResult(props, params, guid, lists, null)
190+
def queryParams = params.subMap(["max","sort","offset"])
194191

192+
def results = queryService.getListForSpecies(guid, params.isBIE, lists, queryParams )
195193
log.debug("RESULTS: " + results)
196194

197195
// fetch lists that this user has access to view
198196
def hidePrivateLists = grailsApplication.config.getProperty('publicview.hidePrivateLists', Boolean, false)
199197
def permittedPrivateLists = queryService.visibleLists(false, hidePrivateLists)
200198

201-
def filteredRecords = results.findAll { !it.mylist.isPrivate || permittedPrivateLists.contains(it.dataResourceUid) }
202-
203-
if (isBIE) {
204-
// BIE only want lists with isBIE == true
205-
filteredRecords = filteredRecords.findAll { it.mylist.isBIE }
206-
}
207-
208-
def listOfRecordMaps = filteredRecords.collect { li -> // don't output private lists
199+
def listOfRecordMaps = results.findResults {
200+
// don't output private lists
201+
(!it.mylist.isPrivate) || permittedPrivateLists.contains(it.dataResourceUid) ?
209202
[
210-
dataResourceUid: li.dataResourceUid,
211-
guid : li.guid,
203+
dataResourceUid: it.dataResourceUid,
204+
guid : it.guid,
212205
list : [
213-
username: li.mylist.username,
214-
listName: li.mylist.listName,
215-
sds : li.mylist.isSDS ?: false,
216-
isBIE : li.mylist.isBIE ?: false
206+
username: it.mylist.username,
207+
listName: it.mylist.listName,
208+
sds : it.mylist.isSDS ?: false,
209+
isBIE : it.mylist.isBIE ?: false
217210
],
218-
kvpValues : li.kvpValues.collect { kvp ->
211+
kvpValues : it.kvpValues.collect { kvp ->
219212
[
220213
key : kvp.key,
221214
value : kvp.value,
222215
vocabValue: kvp.vocabValue
223216
]
224217
}
225-
]
218+
] : null
226219
}
227220
render listOfRecordMaps as JSON
228221
}
@@ -1337,5 +1330,10 @@ class WebServiceController {
13371330
return isAllowed
13381331
}
13391332

1333+
def handleException(final Exception e ) {
1334+
log.error(e.message)
1335+
return {error: e.message}
1336+
}
1337+
13401338

13411339
}

grails-app/services/au/org/ala/specieslist/HelperService.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import org.grails.web.json.JSONArray
2828
import org.nibor.autolink.*
2929
import org.springframework.context.MessageSource
3030
import org.springframework.context.i18n.LocaleContextHolder
31+
import org.apache.http.util.EntityUtils
3132

3233
import javax.annotation.PostConstruct
3334

@@ -112,7 +113,8 @@ class HelperService {
112113
requestContentType = ContentType.JSON
113114
headers."Authorization" = "${grailsApplication.config.registryApiKey}"
114115
response.success = { resp ->
115-
log.info(resp?.toString())
116+
def result = (resp.getEntity() != null ? EntityUtils.toString(resp.getEntity()) : "")
117+
log.info("${drId} has been deleted from ${grailsApplication.config.collectory.baseURL} with ${result}")
116118
}
117119
response.failure = { resp ->
118120
log.error("Delete request for ${drId} failed with status ${resp.status}")

grails-app/services/au/org/ala/specieslist/QueryService.groovy

100644100755
+46-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package au.org.ala.specieslist
1717

18-
18+
import groovy.time.*
1919
import org.hibernate.Criteria
2020
import org.hibernate.criterion.CriteriaQuery
2121
import org.hibernate.criterion.Order
@@ -180,9 +180,11 @@ class QueryService {
180180
if (query){
181181
selectedFacets << [query: key, facet: query]
182182
} 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+
}
186188
} else if (key == WKT){
187189
query = WKT_QUERY
188190
selectedFacets << [query: WKT, facet: [label:'spatialBounds.list.label']]
@@ -445,8 +447,38 @@ class QueryService {
445447
order = order ?: ASC
446448
c.order(new Order(sort, ASC.equalsIgnoreCase(order)))
447449
}
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+
}
448476

449477
/**
478+
* @Todo
479+
* Fix bug when param: max is set
480+
* @See issue #271
481+
*
450482
* retrieves the species list items that obey the supplied filters.
451483
*
452484
* When a distinct field is provided the values of the field are returned rather than a SpeciesListItem
@@ -461,6 +493,9 @@ class QueryService {
461493
def speciesListProperties = getSpeciesListProperties()
462494
def c = SpeciesListItem.createCriteria()
463495

496+
//params – pagination parameters (max, offset, etc...) closure – The closure to execute
497+
//sort, max, offset
498+
// max parameter does not work, @see #271
464499
c.list(props += params) {
465500
//set the results transformer so that we don't get duplicate records because of
466501
// the 1:many relationship between a list item and KVP
@@ -513,6 +548,7 @@ class QueryService {
513548
}
514549
}
515550
}
551+
516552
}
517553
}
518554

@@ -793,12 +829,14 @@ class QueryService {
793829
queryParameters.qCommonName = '%'+q+'%'
794830
queryParameters.qRawScientificName = '%'+q+'%'
795831
}
796-
832+
def timeStart = new Date()
797833
def results = SpeciesListItem.executeQuery("select kvp.key, kvp.value, kvp.vocabValue, count(sli) as cnt from SpeciesListItem as sli " +
798834
"join sli.kvpValues as kvp where sli.dataResourceUid = :druid ${ids ? 'and sli.id in (:ids)' : ''} " +
799835
"${q ? 'and (sli.matchedName like :qMatchedName or sli.commonName like :qCommonName or sli.rawScientificName like :qRawScientificName) ' : ''} " +
800836
"group by kvp.key, kvp.value, kvp.vocabValue, kvp.itemOrder, kvp.key order by kvp.itemOrder, kvp.key, cnt desc",
801837
queryParameters)
838+
def timeStop = new Date()
839+
log.info("Query KVP of " + fqs + "took " + TimeCategory.minus(timeStop, timeStart))
802840

803841
//obtain the families from the common list facets
804842
def commonResults = SpeciesListItem.executeQuery("select sli.family, count(sli) as cnt from SpeciesListItem sli " +
@@ -816,15 +854,15 @@ class QueryService {
816854
} else {
817855
def qParam = '%'+q+'%'
818856
def queryParameters = q ? [dataResourceUid: id, matchedName: qParam, commonName: qParam, rawScientificName: qParam] : [dataResourceUid: id]
819-
857+
def timeStart = new Date()
820858
def results = SpeciesListItem.executeQuery('select kvp.key, kvp.value, kvp.vocabValue, count(sli) as cnt from SpeciesListItem as sli ' +
821859
'join sli.kvpValues as kvp where sli.dataResourceUid = :dataResourceUid ' +
822860
"${q ? 'and (sli.matchedName like :matchedName or sli.commonName like :commonName or sli.rawScientificName like :rawScientificName) ' : ''} " +
823861
'group by kvp.key, kvp.value, kvp.vocabValue, kvp.itemOrder order by kvp.itemOrder, kvp.key, cnt desc',
824862
queryParameters)
825-
863+
def timeStop = new Date()
864+
log.info("Query KVP of " + id + "took " + TimeCategory.minus(timeStop, timeStart))
826865
properties = results.findAll{it[1].length()<maxLengthForFacet}.groupBy{it[0]}.findAll{it.value.size()>1 }
827-
828866
//obtain the families from the common list facets
829867
def commonResults = SpeciesListItem.executeQuery('select family, count(*) as cnt from SpeciesListItem ' +
830868
'where family is not null AND dataResourceUid = :dataResourceUid ' +

grails-app/views/_speciesList.gsp

-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848
var url = "${request.contextPath}"+"/speciesList/"+action+ "/"+listId;
4949
//console.log("Dialog ACTION ITEMS",listId, url)
5050
$.post(url, function(data){
51-
//alert('Value returned from service: ' + data.uid);
52-
alert('${message(code:'admin.lists.actions.button.message.ok', default:'Action was successful!')}');
5351
window.location.reload()
5452
}).error(function(jqXHR, textStatus, error) {
5553
alert("An error occurred: " + error + " - " + jqXHR.responseText);

grails-app/views/speciesListItem/list.gsp

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
var url = "${request.contextPath}"+"/speciesList/delete/" + listId;
226226

227227
$.post(url, function(data){
228-
window.location.reload()
228+
window.location.replace("${request.contextPath}"+"/speciesList/list");
229229
}).error(function(jqXHR, textStatus, error) {
230230
alert("An error occurred: " + error + " - " + jqXHR.responseText);
231231
$(modal).modal('hide');

0 commit comments

Comments
 (0)