Skip to content

Commit

Permalink
Merge pull request #250 from AtlasOfLivingAustralia/add_date_fields
Browse files Browse the repository at this point in the history
Add lastMatched species list date
  • Loading branch information
adam-collins authored Jun 11, 2023
2 parents aa40933 + 3d9593b commit e2768a2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class EditorController {
@Transactional
def editRecord() {
def sli = SpeciesListItem.get(params.id)

def sl = sli.mylist

if (!isCurrentUserEditorForList(SpeciesList.findByDataResourceUid(sli.dataResourceUid))) {
render(text: "You are not authorised to access this page", status: 403 )
return
Expand All @@ -177,6 +180,7 @@ class EditorController {
// old value was not empty - remove from this SLI
sli.removeFromKvpValues(kvp)
kvpRemoveList.add(kvp)
sl.lastUploaded = new Date()
}

if (params[key]) {
Expand Down Expand Up @@ -217,6 +221,7 @@ class EditorController {
if (changed) {
log.debug "re-matching name for ${params.rawScientificName}"
helperService.matchNameToSpeciesListItem(sli.rawScientificName, sli, sli.mylist)
sl.lastMatched = new Date()
}

if (!sli.validate()) {
Expand All @@ -225,6 +230,7 @@ class EditorController {
render(text: message, status: 500)
}
else if (sli.save(flush: true)) {
sl.save(flush: true)
def msg = message(code:'public.lists.view.table.edit.messages', default:'Record successfully created')
render(text: msg, status: 200)
}
Expand Down Expand Up @@ -255,6 +261,9 @@ class EditorController {
def deleteRecord() {
def sli = SpeciesListItem.get(params.id)

sli.mylist.lastUploaded = new Date()
sli.mylist.save(flush: true)

if (!isCurrentUserEditorForList(SpeciesList.findByDataResourceUid(sli.dataResourceUid))) {
render(text: "You are not authorised to access this page", status: 403 )
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ class WebServiceController {
dateCreated : sl.dateCreated,
lastUpdated : sl.lastUpdated,
lastUploaded : sl.lastUploaded,
lastMatched : sl.lastMatched,
username : sl.username,
fullName : sl.getFullName(),
itemCount : sl.itemsCount,//SpeciesListItem.countByList(sl)
Expand Down Expand Up @@ -338,6 +339,7 @@ class WebServiceController {
dateCreated : it.dateCreated,
lastUpdated : it.lastUpdated,
lastUploaded : it.lastUploaded,
lastMatched : it.lastMatched,
username : it.username,
fullName : it.getFullName(),
itemCount : it.itemsCount,
Expand Down
2 changes: 2 additions & 0 deletions grails-app/domain/au/org/ala/specieslist/SpeciesList.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SpeciesList {
Date dateCreated
Date lastUpdated
Date lastUploaded
Date lastMatched
ListType listType
Boolean isPrivate
Boolean isSDS
Expand Down Expand Up @@ -74,6 +75,7 @@ class SpeciesList {
looseSearch nullable: true
searchStyle nullable: true
lastUploaded nullable: true
lastMatched nullable: true
userId nullable: true
ownerFullName nullable: true // derived
}
Expand Down
4 changes: 3 additions & 1 deletion grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ speciesList.sdsType.label=SDS Type
speciesList.looseSearch.label=Loose Name Search
speciesList.searchStyle.label=Name Search Style
speciesList.lastUploaded.label=Date last uploaded
speciesList.lastMatched.label=Date last matched

upload.heading.hasList=Resubmit to an existing list
upload.heading=Upload a list
Expand Down Expand Up @@ -144,6 +145,7 @@ speciesList.lastUpdated.label=Last Update
speciesList.metadata.label=Metadata Link
speciesList.name.dateCreated=Date submitted
speciesList.name.lastUpdated=Date updated
speciesList.name.lastUploaded=Date uploaded
speciesList.name.count=Item Count


Expand Down Expand Up @@ -414,4 +416,4 @@ logger.download.reason.systematic.research=systematic research/taxonomy
logger.download.reason.other.scientific.research=other scientific research
logger.download.reason.testing=testing
logger.download.reason.citizen.science=citizen science
logger.download.reason.restoration.remediation=restoration/remediation
logger.download.reason.restoration.remediation=restoration/remediation
29 changes: 29 additions & 0 deletions grails-app/init/au/org/ala/specieslist/BootStrap.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@

package au.org.ala.specieslist

import grails.converters.JSON
import groovy.sql.Sql
import org.apache.commons.lang.WordUtils

class BootStrap {
def authService, userDetailsService, grailsApplication
Sql groovySql
def dataSource

def init = { servletContext ->
Object.metaClass.trimLength = {Integer stringLength ->
Expand Down Expand Up @@ -47,6 +51,31 @@ class BootStrap {
userDetailsService.updateSpeciesListUserDetails()
userDetailsService.updateEditorsList()
}

dbUpgrade()
}

def dbUpgrade() {
def conn = dataSource.getConnection()
def statement = conn.createStatement()


String [] dbModificationSql = [
"alter table species_list add column last_uploaded datetime",
"update species_list set last_uploaded = last_updated where last_uploaded is null",
"alter table species_list add column last_matched datetime",
"update species_list set last_matched = last_updated where last_matched is null",

"alter table species_list add column search_style varchar(255)",
"alter table species_list add column loose_search bit(1)"
].each { String sql ->
try {
statement.execute(sql)
} catch (Exception ignored) {
}
}
statement.close()
conn.close()
}

def destroy = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ class HelperService {

List sli = speciesList.getItems().toList()
matchCommonNamesForSpeciesListItems(sli)
speciesList.lastMatched = new Date()

speciesList.save(flush: true, failOnError: true)

[speciesList: speciesList, speciesGuids: guidList]
Expand Down Expand Up @@ -441,6 +443,7 @@ class HelperService {
sl.looseSearch = looseSearch
sl.searchStyle = searchStyle
sl.lastUploaded = new Date()
sl.lastMatched = new Date()
String [] nextLine
boolean checkedHeader = false
Map termIdx = columnMatchingService.getTermAndIndex(header)
Expand Down Expand Up @@ -491,6 +494,7 @@ class HelperService {
sl.firstName = localAuthService.firstname()
sl.surname = localAuthService.surname()
sl.lastUploaded = new Date()
sl.lastMatched = new Date()
while ((nextLine = reader.readNext()) != null) {
if(org.apache.commons.lang.StringUtils.isNotBlank(nextLine)){
sl.addToItems(insertSpeciesItem(nextLine, druid, speciesValueIdx, header,kvpmap, sl))
Expand Down Expand Up @@ -692,7 +696,10 @@ class HelperService {
else if (sl.save()) {
// find common name and save it
matchCommonNamesForSpeciesListItems([sli])
sl.lastMatched = new Date()
sl.lastUploaded = new Date()
sl.save(flush: true)

// Commented out as we would like to keep species list generic
/* def preferredSpeciesImageListName = grailsApplication.config.ala.preferred.species.name
if (sl.listName == preferredSpeciesImageListName) {
Expand Down
3 changes: 3 additions & 0 deletions grails-app/views/_speciesList.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
title="${message(code: 'speciesList.name.dateCreated', default: 'Date Submitted')}"/>
<g:sortableColumn property="lastUpdated" params="${params}"
title="${message(code: 'speciesList.name.lastUpdated', default: 'Date Updated')}"/>
<g:sortableColumn property="lastUploaded" params="${params}"
title="${message(code: 'speciesList.name.lastUploaded', default: 'Date Uploaded')}"/>
<g:sortableColumn property="itemsCount" params="${params}"
title="${message(code: 'speciesList.name.count', default: 'Item Count')}"/>
<g:if test="${showActions && request.getUserPrincipal()}">
Expand All @@ -214,6 +216,7 @@
<td>${list.ownerFullName}</td>
<td><g:formatDate format="yyyy-MM-dd" date="${list.dateCreated}"/></td>
<td><g:formatDate format="yyyy-MM-dd" date="${list.lastUpdated}"/></td>
<td><g:formatDate format="yyyy-MM-dd" date="${list.lastUploaded}"/></td>
<td>${list.itemsCount}</td>
<g:if test="${showActions && (list.username == request.remoteUser || request.isUserInRole("ROLE_ADMIN"))}">
<td>
Expand Down
3 changes: 3 additions & 0 deletions grails-app/views/speciesListItem/list.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@
<dt>${message(code: 'speciesList.lastUploaded.label', default: 'Date last loaded')}</dt>
<dd><g:formatDate format="yyyy-MM-dd"
date="${speciesList.lastUploaded}"/></dd>
<dt>${message(code: 'speciesList.lastMatched.label', default: 'Date last matched')}</dt>
<dd><g:formatDate format="yyyy-MM-dd"
date="${speciesList.lastMatched}"/></dd>
<dt>${message(code: 'speciesList.isPrivate.label', default: 'Is private')}</dt>
<dd><g:formatBoolean boolean="${speciesList.isPrivate ?: false}" true="Yes" false="No"/></dd>
<dt>${message(code: 'speciesList.isBIE.label', default: 'Included in BIE')}</dt>
Expand Down

0 comments on commit e2768a2

Please sign in to comment.