Skip to content

Commit

Permalink
Merge pull request #912 from AtlasOfLivingAustralia/feature/paratoo
Browse files Browse the repository at this point in the history
Feature/paratoo
temi authored Feb 25, 2024

Verified

This commit was signed with the committer’s verified signature.
MaskDuck MaskDuck
2 parents a8a7f2d + 401ac4c commit b6f2a56
Showing 5 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ buildscript {
plugins {
id "com.github.node-gradle.node" version "3.4.0"
id 'jacoco'
id "com.gorylenko.gradle-git-properties" version "2.4.1"
}

version "4.4-SNAPSHOT"
Original file line number Diff line number Diff line change
@@ -22,6 +22,9 @@ import static au.org.ala.ecodata.Status.DELETED

class MetadataService {

static final String BUILD_VERSION_PROPERTY = "git.build.version"
private static final String GIT_PROPERTIES_FILE = "git.properties"

// The spatial portal returns n/a when the point does not intersect a layer.
private static final String SPATIAL_PORTAL_NO_MATCH_VALUE = 'n/a'

@@ -1182,7 +1185,11 @@ class MetadataService {

/** Returns a value from the gradle git plugin generated git.properties */
String getGitProperty(String propertyName) {
getFromPropertyFile("git.properties", propertyName)
getFromPropertyFile(GIT_PROPERTIES_FILE, propertyName)
}

String getVersion() {
getGitProperty(BUILD_VERSION_PROPERTY)
}

/** Returns a value from the gradle/spring boot generated build-info.properties */
29 changes: 25 additions & 4 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ class ParatooService {
SiteService siteService
PermissionService permissionService
TokenService tokenService
MetadataService metadataService

/**
* The rules we use to find projects eligible for use by paratoo are:
@@ -147,9 +148,12 @@ class ParatooService {
surveyId: paratooCollectionId.surveyId,
eventTime: new Date(),
userId: userId,
projectId: projectId
projectId: projectId,
system: "MERIT",
version: metadataService.getVersion()
)
dataSet.orgMintedIdentifier = orgMintedIdentifier.encodeAsMintedCollectionId()
log.info "Minting identifier for Monitor collection: ${paratooCollectionId}: ${dataSet.orgMintedIdentifier}"
project.custom.dataSets << dataSet
Map result = projectService.update([custom:project.custom], projectId, false)

@@ -272,9 +276,11 @@ class ParatooService {
private Map syncParatooProtocols(List<Map> protocols) {

Map result = [errors:[], messages:[]]
List guids = []
protocols.each { Map protocol ->
String id = protocol.id
String guid = protocol.attributes.identifier
guids << guid
String name = protocol.attributes.name
ActivityForm form = ActivityForm.findByExternalId(guid)
if (!form) {
@@ -295,12 +301,15 @@ class ParatooService {
if (paratooInternalId) {
String message = "Updating form with id: "+paratooInternalId.externalId+", guid: "+guid+", name: "+name+", new id: "+id
paratooInternalId.externalId = id
result.messages << message
log.info message
}
else {
result.errors << "Error: Missing internal id for form with id: "+id+", name: "+name
String error = "Error: Missing internal id for form with id: "+id+", name: "+name
result.errors << error
log.error error
}
result.messages << message
log.info message

}

mapProtocolToActivityForm(protocol, form)
@@ -311,6 +320,18 @@ class ParatooService {
log.warn "Error saving form with id: "+id+", name: "+name
}
}

List allProtocolForms = ActivityForm.findAll {
externalIds {
idType == ExternalId.IdType.MONITOR_PROTOCOL_GUID
}
status != Status.DELETED
}

List deletions = allProtocolForms.findAll{it.externalIds.find{it.idType == ExternalId.IdType.MONITOR_PROTOCOL_GUID && !(it.externalId in guids)}}
deletions.each { ActivityForm activityForm ->
result.messages << "Form ${activityForm.name} with guid: ${activityForm.externalIds.find{it.idType == ExternalId.IdType.MONITOR_PROTOCOL_GUID}.externalId} has been deleted"
}
result

}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import au.org.ala.ecodata.DateUtil
import grails.converters.JSON
import grails.databinding.BindingFormat
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import org.springframework.beans.factory.annotation.Value

@JsonIgnoreProperties(['metaClass', 'errors', 'expandoMetaClass'])
class ParatooMintedIdentifier {
@@ -12,6 +13,8 @@ class ParatooMintedIdentifier {
Date eventTime
String userId
String projectId
String system
String version

String eventTimeAsISOString() {
DateUtil.formatWithMilliseconds(eventTime)
@@ -24,7 +27,11 @@ class ParatooMintedIdentifier {
userId: userId,
projectId: projectId,
protocolId: surveyId.protocol.id,
protocolVersion: surveyId.protocol.version
protocolVersion: surveyId.protocol.version,
org_provenance: [
system: system,
version: version
]
]
String jsonString = (data as JSON).toString()
jsonString.encodeAsBase64()
2 changes: 2 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
WebService webService = Mock(WebService)
TokenService tokenService = Mock(TokenService)
SettingService settingService = Mock(SettingService)
MetadataService metadataService = Mock(MetadataService)

static Map DUMMY_POLYGON = [type:'Polygon', coordinates: [[[1,2], [2,2], [2, 1], [1,1], [1,2]]]]

@@ -35,6 +36,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
service.permissionService = new PermissionService() // Using the real permission service for this test
service.tokenService = tokenService
service.settingService = settingService
service.metadataService = metadataService

JSON.registerObjectMarshaller(new MapMarshaller())
JSON.registerObjectMarshaller(new CollectionMarshaller())

0 comments on commit b6f2a56

Please sign in to comment.