@@ -12,9 +12,6 @@ import org.codehaus.jackson.map.ObjectMapper
12
12
import org.grails.web.converters.marshaller.json.CollectionMarshaller
13
13
import org.grails.web.converters.marshaller.json.MapMarshaller
14
14
15
- import java.time.format.DateTimeTextProvider
16
- import java.time.temporal.TemporalField
17
-
18
15
import static grails.async.Promises.waitAll
19
16
/**
20
17
* Tests for the ParatooService.
@@ -82,6 +79,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
82
79
Service . findAll(). each { it. delete() }
83
80
UserPermission . findAll(). each { it. delete() }
84
81
Program . findAll(). each { it. delete() }
82
+ Site . findAll(). each { it. delete() }
85
83
}
86
84
87
85
def cleanup () {
@@ -339,7 +337,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
339
337
340
338
and :
341
339
site. name == " SATFLB0001 - Control (100 x 100)"
342
- site. description == " SATFLB0001 - Control (100 x 100) (convex hull of all features) "
340
+ site. description == " SATFLB0001 - Control (100 x 100)"
343
341
site. notes == " Core monitoring plot some comment"
344
342
site. type == " compound"
345
343
site. publicationStatus == " published"
@@ -350,6 +348,121 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
350
348
351
349
}
352
350
351
+ void " The service will create a new site if ploy layout has been updated or use existing site" () {
352
+ setup :
353
+ String projectId = ' p1'
354
+ String orgMintedId = ' d1'
355
+ Date afterSubmissionDate = DateUtil . parseWithMilliseconds(" 2023-09-15T06:00:11.996Z" )
356
+ Date beforeSubmissionDate = DateUtil . parseWithMilliseconds(" 2023-09-14T06:00:11.996Z" )
357
+ new Site (
358
+ name : " SATFLB0001 - Control (100 x 100)" ,
359
+ siteId : " s0" ,
360
+ extent : [geometry : DUMMY_POLYGON ],
361
+ description : " SATFLB0001 - Control (100 x 100)" ,
362
+ notes : " Core monitoring plot some comment" ,
363
+ type : " compound" ,
364
+ externalIds : [new ExternalId (externalId : " 2" , idType : ExternalId.IdType . MONITOR_PLOT_GUID )],
365
+ dateCreated : afterSubmissionDate,
366
+ lastUpdated : afterSubmissionDate
367
+ ). save(flush : true )
368
+ ParatooProtocolId protocol = new ParatooProtocolId (id : " 1" , version : 1 )
369
+ ParatooCollection collection = new ParatooCollection (
370
+ orgMintedUUID :orgMintedId,
371
+ coreProvenance : [
372
+ " system_core" : " <system-core>" ,
373
+ " version_core" : " <core-version>"
374
+ ]
375
+ )
376
+ ParatooCollectionId paratooCollectionId = buildCollectionId(" mintCollectionIdBasalAreaPayload" ," guid-3" )
377
+ Map dataSet = [dataSetId :' d1' , grantId :' g1' , surveyId :paratooCollectionId. toMap()]
378
+ ParatooProject project = new ParatooProject (id : projectId, project : new Project (projectId : projectId, custom : [dataSets : [dataSet]]))
379
+ Map surveyData = readSurveyData(' basalAreaDbhReverseLookup' )
380
+ Map site
381
+
382
+ when :
383
+ Map result = service. submitCollection(collection, project)
384
+ waitAll(result. promise)
385
+ println (" finished waiting" )
386
+
387
+ then :
388
+ 1 * webService. doPost(* _) >> [resp : surveyData]
389
+ 1 * tokenService. getAuthToken(true ) >> Mock (AccessToken )
390
+ 2 * projectService. updateDataSet(projectId, _) >> [status : ' ok' ]
391
+ 0 * siteService. create(_)
392
+ 1 * activityService. create({
393
+ it. startDate == " 2023-09-22T00:59:47Z" && it. endDate == " 2023-09-23T00:59:47Z" &&
394
+ it. plannedStartDate == " 2023-09-22T00:59:47Z" && it. plannedEndDate == " 2023-09-23T00:59:47Z" &&
395
+ it. externalIds[0 ]. externalId == " d1" && it. externalIds[0 ]. idType == ExternalId.IdType . MONITOR_MINTED_COLLECTION_ID
396
+ }) >> [activityId : ' 123' ]
397
+ 1 * recordService. getAllByActivity(' 123' ) >> []
398
+ 1 * settingService. getSetting(' paratoo.surveyData.mapping' ) >> {
399
+ ([" guid-3" : [
400
+ " name" : " Basal Area - DBH" ,
401
+ " usesPlotLayout" : true ,
402
+ " tags" : [" survey" ],
403
+ " apiEndpoint" : " basal-area-dbh-measure-surveys" ,
404
+ " overrides" : [
405
+ " dataModel" : null ,
406
+ " viewModel" : null
407
+ ]
408
+ ]] as JSON ). toString()
409
+ }
410
+ 1 * userService. getCurrentUserDetails() >> [userId : userId]
411
+ 1 * userService. setCurrentUser(userId)
412
+
413
+ when :
414
+ String date = DateUtil . format(new Date ())
415
+ date = date. replace(" Z" , " .999Z" )
416
+ surveyData[" collections" ][" basal-area-dbh-measure-survey" ][" plot_visit" ][" plot_layout" ][" updatedAt" ] = [date]
417
+ result = service. submitCollection(collection, project)
418
+
419
+ then :
420
+ 1 * webService. doPost(* _) >> [resp : surveyData]
421
+ 1 * tokenService. getAuthToken(true ) >> Mock (AccessToken )
422
+ 2 * projectService. updateDataSet(projectId, _) >> [status : ' ok' ]
423
+ 1 * siteService. create(_) >> { site = it[0 ]; [siteId : ' s1' ] }
424
+ 1 * activityService. create({
425
+ it. startDate == " 2023-09-22T00:59:47Z" && it. endDate == " 2023-09-23T00:59:47Z" &&
426
+ it. plannedStartDate == " 2023-09-22T00:59:47Z" && it. plannedEndDate == " 2023-09-23T00:59:47Z" &&
427
+ it. externalIds[0 ]. externalId == " d1" && it. externalIds[0 ]. idType == ExternalId.IdType . MONITOR_MINTED_COLLECTION_ID
428
+ }) >> [activityId : ' 123' ]
429
+ 1 * recordService. getAllByActivity(' 123' ) >> []
430
+ 1 * settingService. getSetting(' paratoo.surveyData.mapping' ) >> {
431
+ ([" guid-3" : [
432
+ " name" : " Basal Area - DBH" ,
433
+ " usesPlotLayout" : true ,
434
+ " tags" : [" survey" ],
435
+ " apiEndpoint" : " basal-area-dbh-measure-surveys" ,
436
+ " overrides" : [
437
+ " dataModel" : null ,
438
+ " viewModel" : null
439
+ ]
440
+ ]] as JSON ). toString()
441
+ }
442
+ 1 * userService. getCurrentUserDetails() >> [userId : userId]
443
+ 1 * userService. setCurrentUser(userId)
444
+ result. updateResult == [status : ' ok' ]
445
+ }
446
+
447
+ void " isUpdatedPlotLayout should check plot layout has been updated after site has been updated" () {
448
+ given :
449
+ def date1 = DateUtil . parseWithMilliseconds(" 2023-09-22T00:59:47.111Z" )
450
+ def date2 = DateUtil . parseWithMilliseconds(" 2023-09-23T00:59:47.111Z" )
451
+ def date3 = DateUtil . parseWithMilliseconds(" 2023-09-24T00:59:47.111Z" )
452
+
453
+ when :
454
+ def result = service. isUpdatedPlotLayout(date1, date2)
455
+
456
+ then :
457
+ result
458
+
459
+ when :
460
+ result = service. isUpdatedPlotLayout(date3, date2)
461
+
462
+ then :
463
+ ! result
464
+ }
465
+
353
466
private Map getProject (){
354
467
[
355
468
projectId :" p1" ,
0 commit comments