Skip to content

Commit

Permalink
Merge pull request #969 from AtlasOfLivingAustralia/feature/issue965
Browse files Browse the repository at this point in the history
Use different id type for plot selections #942
  • Loading branch information
temi authored May 30, 2024
2 parents 72f2d40 + 29212f4 commit 49d2cdc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion grails-app/domain/au/org/ala/ecodata/ExternalId.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ExternalId implements Comparable {
enum IdType {
INTERNAL_ORDER_NUMBER, TECH_ONE_CODE, WORK_ORDER, GRANT_AWARD, GRANT_OPPORTUNITY, RELATED_PROJECT,
MONITOR_PROTOCOL_INTERNAL_ID, MONITOR_PROTOCOL_GUID, TECH_ONE_CONTRACT_NUMBER, MONITOR_PLOT_GUID,
MONITOR_MINTED_COLLECTION_ID, UNSPECIFIED }
MONITOR_PLOT_SELECTION_GUID, MONITOR_MINTED_COLLECTION_ID, UNSPECIFIED }

static constraints = {
}
Expand Down
8 changes: 4 additions & 4 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ class ParatooService {
// Monitor has users selecting a point as an approximate survey location then
// laying out the plot using GPS when at the site. We only want to return the approximate planning
// sites from this call
List<Site> plotSelections = sites.findAll{it.type == Site.TYPE_SURVEY_AREA && it.extent?.geometry?.type == 'Point'}
List<Site> plotSelections = sites.findAll{it.externalIds?.find{externalId -> externalId.idType == ExternalId.IdType.MONITOR_PLOT_SELECTION_GUID}}

Map attributes = [
id:project.projectId,
Expand Down Expand Up @@ -876,7 +876,7 @@ class ParatooService {
// The project/s for the site will be specified by a subsequent call to /projects
siteData.projects = []

Site site = Site.findByExternalId(ExternalId.IdType.MONITOR_PLOT_GUID, siteData.externalId)
Site site = Site.findByExternalId(ExternalId.IdType.MONITOR_PLOT_SELECTION_GUID, siteData.externalIds[0].externalId)
Map result
if (site) {
result = siteService.update(siteData, site.siteId)
Expand All @@ -893,7 +893,7 @@ class ParatooService {
site.projects = []
// get all projects for the user I suppose - not sure why this isn't in the payload as it's in the UI...
site.type = Site.TYPE_SURVEY_AREA
site.externalIds = [new ExternalId(idType: ExternalId.IdType.MONITOR_PLOT_GUID, externalId: geoJson.properties.externalId)]
site.externalIds = [new ExternalId(idType: ExternalId.IdType.MONITOR_PLOT_SELECTION_GUID, externalId: geoJson.properties.externalId)]
site.publicationStatus = PublicationStatus.PUBLISHED
// Mark the plot as read only as it is managed by the Monitor app

Expand All @@ -920,7 +920,7 @@ class ParatooService {

siteExternalIds.each { String siteExternalId ->

Site site = Site.findByExternalId(ExternalId.IdType.MONITOR_PLOT_GUID, siteExternalId)
Site site = Site.findByExternalId(ExternalId.IdType.MONITOR_PLOT_SELECTION_GUID, siteExternalId)
if (site) {
site.projects = site.projects ?: []
if (!site.projects.contains(project.id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ class ParatooProtocolConfig {

String name = plotSelectionGeoJson.properties.name + ' - ' + plotLayoutTypeLabel + ' ('+CORE_PLOT_SHORT+')'

Map plotGeoJson = createFeatureFromGeoJSON(plotLayoutPoints, name, plotLayoutId, "${CORE_PLOT} ${plotSelectionGeoJson?.properties?.notes?:""}")
Map plotGeoJson = createFeatureFromGeoJSON(plotLayoutPoints, name, plotLayoutId, "${CORE_PLOT} ${plotSelectionGeoJson?.properties?.notes?:""}", CORE_PLOT_SHORT)

if (faunaPlotPoints) {
name = plotSelectionGeoJson.properties.name + ' - ' + plotLayoutTypeLabel + ' (' + FAUNA_PLOT_SHORT + ')'
Map faunaPlotGeoJson = createFeatureFromGeoJSON(faunaPlotPoints, name, plotLayoutId, "${FAUNA_PLOT} ${plotSelectionGeoJson?.properties?.notes?:""}")
Map faunaPlotGeoJson = createFeatureFromGeoJSON(faunaPlotPoints, name, plotLayoutId, "${FAUNA_PLOT} ${plotSelectionGeoJson?.properties?.notes?:""}", FAUNA_PLOT_SHORT)
List features = [plotGeoJson, faunaPlotGeoJson]

name = plotSelectionGeoJson.properties.name + ' - ' + plotLayoutTypeLabel + ' (' + CORE_PLOT_SHORT + ' + ' + FAUNA_PLOT_SHORT + ')'
Expand All @@ -357,13 +357,13 @@ class ParatooProtocolConfig {
]
}

static Map createFeatureFromGeoJSON(List plotLayoutPoints, String name, String plotLayoutId, String notes = "") {
static Map createFeatureFromGeoJSON(List plotLayoutPoints, String name, String plotLayoutId, String notes = "", String activityType = null) {
Map plotGeometry = toGeometry(plotLayoutPoints)
createFeatureObject(plotGeometry, name, plotLayoutId, notes)
createFeatureObject(plotGeometry, name, plotLayoutId, notes, activityType)
}

static Map createFeatureObject(Map plotGeometry, String name, String plotLayoutId, String notes = "") {
[
static Map createFeatureObject(Map plotGeometry, String name, String plotLayoutId, String notes = "", String activityType = null) {
Map featureObject = [
type : 'Feature',
geometry : plotGeometry,
properties: [
Expand All @@ -373,6 +373,10 @@ class ParatooProtocolConfig {
notes : notes
]
]
if (activityType) {
featureObject.properties.activityType = activityType
}
featureObject
}

static Map toGeometry(List points) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
"uuid" : "lmpisy5p9g896lad4ut",
"comments" : "Test"]

Map expected = ['name': 'CTMAUA2222', 'description': 'CTMAUA2222', publicationStatus: 'published', 'externalIds': [new ExternalId(externalId: 'lmpisy5p9g896lad4ut', idType: ExternalId.IdType.MONITOR_PLOT_GUID)], 'notes': 'Test', 'extent': ['geometry': ['type': 'Point', 'coordinates': [149.0651439, -35.2592424], 'decimalLatitude': -35.2592424, 'decimalLongitude': 149.0651439], 'source': 'point'], 'projects': [], 'type': 'surveyArea']
Map expected = ['name': 'CTMAUA2222', 'description': 'CTMAUA2222', publicationStatus: 'published', 'externalIds': [new ExternalId(externalId: 'lmpisy5p9g896lad4ut', idType: ExternalId.IdType.MONITOR_PLOT_SELECTION_GUID)], 'notes': 'Test', 'extent': ['geometry': ['type': 'Point', 'coordinates': [149.0651439, -35.2592424], 'decimalLatitude': -35.2592424, 'decimalLongitude': 149.0651439], 'source': 'point'], 'projects': [], 'type': 'surveyArea']

String userId = 'u1'

Expand Down Expand Up @@ -533,7 +533,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer

Site projectArea = new Site(siteId: 's1', name: 'Site 1', type: Site.TYPE_PROJECT_AREA, extent: [geometry: DUMMY_POLYGON])
projectArea.save(failOnError: true, flush: true)
Site plot = new Site(siteId: 's2', name: "Site 2", type: Site.TYPE_SURVEY_AREA, extent: [geometry: DUMMY_PLOT], projects: ['p1'])
Site plot = new Site(siteId: 's2', name: "Site 2", type: Site.TYPE_SURVEY_AREA, extent: [geometry: DUMMY_PLOT], projects: ['p1'], externalIds:[new ExternalId(externalId: "2", idType: ExternalId.IdType.MONITOR_PLOT_SELECTION_GUID)])
plot.save(failOnError: true, flush: true)
siteService.sitesForProjectWithTypes('p1', [Site.TYPE_PROJECT_AREA, Site.TYPE_SURVEY_AREA]) >> [projectArea, plot]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class ParatooProtocolConfigSpec extends Specification {
type: "Polygon",
coordinates: [[[152.880694, -27.388252], [152.880651, -27.388336], [152.880518, -27.388483], [152.880389, -27.388611], [152.88028, -27.388749], [152.880154, -27.388903], [152.880835, -27.389463], [152.880644, -27.389366], [152.880525, -27.389248], [152.88035, -27.389158], [152.880195, -27.389021], [152.880195, -27.389373], [152.880797, -27.388316], [152.881448, -27.388909], [152.881503, -27.388821], [152.881422, -27.388766], [152.881263, -27.388644], [152.881107, -27.388549], [152.880939, -27.388445], [152.881314, -27.389035], [152.88122, -27.389208], [152.881089, -27.389343], [152.880973, -27.389472], [152.880916, -27.389553], [152.880694, -27.388252]]]
],
properties: [name: "QDASEQ0001 - Control (Core)", externalId: "1", description: "QDASEQ0001 - Control (Core)", notes: "Core monitoring plot some comment"]
properties: [name: "QDASEQ0001 - Control (Core)", externalId: "1", description: "QDASEQ0001 - Control (Core)", notes: "Core monitoring plot some comment", activityType:'Core']
]
}

Expand Down Expand Up @@ -204,15 +204,15 @@ class ParatooProtocolConfigSpec extends Specification {
type:"Polygon",
coordinates:[[[138.63720760798054, -34.97222197296049], [138.63720760798054, -34.97204230990367], [138.63720760798054, -34.971862646846844], [138.63720760798054, -34.97168298379002], [138.63720760798054, -34.9715033207332], [138.63720760798054, -34.971413489204785], [138.63731723494544, -34.971413489204785], [138.6375364888752, -34.971413489204785], [138.63775574280498, -34.971413489204785], [138.63797499673475, -34.971413489204785], [138.63819425066453, -34.971413489204785], [138.63830387762943, -34.971413489204785], [138.63830387762943, -34.9715033207332], [138.63830387762943, -34.97168298379002], [138.63830387762943, -34.971862646846844], [138.63830387762943, -34.97204230990367], [138.63830387762943, -34.97222197296049], [138.63830387762943, -34.9723118044889], [138.63819425066453, -34.9723118044889], [138.63797499673475, -34.9723118044889], [138.63775574280498, -34.9723118044889], [138.6375364888752, -34.9723118044889], [138.63731723494544, -34.9723118044889], [138.63720760798054, -34.9723118044889], [138.63720760798054, -34.97222197296049]]]
],
properties:[name:"SATFLB0001 - Control (Core)", externalId:"2", description:"SATFLB0001 - Control (Core)", notes:"Core monitoring plot some comment"]],
properties:[name:"SATFLB0001 - Control (Core)", externalId:"2", description:"SATFLB0001 - Control (Core)", notes:"Core monitoring plot some comment", activityType:'Core']],
[
type:"Feature",
geometry:[
type:"Polygon",
coordinates:[[[138.6371026907952, -34.971403261821905], [138.63709732396242, -34.972304399720215], [138.6381916652405, -34.972304399720215], [138.63819166764344, -34.9714076576406], [138.6371026907952, -34.971403261821905]]]
],
properties:[
name:"SATFLB0001 - Control (Fauna)", externalId:"2", description:"SATFLB0001 - Control (Fauna)", notes:"Fauna plot some comment"
name:"SATFLB0001 - Control (Fauna)", externalId:"2", description:"SATFLB0001 - Control (Fauna)", notes:"Fauna plot some comment", activityType:'Fauna'
]
]
]
Expand All @@ -228,7 +228,8 @@ class ParatooProtocolConfigSpec extends Specification {
name:"SATFLB0001 - Control (Core)",
externalId:"2",
description:"SATFLB0001 - Control (Core)",
notes:"Core monitoring plot some comment"
notes:"Core monitoring plot some comment",
activityType: 'Core'
]
],
[
Expand All @@ -241,7 +242,8 @@ class ParatooProtocolConfigSpec extends Specification {
name:"SATFLB0001 - Control (Fauna)",
externalId:"2",
description:"SATFLB0001 - Control (Fauna)",
notes:"Fauna plot some comment"
notes:"Fauna plot some comment",
activityType: 'Fauna'
]
]
]
Expand Down

0 comments on commit 49d2cdc

Please sign in to comment.