Skip to content

Commit

Permalink
Merge pull request #989 from AtlasOfLivingAustralia/feature/issue988
Browse files Browse the repository at this point in the history
Allow use of known shape as project extent in Monitor projects #988
  • Loading branch information
salomon-j committed Jul 1, 2024
2 parents 61aa967 + 961d743 commit 3683737
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,18 @@ class ParatooService {
Map projectAreaGeoJson = null
if (projectArea) {
projectAreaGeoJson = siteService.geometryAsGeoJson(projectArea)
if (projectAreaGeoJson?.type == 'Feature') {
projectAreaGeoJson = projectAreaGeoJson.geometry
}
else if (projectAreaGeoJson?.type == 'MultiPolygon') {
projectAreaGeoJson = [
type:'Polygon',
coordinates:projectAreaGeoJson.coordinates[0]
]
}
else {
log.warn("Invalid geometry type for project area: ${projectAreaGeoJson?.type} specified for Monitor project ${project.projectId}")
}
}

// Monitor has users selecting a point as an approximate survey location then
Expand Down
2 changes: 1 addition & 1 deletion grails-app/services/au/org/ala/ecodata/SiteService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class SiteService {

if (!geometry) {
log.error("Invalid site: ${site.siteId} missing geometry")
return
return null
}
def result = null
switch (geometry.type) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer

static Map DUMMY_POLYGON = [type: 'Polygon', coordinates: [[[1, 2], [2, 2], [2, 1], [1, 1], [1, 2]]]]
static Map DUMMY_PLOT = ['type':'Point', coordinates: [1,2]]
static Map DUMMY_MULTI_POLYGON = [type: 'MultiPolygon', coordinates: [[[[1, 2], [2, 2], [2, 1], [1, 1], [1, 2]]]]]

// The am/pm in the formatted time is local dependent and this appears to be easiest way to determine the value.
String am = DateUtil.formatAsDisplayDateTime("2024-05-14T00:00:00Z")[-2..-1]
Expand Down Expand Up @@ -146,6 +147,27 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer

}

void "userProjects can convert a Feature or MultiPolygon typed project extent to a Polygon to support the use of known shape selection in MERIT (e.g. a NRM region)"() {
when:
List<ParatooProject> projects = service.userProjects(userId)
then:
1 * siteService.geometryAsGeoJson(_) >> DUMMY_MULTI_POLYGON
and:
projects.size() == 1
projects[0].id == "p1"
projects[0].name == "Project 1"
projects[0].accessLevel == AccessLevel.admin
projects[0].projectArea == DUMMY_POLYGON
projects[0].plots.size() == 1
projects[0].plots[0].siteId == 's2'
projects[0].protocols*.name == ["Plot Selection", "aParatooForm 1", "aParatooForm 2", "aParatooForm 3"]
}
void "The service should create a data set in the planned state when the mintCollectionId method is called"() {
setup:
ParatooCollectionId collectionId = buildCollectionId()
Expand Down

0 comments on commit 3683737

Please sign in to comment.