Skip to content

Commit dccc4f4

Browse files
committed
- external ids are now of type string - fixed broken tests
1 parent dc6099e commit dccc4f4

File tree

3 files changed

+91
-30
lines changed

3 files changed

+91
-30
lines changed

src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProtocolConfig.groovy

+11-11
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ParatooProtocolConfig {
219219
List features = extractFeatures(output, form)
220220
if (features) {
221221
features.addAll(geoJson.features?:[])
222-
geoJson = createConvexHullGeoJSON(features, geoJson.properties.name, geoJson.properties.externalId)
222+
geoJson = createConvexHullGeoJSON(features, geoJson.properties.name, geoJson.properties.externalId, geoJson.properties.notes)
223223
}
224224
}
225225
}
@@ -314,14 +314,13 @@ class ParatooProtocolConfig {
314314

315315
private Map extractSiteDataFromPlotVisit(Map survey) {
316316
Map surveyData = getSurveyData(survey)
317-
def plotLayoutId = getProperty(surveyData, plotLayoutIdPath) // Currently an int, may become uuid?
317+
String plotLayoutId = getProperty(surveyData, plotLayoutIdPath) // Currently an int, may become uuid?
318318

319319
if (!plotLayoutId) {
320320
log.warn("No plot_layout found in survey at path ${plotLayoutIdPath}")
321321
return null
322322
}
323-
else
324-
plotLayoutId = plotLayoutId.toString()
323+
325324
List plotLayoutPoints = getProperty(surveyData, plotLayoutPointsPath)
326325
Map plotSelection = getProperty(surveyData, plotSelectionPath)
327326
Map plotSelectionGeoJson = plotSelectionToGeoJson(plotSelection)
@@ -333,17 +332,17 @@ class ParatooProtocolConfig {
333332

334333
Map plotGeoJson = createFeatureFromGeoJSON(plotLayoutPoints, name, plotLayoutId, "${CORE_PLOT} ${plotSelectionGeoJson?.properties?.notes?:""}")
335334
List faunaPlotPoints = getProperty(surveyData, faunaPlotPointPath)
336-
Map faunaPlotGeoJson = createFeatureFromGeoJSON(faunaPlotPoints, name, plotLayoutId, "${FAUNA_PLOT} ${plotSelectionGeoJson?.properties?.notes?:""}")
337335

338-
if (faunaPlotGeoJson) {
336+
if (faunaPlotPoints) {
337+
Map faunaPlotGeoJson = createFeatureFromGeoJSON(faunaPlotPoints, name, plotLayoutId, "${FAUNA_PLOT} ${plotSelectionGeoJson?.properties?.notes?:""}")
339338
List features = [plotGeoJson, faunaPlotGeoJson]
340-
plotGeoJson = createConvexHullGeoJSON(features, name, plotLayoutId)
339+
plotGeoJson = createConvexHullGeoJSON(features, name, plotLayoutId, plotGeoJson.properties.notes)
341340
}
342341

343342
plotGeoJson
344343
}
345344

346-
static Map createConvexHullGeoJSON (List features, String name, String externalId = "") {
345+
static Map createConvexHullGeoJSON (List features, String name, String externalId = "", String notes = "") {
347346
List featureGeometries = features.collect { it.geometry }
348347
Geometry geometry = GeometryUtils.getFeatureCollectionConvexHull(featureGeometries)
349348
[
@@ -352,18 +351,19 @@ class ParatooProtocolConfig {
352351
properties: [
353352
name: name,
354353
externalId: externalId,
354+
notes: notes,
355355
description: "${name} (convex hull of all features)",
356356
],
357357
features: features
358358
]
359359
}
360360

361-
static Map createFeatureFromGeoJSON(List plotLayoutPoints, String name, def plotLayoutId, String notes = "") {
361+
static Map createFeatureFromGeoJSON(List plotLayoutPoints, String name, String plotLayoutId, String notes = "") {
362362
Map plotGeometry = toGeometry(plotLayoutPoints)
363363
createFeatureObject(plotGeometry, name, plotLayoutId, notes)
364364
}
365365

366-
static Map createFeatureObject(Map plotGeometry, String name, plotLayoutId, String notes = "") {
366+
static Map createFeatureObject(Map plotGeometry, String name, String plotLayoutId, String notes = "") {
367367
[
368368
type : 'Feature',
369369
geometry : plotGeometry,
@@ -388,7 +388,7 @@ class ParatooProtocolConfig {
388388
plotGeometry
389389
}
390390

391-
static Map createLineStringFeatureFromGeoJSON (List plotLayoutPoints, String name, def plotLayoutId, String notes = "") {
391+
static Map createLineStringFeatureFromGeoJSON (List plotLayoutPoints, String name, String plotLayoutId, String notes = "") {
392392
Map plotGeometry = toLineStringGeometry(plotLayoutPoints)
393393
createFeatureObject(plotGeometry, name, plotLayoutId, notes)
394394
}

src/test/groovy/au/org/ala/ecodata/ParatooServiceSpec.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
332332

333333
and:
334334
site.name == "SATFLB0001 - Control (100 x 100)"
335-
site.description == "SATFLB0001 - Control (100 x 100)"
336-
site.notes == "some comment"
337-
site.type == "surveyArea"
335+
site.description == "SATFLB0001 - Control (100 x 100) (convex hull of all features)"
336+
site.notes == "Core monitoring plot some comment"
337+
site.type == "compound"
338338
site.publicationStatus == "published"
339339
site.externalIds[0].externalId == "2"
340340
site.externalIds[0].idType == ExternalId.IdType.MONITOR_PLOT_GUID

src/test/groovy/au/org/ala/ecodata/paratoo/ParatooProtocolConfigSpec.groovy

+77-16
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ class ParatooProtocolConfigSpec extends Specification {
134134
then:
135135
config.getStartDate(observation) == "2022-09-21T01:55:44Z"
136136
config.getEndDate(observation) == "2022-09-21T01:55:44Z"
137-
config.getGeoJson(observation) == [type: "Feature", geometry: [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 (100 x 100)", externalId: 1, description: "QDASEQ0001 - Control (100 x 100)", notes: "some comment"]]
137+
config.getGeoJson(observation) == [
138+
type: "Feature",
139+
geometry: [
140+
type: "Polygon",
141+
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]]]
142+
],
143+
properties: [name: "QDASEQ0001 - Control (100 x 100)", externalId: "1", description: "QDASEQ0001 - Control (100 x 100)", notes: "Core monitoring plot some comment"]
144+
]
138145
}
139146

140147
def "The basal-area-dbh-measure-survey can be used with this config"() {
@@ -184,20 +191,72 @@ class ParatooProtocolConfigSpec extends Specification {
184191
config.getStartDate(observation) == "2023-09-22T00:59:47Z"
185192
config.getEndDate(observation) == "2023-09-23T00:59:47Z"
186193
config.getGeoJson(observation) == [
187-
type : "Feature",
188-
geometry : [
189-
type : "Polygon",
190-
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]]]],
191-
properties: ["name": "SATFLB0001 - Control (100 x 100)", externalId: 2, description: "SATFLB0001 - Control (100 x 100)", notes: "some comment"]
194+
type:"Feature",
195+
geometry:[
196+
coordinates:[[[138.6372, -34.9723], [138.6371, -34.9723], [138.6371, -34.9714], [138.6382, -34.9714], [138.6383, -34.9714], [138.6383, -34.9723], [138.6372, -34.9723]]],
197+
type:"Polygon"
198+
],
199+
properties:[name:"SATFLB0001 - Control (100 x 100)", externalId:"2", notes:"Core monitoring plot some comment", description:"SATFLB0001 - Control (100 x 100) (convex hull of all features)"],
200+
features:[
201+
[
202+
type:"Feature",
203+
geometry:[
204+
type:"Polygon",
205+
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]]]
206+
],
207+
properties:[name:"SATFLB0001 - Control (100 x 100)", externalId:"2", description:"SATFLB0001 - Control (100 x 100)", notes:"Core monitoring plot some comment"]],
208+
[
209+
type:"Feature",
210+
geometry:[
211+
type:"Polygon",
212+
coordinates:[[[138.6371026907952, -34.971403261821905], [138.63709732396242, -34.972304399720215], [138.6381916652405, -34.972304399720215], [138.63819166764344, -34.9714076576406], [138.6371026907952, -34.971403261821905]]]
213+
],
214+
properties:[
215+
name:"SATFLB0001 - Control (100 x 100)", externalId:"2", description:"SATFLB0001 - Control (100 x 100)", notes:"Fauna plot some comment"
216+
]
217+
]
218+
]
192219
]
193-
config.getGeoJson(observation, activityForm).features == [[
194-
type : "Feature",
195-
geometry : [
196-
type : "Point",
197-
coordinates: [149.0651491, -35.2592444]
220+
config.getGeoJson(observation, activityForm).features == [
221+
[
222+
type:"Feature",
223+
geometry:[
224+
type:"Point",
225+
coordinates:[149.0651491, -35.2592444]
226+
],
227+
properties:[
228+
name:"Point aParatooForm 2-1",
229+
externalId:37,
230+
id:"aParatooForm 2-1"
231+
]
198232
],
199-
properties: ["name": "Point aParatooForm 2-1", externalId: 37, id: "aParatooForm 2-1"]
200-
]]
233+
[
234+
type:"Feature",
235+
geometry:[
236+
type:"Polygon",
237+
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]]]
238+
],
239+
properties:[
240+
name:"SATFLB0001 - Control (100 x 100)",
241+
externalId:"2",
242+
description:"SATFLB0001 - Control (100 x 100)",
243+
notes:"Core monitoring plot some comment"
244+
]
245+
],
246+
[
247+
type:"Feature",
248+
geometry:[
249+
type:"Polygon",
250+
coordinates:[[[138.6371026907952, -34.971403261821905], [138.63709732396242, -34.972304399720215], [138.6381916652405, -34.972304399720215], [138.63819166764344, -34.9714076576406], [138.6371026907952, -34.971403261821905]]]
251+
],
252+
properties:[
253+
name:"SATFLB0001 - Control (100 x 100)",
254+
externalId:"2",
255+
description:"SATFLB0001 - Control (100 x 100)",
256+
notes:"Fauna plot some comment"
257+
]
258+
]
259+
]
201260
}
202261

203262
def "The observations from opportunistic-survey can be filtered"() {
@@ -265,7 +324,9 @@ class ParatooProtocolConfigSpec extends Specification {
265324
features : [[type: "Feature", geometry: [type: "Point", coordinates: [138.63, -35.0005]], properties:[name:"Point aParatooForm 1-1", externalId:40, id:"aParatooForm 1-1"]]],
266325
properties: [
267326
name : "aParatooForm 1 site - ${startDateInDefaultTimeZone}",
268-
description: "aParatooForm 1 site - ${startDateInDefaultTimeZone} (convex hull of all features)"
327+
description: "aParatooForm 1 site - ${startDateInDefaultTimeZone} (convex hull of all features)",
328+
externalId: "",
329+
notes: "",
269330
]
270331
]
271332
}
@@ -281,7 +342,7 @@ class ParatooProtocolConfigSpec extends Specification {
281342
]
282343

283344
when:
284-
result = ParatooProtocolConfig.createLineStringFeatureFromGeoJSON([[lat: 1, lng: 2], [lat: 3, lng: 4], [lat: 5, lng: 6]], "test name", 1, "test notes")
345+
result = ParatooProtocolConfig.createLineStringFeatureFromGeoJSON([[lat: 1, lng: 2], [lat: 3, lng: 4], [lat: 5, lng: 6]], "test name", "1", "test notes")
285346

286347
then:
287348
result == [
@@ -292,7 +353,7 @@ class ParatooProtocolConfigSpec extends Specification {
292353
],
293354
"properties": [
294355
"name" : "test name",
295-
"externalId" : 1,
356+
"externalId" : "1",
296357
"description": "test name",
297358
"notes" : "test notes"
298359
]

0 commit comments

Comments
 (0)