Skip to content

Commit 9305372

Browse files
committed
consolidate csw entity handler + data from distributionInfo
1 parent b925d64 commit 9305372

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

inst/metadata/entity/entity_handler_ogc_csw.R

+30-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
5858
#type
5959
if(length(rec$hierarchyLevel)>0) entity$setType(key = "generic", type = rec$hierarchyLevel[[1]]$attrs$codeListValue)
6060
#language
61-
entity$setLanguage(if(is(rec$language,"ISOLanguage")) rec$language$attrs$codeListValue else rec$language)
61+
lang = if(is(rec$language,"ISOLanguage")) rec$language$attrs$codeListValue else rec$language
62+
entity$setLanguage(if(!is.na(lang)) lang else "eng")
6263
#srid
6364
if(length(rec$referenceSystemInfo)>0){
6465
code = rec$referenceSystemInfo[[1]]$referenceSystemIdentifier$code
@@ -170,7 +171,7 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
170171
entity$setDescription("edition", rec$identificationInfo[[1]]$citation$edition)
171172
}
172173
status = rec$identificationInfo[[1]]$status
173-
if(length(status)>0) entity$setDescription("status", status[[1]]$attrs$codeListValue)
174+
if(length(status)>0) if(nzchar(status[[1]]$attrs$codeListValue)) entity$setDescription("status", status[[1]]$attrs$codeListValue)
174175
#subject
175176
entity$subjects = lapply(rec$identificationInfo[[1]]$descriptiveKeywords, function(dk){
176177
subject = geoflow_subject$new()
@@ -234,6 +235,7 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
234235
if(is(constraint, "ISOLegalConstraints")){
235236
#use constraints
236237
use_values = lapply(constraint$useConstraints, function(x){x$attrs$codeListValue})
238+
use_values = use_values[use_values != ""]
237239
if(length(use_values)>0){
238240
for(use_value in use_values){
239241
use_right = geoflow_right$new()
@@ -244,6 +246,7 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
244246
}
245247
#access constraints
246248
access_values = lapply(constraint$accessConstraints, function(x){x$attrs$codeListValue})
249+
access_values = access_values[access_values != ""]
247250
if(length(access_values)>0){
248251
for(access_value in access_values){
249252
access_right = geoflow_right$new()
@@ -379,6 +382,31 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
379382
}
380383
}
381384

385+
#data
386+
if(!is.null(rec$distributionInfo))
387+
tro = rec$distributionInfo$transferOptions
388+
if(!is.null(tro)){
389+
onLine = tro[[1]]$onLine
390+
if(length(onLine)>0){
391+
onLineToDownload = onLine[sapply(onLine, function(x){x$protocol == "WWW:DOWNLOAD-1.0-http--download"})]
392+
if(length(onLineToDownload)>0){
393+
g_data = geoflow_data$new()
394+
onLineToDownload = onLineToDownload[[1]]
395+
outres = onLineToDownload$name
396+
attr(outres, "uri") = onLineToDownload$linkage$value
397+
g_data$setSource(outres)
398+
g_data$sourceType = switch(mime::guess_type(onLineToDownload$linkage$value),
399+
"text/csv" = "csv",
400+
"application/zip" = "zip",
401+
"application/x-qgis" = "shp",
402+
"application/geopackage+sqlite3" = "gpkg",
403+
"application/x-netcdf" = "nc",
404+
"image/tiff" = "geotiff"
405+
)
406+
entity$setData(g_data)
407+
}
408+
}
409+
}
382410
return(entity)
383411
})
384412

0 commit comments

Comments
 (0)