-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathLayerController.groovy
814 lines (759 loc) · 31 KB
/
LayerController.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
/*
* Copyright (C) 2016 Atlas of Living Australia
* All Rights Reserved.
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License") you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*/
package au.org.ala.spatial
import au.ala.org.ws.security.RequireApiKey
import au.org.ala.plugins.openapi.Path
import com.opencsv.CSVWriter
import grails.converters.JSON
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.media.ArraySchema
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import org.apache.commons.lang.StringEscapeUtils
import org.apache.commons.lang.StringUtils
import org.apache.commons.lang3.ArrayUtils
import javax.ws.rs.Produces
import java.text.SimpleDateFormat
import static io.swagger.v3.oas.annotations.enums.ParameterIn.PATH
import static io.swagger.v3.oas.annotations.enums.ParameterIn.QUERY
class LayerController {
LayerService layerService
FieldService fieldService
SpatialObjectsService spatialObjectsService
FileService fileService
SpatialConfig spatialConfig
// HTML Page
def list() {
def fields = fieldService.getFieldsByCriteria('')
def layers = layerService.getLayers().collect { layer ->
def map = layer.properties as Map
fields.each { field ->
if (field.spid == layer.id.toString()) {
if (map?.last_update) {
map.put('last_update', field?.last_update?.getTime() < ((Date) map?.last_update)?.getTime() ? field.last_update : map.last_update)
} else if (field.last_update) {
map.put('last_update', field.last_update)
}
}
}
map
}
render(view: "index.gsp", model: [layers: layers])
}
@Operation(
method = "GET",
tags = "layers",
operationId = "getLayerImage",
summary = "Get thumbnail image of layer",
parameters = [
@Parameter(
name = "name",
in = PATH,
schema = @Schema(implementation = String),
description = "Layer short name",
required = false
)
],
responses = [
@ApiResponse(
description = "Image",
responseCode = "200",
content = [
@Content(
mediaType = "image/jpg"
)
]
)
],
security = []
)
@Path("layer/img/{name}")
@Produces("image/jpg")
def img(String id) {
if (layerService.getLayerByName(id)) {
File f = new File(spatialConfig.data.dir + '/public/thumbnail/' + id + '.jpg')
render(file: f, fileName: "${id}.jpg", contentType: "image/jpg")
} else {
response.sendError(404, "$id not found")
}
}
@Operation(
method = "GET",
tags = "layers",
operationId = "getLayersCSV",
summary = "Get CSV list of layers",
parameters = [
@Parameter(
name = "usage",
in = QUERY,
schema = @Schema(implementation = Boolean),
description = "Set as True to include layer usage information",
required = false
),
@Parameter(
name = "months",
in = QUERY,
schema = @Schema(implementation = Integer),
description = "Number of months for the usage. Default is 12",
required = false
)
],
responses = [
@ApiResponse(
description = "CSV of layers",
responseCode = "200",
content = [
@Content(
mediaType = "application/csv"
)
]
)
],
security = []
)
@Path("layers/layers.csv")
@Produces("application/csv")
def csvlist() {
List layers = layerService.getLayers()
String[] header = ["ID",
"Short name",
"Name",
"Description",
"Data provider",
"Provider website",
"Provider role",
"Metadata date",
"Reference date",
"Licence level",
"Licence info",
"Licence notes",
"Type",
"Classification 1",
"Classification 2",
"Units",
"Notes",
"More information",
"Keywords", "Date Added"]
Map<String, Map> usage = null
if ("true".equalsIgnoreCase(params.usage as String)) {
header = ArrayUtils.addAll(header, "Usage")
usage = layerUsage(params.months as Integer ?: 12).get("Total")
}
response.setContentType("text/csv charset=UTF-8")
response.setHeader("Content-Disposition", "inlinefilename=ALA_Spatial_Layers.csv")
CSVWriter cw = null
try {
cw = new CSVWriter(response.getWriter())
cw.writeNext("Please provide feedback on the 'keywords' columns to data_management@ala.org.au".split("\n"))
cw.writeNext(header)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd")
for (Layers lyr : layers) {
String[] row = [
String.valueOf(lyr.id),
String.valueOf(lyr.name),
String.valueOf(lyr.displayname),
String.valueOf(lyr.description?.replaceAll("\n", " ")),
String.valueOf(lyr.source),
String.valueOf(lyr.source_link),
String.valueOf(lyr.respparty_role),
String.valueOf(lyr.mddatest),
String.valueOf(lyr.citation_date),
String.valueOf(lyr.licence_level),
String.valueOf(lyr.licence_link),
String.valueOf(lyr.licence_notes?.replaceAll("\n", " ")),
String.valueOf(lyr.type),
String.valueOf(lyr.classification1),
String.valueOf(lyr.classification2),
String.valueOf(lyr.environmentalvalueunits),
String.valueOf(lyr.notes?.replaceAll("\n", " ")),
String.valueOf(lyr.metadatapath),
String.valueOf(lyr.keywords),
String.valueOf(lyr.getDt_added() == null ? '' : sdf.format(lyr.getDt_added()))]
if ("true".equalsIgnoreCase(params.usage as String)) {
row = ArrayUtils.add(row, (String) usage.getOrDefault(String.valueOf(lyr.id) , 0) as String)
}
cw.writeNext(row)
}
cw.flush()
} catch (err) {
log.trace(err.getMessage(), err)
} finally {
if (cw != null) {
try {
cw.close()
} catch (err) {
log.trace(err.getMessage(), err)
}
}
}
}
/**
* Get layer usage count by usage type. Includes 'Total' for all usage.
*
* Layer usage is determined from specific Log and Task records created by spatial-hub.
*
* spatial-hub use of a layer
*
* Add to Map | Layer
* log search
* category2=ToolAddLayerService
* data.0 -> array of fieldIds
*
* Add to Map | Area | Environmental envelope
* task search
* name=Envelope
* input[name=envelope].value -> array of string -> split(':')[0] for fieldIds
*
* Tools | Scatterplot - single
* task search
* name=ScatterplotCreate
* input[name=layer].value -> array of fieldIds
*
* Tools | Scatterplot - multiple
* task search
* name=ScatterplotList
* input[name=layer].value -> array of fieldIds
*
* Tools | Tabulate
* task search
* category2=Tabulation
* data.layer1 and data.layer2
*
* Tools | Predict
* task search
* name=Maxent
* input[name=layer].value -> array of fieldIds
*
* Tools | Classify
* task search
* name=Classification
* input[name=layer].value -> array of fieldIds
*
* Tools | Classify
* task search
* name=SpeciesByLayer
* input[name=layer].value -> array of fieldIds
*
* spatial-hub use of an area
*
* Add to Map | Area | Select area from polygonal layer
* Add to Map | Area | Gazetteer polygon
* log search
* category2=Area
* data.pid -> select fid from objects where pid=data.pid
*
* @return
*/
private Map<String, Map> layerUsage(Integer months) {
Map<String, Map> layerUsage = [:]
def c = Calendar.getInstance()
c.add(Calendar.MONTH, params.ageInMonths as Integer ?: (Integer.valueOf(-1) * months))
// Use as layer
def fields = fieldService.getFields(false)
def layers = [:]
Log.executeQuery("SELECT data FROM Log WHERE created is not null and created >= ${c.time} " +
"and category2='ToolAddLayerService'").each { it ->
try {
if (it) {
def layer = JSON.parse(it)
String layerId = layer['0'][0]
layers.put(layerId, layers.getOrDefault(layerId, 0) + 1)
}
} catch (Exception e) {
log.error("Error in calculating usage of tool: add layer")
}
}
layerUsage.put("Add to Map | Layer", layers)
layers = [:]
Log.executeQuery("SELECT data FROM Log WHERE created is not null and created >= ${c.time} and category2='Tabulation'").each {
try {
def layer1 = JSON.parse(it)["layer1"]
layers.put(layer1, layers.getOrDefault(layer1, 0) + 1)
def layer2 = JSON.parse(it)["layer2"]
layers.put(layer2, layers.getOrDefault(layer2, 0) + 1)
} catch (Exception e) {
log.error("Error in calculating usage of tool: tabulation")
}
}
layerUsage.put("Tools | Tabulate", layers)
layers = [:]
Log.executeQuery("SELECT data FROM Log WHERE data is not null and created is not null and created >= ${c.time} and category2='Area'").each {
try {
String pid = JSON.parse(it)["pid"]
if (pid != null) {
for (String p : pid.split("~")) {
def obj = spatialObjectsService.getObjectByPid(p)
if (obj) {
if (obj.fid != spatialConfig.userObjectsField) {
layers.put(obj.fid, layers.getOrDefault(obj.fid, 0) + 1)
}
}
}
}
} catch (Exception e) {
log.error("Error in calculating usage of areas")
}
}
layerUsage.put("Add to map | Area | Gaz or Area from polygonal layer", layers)
layers = [:]
Task.executeQuery("SELECT input FROM Task t where t.created is not null and t.created >= ${c.time} and t.status = 4 and t.name = 'Envelope'").each {
try {
if (it.name == 'envelope') {
JSON.parse(it.value).each {
def layer = it.split(':')[0]
layers.put(layer, layers.getOrDefault(layer, 0) + 1)
}
}
} catch (Exception e) {
log.error("Error in calculating usage of envelopes")
}
}
layerUsage.put("Add to Map | Area | Environmental envelope", layers)
layers = [:]
Task.executeQuery("SELECT input FROM Task t where t.created is not null and t.created >= ${c.time} and t.status = 4 and t.name = 'ScatterplotCreate'").each {
try {
if (it.name == 'layer') {
JSON.parse(it.value).each {
layers.put(it, layers.getOrDefault(it, 0) + 1)
}
}
} catch (Exception e) {
log.error("Error in calculating usage of tool: single scatterplot ")
}
}
layerUsage.put("Tools | Scatterplot - single", layers)
layers = [:]
Task.executeQuery("SELECT input FROM Task t where t.created is not null and t.created >= ${c.time} and t.status = 4 and t.name = 'ScatterplotList'").each {
try {
if (it.name == 'layer') {
JSON.parse(it.value).each {
layers.put(it, layers.getOrDefault(it, 0) + 1)
}
}
} catch (Exception e) {
log.error("Error in calculating usage of tool: multiple scatterplot")
}
}
layerUsage.put("Tools | Scatterplot - multiple", layers)
layers = [:]
Task.executeQuery("SELECT input FROM Task t where t.created is not null and t.created >= ${c.time} and t.status = 4 and t.name = 'Maxent'").each {
try {
if (it.name == 'layer') {
JSON.parse(it.value).each {
layers.put(it, layers.getOrDefault(it, 0) + 1)
}
}
} catch (Exception e) {
log.error("Error in calculating usage of tool: predict")
}
}
layerUsage.put("Tools | Predict", layers)
layers = [:]
Task.executeQuery("SELECT input FROM Task t where t.created is not null and t.created >= ${c.time} and t.status = 4 and t.name = 'Classification'").each {
try {
if (it.name == 'layer') {
JSON.parse(it.value).each {
layers.put(it, layers.getOrDefault(it, 0) + 1)
}
}
} catch (Exception e) {
log.error("Error in calculating usage of tool: classify")
}
}
layerUsage.put("Tools | Classify", layers)
layers = [:]
Task.executeQuery("SELECT input FROM Task t where t.created is not null and t.created >= ${c.time} and t.status = 4 and t.name = 'SpeciesByLayer'").each {
try {
if (it.name == 'layer') {
JSON.parse(it.value).each {
layers.put(it, layers.getOrDefault(it, 0) + 1)
}
}
} catch (Exception e) {
log.error("Error in calculating usage of tool: speccies by layer")
}
}
layerUsage.put("Tools | Species By Layer", layers)
// convert to fieldIds to layerIds and aggregate.
layers = [:]
layerUsage.each { k1, v1 ->
v1.each { k2, v2 ->
for (Fields f : fields) {
if (f.id == k2) {
layers.put(f.spid, layers.getOrDefault(f.spid, 0) + v2)
}
}
}
}
layerUsage.put("Total", layers)
layerUsage
}
@Operation(
method = "GET",
tags = "layers",
operationId = "getLayerFile",
summary = "Get zipped copy of the layer if permitted",
parameters = [
@Parameter(
name = "id",
in = PATH,
schema = @Schema(implementation = String),
description = "Layer ID",
required = false
)
],
responses = [
@ApiResponse(
description = "zipped layer file",
responseCode = "200",
content = [
@Content(
mediaType = "application/zip"
)
]
)
],
security = [@SecurityRequirement(name = 'openIdConnect')]
)
@Path("layer/download/{id}")
@Produces("application/zip")
@RequireApiKey
def download() {
String id = params.id
Layers layer = layerService.getLayerByDisplayName(id)
if (!layer) {
layer = layerService.getLayerById(Long.valueOf(id), false)
}
if (layer) {
if (downloadAllowed(layer)) {
OutputStream outputStream = null
try {
outputStream = response.outputStream as OutputStream
//write resource
response.setContentType("application/octet-stream")
response.setHeader("Content-disposition", "attachment;filename=${layer.displayname}.zip")
// When a geotiff exists, only download the geotiff
def path = "/layer/${layer.name}"
def geotiff = new File(spatialConfig.data.dir + path + ".tif")
if (geotiff.exists()) {
path += ".tif"
}
// TODO: allow download of the shapefile
fileService.write(outputStream, path)
outputStream.flush()
} catch (err) {
log.error(err.getMessage(), err)
} finally {
if (outputStream != null) {
try {
outputStream.close()
} catch (err) {
log.error(err.getMessage(), err)
}
}
}
} else {
response.status = 403
}
} else {
response.status = 404
}
}
private downloadAllowed(layer) {
return spatialConfig.download.layer.licence_levels.contains(layer.licence_level)
}
// HTML Page
def more(String id) {
Layers l = layerService.getLayerByName(id)
if (l == null) {
try {
l = layerService.getLayerById(Integer.parseInt(id))
} catch (ignored) {
}
}
Fields f = null
if (l == null) {
f = fieldService.getFieldById(id, false)
if (f) {
l = layerService.getLayerById(Integer.parseInt(f.spid))
}
}
render(view: "show.gsp", model: [layer: l, field: f, downloadAllowed: downloadAllowed(l)])
}
@Operation(
method = "GET",
tags = "layers",
operationId = "listLayers",
summary = "Get a list of all layers",
parameters = [],
responses = [
@ApiResponse(
description = "List of layers",
responseCode = "200",
content = [
@Content(
mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = Layers))
)
]
)
],
security = []
)
@Path("layers")
@Produces("application/json")
def index() {
String id = params.id
if (id == null)
if (params?.all as Boolean) {
render layerService.getLayersForAdmin() as JSON
} else {
render layerService.getLayers() as JSON
}
else
show(id)
}
@Operation(
method = "GET",
tags = "layers",
operationId = "getLayerById",
summary = "Get a layer by layer ID",
parameters = [
@Parameter(
name = "id",
in = PATH,
schema = @Schema(implementation = String),
description = "Layer ID",
required = true
)
],
responses = [
@ApiResponse(
description = "Layer",
responseCode = "200",
content = [
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Layers)
)
]
)
],
security = []
)
@Path("layer/{id}")
@Produces("application/json")
def show() {
String id = params.id
if (id == null) {
render layerService.getLayers() as JSON
} else {
Layers l = null
try {
l = layerService.getLayerById(Integer.parseInt(id), false)
} catch (err) {
log.error 'failed to get layer: ' + id, err
}
if (l == null) {
l = layerService.getLayerByName(id, false)
}
if (l == null) {
Fields f = fieldService.getFieldById(id, false)
if (f != null) {
l = layerService.getLayerById(Integer.parseInt(f.spid), false)
}
}
if (l) {
render l as JSON
} else {
response.status = 404
}
}
}
@Operation(
method = "GET",
tags = "layers",
operationId = "searchLayers",
summary = "search for layers",
parameters = [
@Parameter(
name = "q",
in = QUERY,
description = "restrict to layer names that contain this value",
schema = @Schema(implementation = String),
required = false
)
],
responses = [
@ApiResponse(
description = "List of layers",
responseCode = "200",
content = [
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Layers)
)
]
)
],
security = []
)
@Path("layers/search")
@Produces("application/json")
def search() {
render layerService.getLayersByCriteria(params.q as String) as JSON
}
@Deprecated
@Operation(
method = "GET",
tags = "layers",
operationId = "listEnvironmentalLayers",
summary = "Get a list of all environmental (raster) layers",
parameters = [],
responses = [
@ApiResponse(
description = "List of layers",
responseCode = "200",
content = [
@Content(
mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = Layers))
)
]
)
],
security = []
)
@Path("layers/grids")
@Produces("application/json")
def grids() {
render layerService.getLayersByEnvironment() as JSON
}
@Deprecated
@Operation(
method = "GET",
tags = "layers",
operationId = "listContextualLayers",
summary = "Get a list of all contextual (vector) layers",
parameters = [],
responses = [
@ApiResponse(
description = "List of layers",
responseCode = "200",
content = [
@Content(
mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = Layers))
)
]
)
],
security = []
)
@Path("layers/shapes")
@Produces("application/json")
def shapes() {
render layerService.getLayersByContextual() as JSON
}
@Deprecated
@Operation(
method = "GET",
tags = "layers",
operationId = "listLayersRIFCS",
summary = "Get a list of all layers in RIF-CS format",
parameters = [],
responses = [
@ApiResponse(
description = "List of layers",
responseCode = "200",
content = [
@Content(
mediaType = "text/xml",
array = @ArraySchema(schema = @Schema(implementation = Layers))
)
]
)
],
security = []
)
@Path("layers/rif-cs")
@Produces("text/xml")
def "rif-cs"() {
// Build XML by hand here because JSP processing seems to omit CDATA sections from the output
StringBuilder sb = new StringBuilder()
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>")
sb.append("<registryObjects xmlns=\"https://ands.org.au/standards/rif-cs/registryObjects\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://ands.org.au/standards/rif-cs/registryObjects http://services.ands.org.au/documentation/rifcs/schema/registryObjects.xsd\">")
for (Layers layer : layerService.getLayers()) {
sb.append("<registryObject group=\"Atlas of Living Australia\">")
sb.append("<key>ala.org.au/uid_" + layer.getUid() + "</key>")
sb.append("<originatingSource><![CDATA[" + layer.getMetadatapath() + "]]></originatingSource>")
sb.append("<collection type=\"dataset\">")
sb.append("<identifier type=\"local\">ala.org.au/uid_" + layer.getUid() + "</identifier>")
sb.append("<name type=\"abbreviated\">")
sb.append("<namePart>" + layer.getName() + "</namePart>")
sb.append("</name>")
sb.append("<name type=\"alternative\">")
sb.append("<namePart><![CDATA[" + layer.getDescription() + "]]></namePart>")
sb.append("</name>")
sb.append("<name type=\"primary\">")
sb.append("<namePart><![CDATA[" + layer.getDescription() + "]]></namePart>")
sb.append("</name>")
sb.append("<location>")
sb.append("<address>")
sb.append("<electronic type=\"url\">")
sb.append("<value>https://spatial.ala.org.au/layers</value>")
sb.append("</electronic>")
sb.append("</address>")
sb.append("</location>")
sb.append("<relatedObject>")
sb.append("<key>Contributor:Atlas of Living Australia</key>")
sb.append("<relation type=\"hasCollector\" />")
sb.append("</relatedObject>")
sb.append("<subject type=\"anzsrc-for\">0502</subject>")
sb.append("<subject type=\"local\">" + layer.getClassification1() + "</subject>")
if (!StringUtils.isEmpty(layer.getClassification2())) {
sb.append("<subject type=\"local\">" + layer.getClassification2() + "</subject>")
}
sb.append("<description type=\"full\"><![CDATA[" + layer.getNotes() + "]]></description>")
sb.append("<relatedInfo type=\"website\">")
sb.append("<identifier type=\"uri\"><![CDATA[" + layer.getMetadatapath() + "]]></identifier>")
sb.append("<title>Further metadata</title>")
sb.append("</relatedInfo>")
sb.append("<relatedInfo type=\"website\">")
sb.append("<identifier type=\"uri\"><![CDATA[" + layer.getSource_link() + "]]></identifier>")
sb.append("<title>Original source of this data</title>")
sb.append("</relatedInfo>")
sb.append("<rights>")
sb.append("<licence ")
if (!StringUtils.isEmpty(layer.getLicence_link())) {
sb.append("rightsUri=\"" + StringEscapeUtils.escapeXml(layer.getLicence_link()) + "\">")
} else {
sb.append(">")
}
sb.append("<![CDATA[" + layer.getLicence_notes() + "]]></licence>")
sb.append("</rights>")
sb.append("<coverage>")
sb.append("<spatial type=\"iso19139dcmiBox\">northlimit=" + layer.getMaxlatitude() + " southlimit=" + layer.getMinlatitude() + " westlimit=" + layer.getMinlongitude() + " eastLimit=" + layer.getMaxlongitude() + " projection=WGS84</spatial>")
sb.append("</coverage>")
sb.append("</collection>")
sb.append("</registryObject>")
}
sb.append("</registryObjects>")
render(contentType: "text/xml", text: sb.toString())
}
}