-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issues in SitemapService #243
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,16 @@ | |
*/ | ||
package au.org.ala.collectory | ||
|
||
import grails.gorm.transactions.Transactional | ||
import grails.util.Holders | ||
import org.springframework.scheduling.annotation.Scheduled | ||
|
||
import java.text.SimpleDateFormat | ||
|
||
class SitemapService { | ||
|
||
static lazyInit = !Holders.getConfig().getProperty("sitemap.enabled", Boolean.TYPE, false) | ||
|
||
def grailsApplication | ||
|
||
|
||
|
@@ -40,6 +44,8 @@ class SitemapService { | |
// run daily, initial delay 1hr | ||
@Scheduled(fixedDelay = 86400000L, initialDelay = 3600000L) | ||
def build() throws Exception { | ||
fileCount = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
initWriter() | ||
buildSitemap() | ||
closeWriter() | ||
|
@@ -63,7 +69,7 @@ class SitemapService { | |
new File(grailsApplication.config.sitemap.dir + "/sitemap" + i + ".xml.tmp").renameTo(newFile) | ||
|
||
// add an entry for this new file | ||
fw.write("<sitemap><url>" + grailsApplication.config.grails.serverURL + "/sitemap" + i + ".xml" + "</url>") | ||
fw.write("<sitemap><loc>" + grailsApplication.config.grails.serverURL + "/sitemap" + i + ".xml" + "</loc>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The correct syntax is |
||
fw.write("<lastmod>" + simpleDateFormat.format(new Date()) + "</lastmod></sitemap>") | ||
} | ||
|
||
|
@@ -106,22 +112,23 @@ class SitemapService { | |
countUrls++ | ||
} | ||
|
||
@Transactional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scheduled runs crash with org.springframework.dao.DataAccessResourceFailureException: Could not obtain current Hibernate Session; nested exception is org.hibernate.HibernateException: No Session found for current thread. Manual runs from admin UI are ok. Adding |
||
def buildSitemap() throws Exception { | ||
|
||
Collection.findAll().each {Collection it -> | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/co" + it.id) | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/" + it.uid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
} | ||
|
||
Institution.findAll().each {Institution it -> | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/in" + it.id) | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/" + it.uid) | ||
} | ||
|
||
DataProvider.findAll().each {DataProvider it -> | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/dp" + it.id) | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/" + it.uid) | ||
} | ||
|
||
DataResource.findAllByIsPrivate(false).each {DataResource it -> | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/dr" + it.id) | ||
writeUrl(it.lastUpdated, "weekly", grailsApplication.config.grails.serverURL + "/public/show/" + it.uid) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If sitemap is enabled the SitemapService should be loaded on application startup thereby enabling scheduled runs. Otherwise scheduled runs are enabled only after a manual run from admin UI.