@@ -277,8 +277,11 @@ class ParatooService {
277
277
surveyDataAndObservations = recursivelyTransformData(form. sections[0 ]. template. dataModel, surveyDataAndObservations, form. name, 1 , config)
278
278
// If we are unable to create a site, null will be returned - assigning a null siteId is valid.
279
279
280
+ String siteName = null
280
281
if (! dataSet. siteId) {
281
- dataSet. siteId = createSiteFromSurveyData(surveyDataAndObservations, collection, surveyId, project. project, config, form)
282
+ Map site = createSiteFromSurveyData(surveyDataAndObservations, collection, surveyId, project. project, config, form)
283
+ dataSet. siteId = site. siteId
284
+ siteName = site. name
282
285
}
283
286
284
287
// plot layout is of type geoMap. Therefore, expects a site id.
@@ -290,6 +293,9 @@ class ParatooService {
290
293
dataSet. endDate = config. getEndDate(surveyDataAndObservations)
291
294
dataSet. format = DATASET_DATABASE_TABLE
292
295
dataSet. sizeUnknown = true
296
+ // Update the data set name as the information supplied during /mint-identifier isn't enough
297
+ // to ensure uniqueness
298
+ dataSet. name = buildUpdatedDataSetSummaryName(siteName, dataSet. startDate, dataSet. endDate, form. name, surveyId)
293
299
294
300
// Delete previously created activity so that duplicate species records are not created.
295
301
// Updating existing activity will also create duplicates since it relies on outputSpeciesId to determine
@@ -308,6 +314,23 @@ class ParatooService {
308
314
}
309
315
}
310
316
317
+ protected static String buildUpdatedDataSetSummaryName (String siteName , String startDate , String endDate , String protocolName , ParatooCollectionId surveyId ) {
318
+ String name = protocolName
319
+ if (siteName) {
320
+ name + = " (" + siteName + " )"
321
+ }
322
+ if (startDate && endDate && startDate != endDate) {
323
+ name + = " - " + DateUtil . formatAsDisplayDateTime(startDate) + " to " + DateUtil . formatAsDisplayDateTime(endDate)
324
+ }
325
+ else if (startDate) {
326
+ name + = " - " + DateUtil . formatAsDisplayDateTime(startDate)
327
+ }
328
+ else {
329
+ name + = " - " + DateUtil . formatAsDisplayDateTime(surveyId. eventTime)
330
+ }
331
+ name
332
+ }
333
+
311
334
/**
312
335
* Rearrange survey data to match the data model.
313
336
* e.g. [a: [b: [c: 1, d: 2], d: 1], b: [c: 1, d: 2]] => [b: [c: 1, d: 2, a: [d: 1]]]
@@ -555,12 +578,13 @@ class ParatooService {
555
578
output
556
579
}
557
580
558
- private String createSiteFromSurveyData (Map observation , ParatooCollection collection , ParatooCollectionId surveyId , Project project , ParatooProtocolConfig config , ActivityForm form ) {
581
+ private Map createSiteFromSurveyData (Map observation , ParatooCollection collection , ParatooCollectionId surveyId , Project project , ParatooProtocolConfig config , ActivityForm form ) {
559
582
String siteId = null
560
583
// Create a site representing the location of the collection
584
+ Map siteProps = null
561
585
Map geoJson = config. getGeoJson(observation, form)
562
586
if (geoJson) {
563
- Map siteProps = siteService. propertiesFromGeoJson(geoJson, ' upload' )
587
+ siteProps = siteService. propertiesFromGeoJson(geoJson, ' upload' )
564
588
List features = geoJson?. features ?: []
565
589
geoJson. remove(' features' )
566
590
siteProps. features = features
@@ -592,7 +616,7 @@ class ParatooService {
592
616
}
593
617
siteId = result. siteId
594
618
}
595
- siteId
619
+ [ siteId :siteId, name :siteProps ?. name]
596
620
}
597
621
598
622
private Map syncParatooProtocols (List<Map > protocols ) {
@@ -774,10 +798,6 @@ class ParatooService {
774
798
dataSet
775
799
}
776
800
777
- private static String buildSurveyQueryString (int start , int limit , String createdAt ) {
778
- " ?populate=deep&sort=updatedAt&pagination[start]=$start &pagination[limit]=$limit &filters[createdAt][\$ eq]=$createdAt "
779
- }
780
-
781
801
Map retrieveSurveyAndObservations (ParatooCollection collection , Map authHeader = null ) {
782
802
String apiEndpoint = PARATOO_DATA_PATH
783
803
Map payload = [
0 commit comments