Skip to content

Commit

Permalink
consolidate CSW entity handler
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Nov 27, 2024
1 parent 6f3797c commit dc8be62
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions inst/metadata/entity/entity_handler_csw.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
if(!is.null(rp$contactInfo$phone$voice)) if(!is.na(rp$contactInfo$phone$voice)) contact$setVoice(rp$contactInfo$phone$voice)
if(!is.null(rp$contactInfo$phone$facsimile)) if(!is.na(rp$contactInfo$phone$facsimile)) contact$setFacsimile(rp$contactInfo$phone$facsimile)
if(!is.null(rp$contactInfo$onlineResource$name)) if(!is.na(rp$contactInfo$onlineResource$name)) contact$setWebsiteName(rp$contactInfo$onlineResource$name)
if(!is.null(rp$contactInfo$onlineResource$linkage$value)) if(!is.na(rp$contactInfo$onlineResource$linkage$value)) contact$setWebsiteUrl(rp$contactInfo$onlineResource$linkage$value)
if(is(rp$contactInfo$onlineResource$linkage, "ISOURL")){
contact$setWebsiteUrl(rp$contactInfo$onlineResource$linkage$value)
}
contact$setRole(rp$role$attrs$codeListValue)
return(contact$clone(deep = TRUE))
}

entities = lapply(recs, function(rec){
entity = geoflow_entity$new()
entity$setIdentifier("id", rec$fileIdentifier)

print(sprintf("Processing metadata '%s' from CSW", rec$fileIdentifier))
#type
if(length(rec$hierarchyLevel)>0) entity$setType(key = "generic", type = rec$hierarchyLevel[[1]]$attrs$codeListValue)
#language
entity$setLanguage(rec$language$attrs$codeListValue)
entity$setLanguage(if(is.list(rec$language)) rec$language$attrs$codeListValue else rec$language)
#srid
if(length(rec$referenceSystemInfo)>0){
code = rec$referenceSystemInfo[[1]]$referenceSystemIdentifier$code
Expand Down Expand Up @@ -138,7 +140,7 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){

#doi (in case available)
hasDOI = sapply(rec$identificationInfo[[1]]$citation$identifier, function(identifier){
has = !is.character(identifier$code)
has = !is.character(identifier$code) & !is.na(identifier$code)
if(has) has = regexpr(pattern = "dx.doi.org", identifier$code$attrs[["xlink:href"]]) > 0
return(has)
})
Expand Down Expand Up @@ -268,13 +270,15 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
for(resource_format in resource_formats){
format = geoflow_format$new()
format$setKey("resource")
name = resource_format$name
if(is(name, "ISOAnchor")){
format$setUri(name$attrs[["xlink:href"]])
name = name$value
if(is(resource_format, "ISOFormat")){
name = resource_format$name
if(is(name, "ISOAnchor")){
format$setUri(name$attrs[["xlink:href"]])
name = name$value
}
format$setName(name)
entity$addFormat(format)
}
format$setName(name)
entity$addFormat(format)
}
}
}
Expand All @@ -284,7 +288,6 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
#distributors
distributors = rec$distributionInfo$distributor
for(distributor in distributors){
print(distributor$distributorContact)
entity$addContact(createContactFromResponsibleParty(distributor$distributorContact))
}
#distribution formats
Expand All @@ -293,13 +296,15 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
for(distrib_format in distrib_formats){
format = geoflow_format$new()
format$setKey("distribution")
name = distrib_format$name
if(is(name, "ISOAnchor")){
format$setUri(name$attrs[["xlink:href"]])
name = name$value
if(is(distrib_format, "ISOFormat")){
name = distrib_format$name
if(is(name, "ISOAnchor")){
format$setUri(name$attrs[["xlink:href"]])
name = name$value
}
format$setName(name)
entity$addFormat(format)
}
format$setName(name)
entity$addFormat(format)
}
}

Expand Down

0 comments on commit dc8be62

Please sign in to comment.