Skip to content

Event core data #880

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

Merged
merged 25 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
874 changes: 681 additions & 193 deletions grails-app/conf/application.groovy

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion grails-app/conf/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ grails:
mongodb:
codecs:
- au.org.ala.ecodata.customcodec.AccessLevelCodec

cors:
enabled: true
allowedHeaders:
Expand Down
15 changes: 15 additions & 0 deletions grails-app/conf/data/eventcore/eml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<eml:eml xmlns:d="eml://ecoinformatics.org/dataset-2.1.0" xmlns:eml="eml://ecoinformatics.org/eml-2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/terms/" xsi:schemaLocation="eml://ecoinformatics.org/eml-2.1.1 http://rs.gbif.org/schema/eml-gbif-profile/1.1/eml-gbif-profile.xsd" system="ALA-Registry" scope="system" xml:lang="en">
<dataset>
<title xmlns:lang="en">${name}</title>
<creator>
<organizationName>${organisationName}</organizationName>
</creator>
<metadataProvider>
<organizationName>Atlas of Living Australia</organizationName>
</metadataProvider>
<pubDate>${dateCreated}</pubDate>
<abstract>
<para>${description}</para>
</abstract>
</dataset>
</eml:eml>
22 changes: 22 additions & 0 deletions grails-app/conf/data/eventcore/meta.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<archive xmlns="${archiveNameSpace}" metadata="${emlFileName}" xmlns:gsp="http://groovy.codehaus.org/2005/gsp">
<core rowType="${core.rowType}" encoding="${core.encoding}" fieldsTerminatedBy="${core.fieldsTerminatedBy}" linesTerminatedBy="${core.linesTerminatedBy}" fieldsEnclosedBy="${core.fieldsEnclosedBy}" ignoreHeaderLines="${core.ignoreHeaderLines}">
<files>
<location>${core.location}</location>
</files>
<id index="${core.coreIndex}"/>
<gsp:scriptlet>core.fields?.each {</gsp:scriptlet>
<field index="${it.index}" term="${it.term}"/>
<gsp:scriptlet>}</gsp:scriptlet>
</core>
<gsp:scriptlet>extensions?.each {</gsp:scriptlet>
<extension rowType="${it.rowType}" encoding="${it.encoding}" fieldsTerminatedBy="${it.fieldsTerminatedBy}" linesTerminatedBy="${it.linesTerminatedBy}" fieldsEnclosedBy="${it.fieldsEnclosedBy}" ignoreHeaderLines="${it.ignoreHeaderLines}">
<files>
<location>${it.location}</location>
</files>
<coreid index="${it.coreIndex}"/>
<gsp:scriptlet>it.fields?.each {</gsp:scriptlet>
<field index="${it.index}" term="${it.term}"/>
<gsp:scriptlet>}</gsp:scriptlet>
</extension>
<gsp:scriptlet>}</gsp:scriptlet>
</archive>
28 changes: 26 additions & 2 deletions grails-app/controllers/au/org/ala/ecodata/HarvestController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.org.ala.ecodata

import grails.converters.JSON
import org.apache.http.HttpStatus
import org.apache.http.entity.ContentType

import java.text.SimpleDateFormat;

Expand Down Expand Up @@ -70,9 +71,11 @@ class HarvestController {
* @param sort = asc | desc | default:asc
* @param lastUpdated = date | dd/MM/yyyy | default:null
* @param status = active | deleted | default:active
*
* @deprecated ALA's records harvester will use getDarwinCoreArchiveForProject once Events system is setup.
* To access it use archiveURL property from {@link HarvestController#listHarvestDataResource}.
*/
def listRecordsForDataResourceId (){
@Deprecated
def listRecordsForDataResourceId () {
def result = [], error, project
Date lastUpdated = null
try {
Expand Down Expand Up @@ -134,4 +137,25 @@ class HarvestController {
response.setContentType("application/json")
render result as JSON
}

/**
* Get Darwin Core Archive for a project that has ala harvest enabled.
* @param projectId
* @return
* At the moment, you need to add their IP address to whitelist.
*/
def getDarwinCoreArchiveForProject (String projectId) {
if (projectId) {
Project project = Project.findByProjectId(projectId)
if(project?.alaHarvest) {
// This is done to get the correct URL for documents.
String hostname = project.isMERIT ? grailsApplication.config.getProperty("fieldcapture.baseURL") : grailsApplication.config.getProperty("biocollect.baseURL")
DocumentHostInterceptor.documentHostUrlPrefix.set(hostname)
recordService.getDarwinCoreArchiveForProject(response.outputStream, project)
} else
response status: HttpStatus.SC_NOT_FOUND, text: [error: "project not found or ala harvest flag is switched off"] as JSON, contentType: ContentType.APPLICATION_JSON
} else {
response status: HttpStatus.SC_BAD_REQUEST, text: [error: "projectId is required"] as JSON, contentType: ContentType.APPLICATION_JSON
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class RecordController {
}
}


private def setResponseHeadersForRecord(response, record) {
response.addHeader("content-location", grailsApplication.config.getProperty('grails.serverURL') + "/record/" + record.occurrenceID)
response.addHeader("location", grailsApplication.config.getProperty('grails.serverURL') + "/record/" + record.occurrenceID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class UrlMappings {
"/ws/project/getDataCollectionWhiteList"(controller: "project"){ action = [GET:"getDataCollectionWhiteList"] }
"/ws/project/getBiocollectFacets"(controller: "project"){ action = [GET:"getBiocollectFacets"] }
"/ws/project/getDefaultFacets"(controller: "project", action: "getDefaultFacets")
"/ws/project/$projectId/archive"(controller: "harvest", action: "getDarwinCoreArchiveForProject")
"/ws/project/$projectId/dataSet/$dataSetId/records"(controller: "project", action: "fetchDataSetRecords")
"/ws/project/findStateAndElectorateForProject"(controller: "project", action: "findStateAndElectorateForProject")
"/ws/admin/initiateSpeciesRematch"(controller: "admin", action: "initiateSpeciesRematch")
Expand Down
12 changes: 12 additions & 0 deletions grails-app/domain/au/org/ala/ecodata/Document.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Document {
String identifier
/* To be replaced by reportId */
String stage
String imageId

boolean thirdPartyConsentDeclarationMade = false
String thirdPartyConsentDeclarationText
Expand Down Expand Up @@ -125,6 +126,10 @@ class Document {
return ''
}

if (imageId) {
return getImageURL()
}

if (isImageHostedOnPublicServer()) {
return identifier
}
Expand All @@ -147,6 +152,12 @@ class Document {

}

String getImageURL () {
if (imageId) {
Holders.getGrailsApplication().config.getProperty("imagesService.baseURL") + "/proxyImage?id=" + imageId
}
}

static constraints = {
name nullable: true
attribution nullable: true
Expand Down Expand Up @@ -180,5 +191,6 @@ class Document {
identifier nullable: true
contentType nullable: true
hubId nullable: true
imageId nullable: true
}
}
2 changes: 2 additions & 0 deletions grails-app/domain/au/org/ala/ecodata/ProjectActivity.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ProjectActivity {
MapLayersConfiguration mapLayersConfig
String surveySiteOption
boolean canEditAdminSelectedSites
boolean published
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd use the "publicationStatus" flag here for consistency with MERIT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this flag was added long back in BioCollect but never added to domain object. Will add as a tech debt.

Date dateCreated
Date lastUpdated

Expand Down Expand Up @@ -87,6 +88,7 @@ class ProjectActivity {
mapLayersConfig nullable: true
surveySiteOption nullable: true, inList: ['sitepick','sitecreate', 'sitepickcreate']
canEditAdminSelectedSites nullable: true
published nullable: true
}

static mapping = {
Expand Down
21 changes: 20 additions & 1 deletion grails-app/services/au/org/ala/ecodata/ActivityService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,26 @@ class ActivityService {
}
}

/**
* An activity is embargoed if either of the below conditions are satisfied
* 1. embargoed flag is set to true on an activity
* 2. project activity is embargoed until a defined date
* @param activity
* @param projectActivity
* @return
*/
boolean isActivityEmbargoed(Activity activity, ProjectActivity projectActivity){
if (activity.embargoed) {
return activity.embargoed
}

if (projectActivity?.visibility?.embargoUntil) {
return projectActivity?.visibility?.embargoUntil.after(new Date())
}

return false
}

List findAllForOrganisationId(id, levelOfDetail = [], includeDeleted = false) {
List activities
if (includeDeleted) {
Expand All @@ -659,5 +679,4 @@ class ActivityService {
}
activities
}

}
17 changes: 11 additions & 6 deletions grails-app/services/au/org/ala/ecodata/MapService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import com.spatial4j.core.context.SpatialContext
import com.spatial4j.core.io.GeohashUtils
import com.spatial4j.core.shape.Rectangle
import grails.converters.JSON
import groovy.json.JsonSlurper
import grails.web.http.HttpHeaders
import groovy.json.JsonSlurper
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse
import org.elasticsearch.action.search.SearchRequest
import org.elasticsearch.common.Strings
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput
import org.elasticsearch.common.xcontent.XContentHelper
import org.elasticsearch.index.query.QueryBuilder
import org.elasticsearch.search.aggregations.bucket.geogrid.GeoGrid
import org.springframework.beans.factory.annotation.Autowired
Expand Down Expand Up @@ -625,16 +623,23 @@ class MapService {
webService.doDelete(url, headers)
}

String bindDataToXMLTemplate (String fileClassPath, Map data) {
String bindDataToXMLTemplate (String fileClassPath, Map data, boolean prettyPrint = false) {
def files = resourceResolver.getResources(fileClassPath)
def engine = new groovy.text.XmlTemplateEngine()
engine.setIndentation('')
if (!prettyPrint)
engine.setIndentation("")
else
engine.setIndentation(" ")

String content
files?.each { Resource file ->
content = engine.createTemplate(file.getURL()).make(data).toString()
}

content?.replaceAll('\n', '');
if (prettyPrint)
return content
else
return content?.replaceAll('\n', '')
}

def buildStyleForTermFacet(String field, List terms, String style, String dataStore) {
Expand Down
14 changes: 13 additions & 1 deletion grails-app/services/au/org/ala/ecodata/ProjectService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,19 @@ class ProjectService {
order(params.sort, params.order)
}

[total: list?.totalCount, list: list?.collect { toMap(it, "basic") }]
def total = list?.totalCount
list = list?.collect { toMap(it, "basic") }
addArchiveLink(list)
[total: total, list: list]
}

/**
* Adds archive URL to projects
* @param projects
* @return
*/
def addArchiveLink (List projects) {
projects?.each { it.archiveURL = grailsApplication.config.getProperty("grails.serverURL") + "/ws/project/${it.projectId}/archive" }
}

def listProjects(Map params) {
Expand Down
Loading