Skip to content

Commit 918bdc0

Browse files
committed
consolidate csw entity handler
1 parent f20e3a0 commit 918bdc0

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

inst/metadata/entity/entity_handler_ogc_csw.R

+35-14
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,25 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
3636
contact$setFirstName(ind_parts[1])
3737
contact$setLastName(ind_parts[2])
3838
}
39-
if(!is.null(rp$contactInfo$address$deliveryPoint)) if(!is.na(rp$contactInfo$address$deliveryPoint)) contact$setPostalAddress(rp$contactInfo$address$deliveryPoint)
40-
if(!is.null(rp$contactInfo$address$postalCode)) if(!is.na(rp$contactInfo$address$postalCode)) contact$setPostalCode(rp$contactInfo$address$postalCode)
41-
if(!is.null(rp$contactInfo$address$city)) if(!is.na(rp$contactInfo$address$city)) contact$setCity(rp$contactInfo$address$city)
42-
if(!is.null(rp$contactInfo$address$country)) if(!is.na(rp$contactInfo$address$country)) contact$setCountry(rp$contactInfo$address$country)
43-
if(!is.null(rp$contactInfo$address$electronicMailAddress)) if(!is.na(rp$contactInfo$address$electronicMailAddress)) contact$setEmail(rp$contactInfo$address$electronicMailAddress)
44-
if(!is.null(rp$contactInfo$phone$voice)) if(!is.na(rp$contactInfo$phone$voice)) contact$setVoice(rp$contactInfo$phone$voice)
45-
if(!is.null(rp$contactInfo$phone$facsimile)) if(!is.na(rp$contactInfo$phone$facsimile)) contact$setFacsimile(rp$contactInfo$phone$facsimile)
46-
if(!is.null(rp$contactInfo$onlineResource$name)) if(!is.na(rp$contactInfo$onlineResource$name)) contact$setWebsiteName(rp$contactInfo$onlineResource$name)
47-
if(is(rp$contactInfo$onlineResource$linkage, "ISOURL")){
48-
contact$setWebsiteUrl(rp$contactInfo$onlineResource$linkage$value)
39+
if(length(rp$contactInfo$address)>0){
40+
address = rp$contactInfo$address[[1]]
41+
if(!is.null(address$deliveryPoint)) if(!is.na(address$deliveryPoint)) contact$setPostalAddress(address$deliveryPoint)
42+
if(!is.null(address$postalCode)) if(!is.na(address$postalCode)) contact$setPostalCode(address$postalCode)
43+
if(!is.null(address$city)) if(!is.na(address$city)) contact$setCity(address$city)
44+
if(!is.null(address$country)) if(!is.na(address$country)) contact$setCountry(address$country)
45+
if(!is.null(address$electronicMailAddress)) if(!is.na(address$electronicMailAddress)) contact$setEmail(address$electronicMailAddress)
46+
}
47+
if(length(rp$contactInfo$phone)>0){
48+
phone = rp$contactInfo$phone[[1]]
49+
if(!is.null(phone$voice)) if(!is.na(phone$voice)) contact$setVoice(phone$voice)
50+
if(!is.null(phone$facsimile)) if(!is.na(phone$facsimile)) contact$setFacsimile(phone$facsimile)
51+
}
52+
if(length(rp$contactInfo$onlineResource)>0){
53+
or = rp$contactInfo$onlineResource[[1]]
54+
if(!is.null(or$name)) if(!is.na(or$name)) contact$setWebsiteName(or$name)
55+
if(is(or$linkage, "ISOURL")){
56+
contact$setWebsiteUrl(or$linkage$value)
57+
}
4958
}
5059
contact$setRole(rp$role$attrs$codeListValue)
5160
return(contact$clone(deep = TRUE))
@@ -58,11 +67,19 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
5867
#type
5968
if(length(rec$hierarchyLevel)>0) entity$setType(key = "generic", type = rec$hierarchyLevel[[1]]$attrs$codeListValue)
6069
#language
61-
lang = if(is(rec$language,"ISOLanguage")) rec$language$attrs$codeListValue else rec$language
70+
lang = if(is(rec$language,"ISOLanguage")){
71+
rec$language$attrs$codeListValue
72+
}else if(is(rec$language, "ISOElementSequence")){
73+
langXML = XML::xmlParse(rec$language$value)
74+
XML::xmlGetAttr(XML::xmlChildren(langXML)[[1]], "codeListValue")
75+
}else{
76+
rec$language
77+
}
6278
entity$setLanguage(if(!is.na(lang)) lang else "eng")
6379
#srid
6480
if(length(rec$referenceSystemInfo)>0){
6581
code = rec$referenceSystemInfo[[1]]$referenceSystemIdentifier$code
82+
code = regmatches(code,regexpr("EPSG:[0-9]+",code))
6683
code_parts = unlist(strsplit(code, "/"))
6784
code = code_parts[length(code_parts)]
6885
code_parts = unlist(strsplit(code, ":"))
@@ -101,7 +118,9 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
101118
#creator
102119
#metadata contacts
103120
for(poc in rec$contact) if(length(poc)>1){
104-
entity$addContact(createContactFromResponsibleParty(poc))
121+
contact_metadata = createContactFromResponsibleParty(poc)
122+
contact_metadata$setRole("metadata")
123+
entity$addContact(contact_metadata)
105124
}
106125

107126
#metadata date
@@ -220,9 +239,11 @@ handle_entities_csw <- function(handler, source, config, handle = TRUE){
220239
if(is(time_extent$extent, "GMLTimeInstant")){
221240
entity$temporal_extent = list(instant = time_extent$extent$timePosition$value)
222241
}else if(is(time_extent$extent, "GMLTimePeriod")){
242+
start = time_extent$extent$beginPosition$value
243+
end = time_extent$extent$endPosition$value
223244
entity$temporal_extent = list(
224-
start = time_extent$extent$beginPosition$value,
225-
end = time_extent$extent$endPosition$value
245+
start = if(regexpr(" ", start)>0) as.POSIXct(start) else as.Date(start),
246+
end = if(regexpr(" ", end)>0) as.POSIXct(end) else as.Date(end)
226247
)
227248
}
228249
}

0 commit comments

Comments
 (0)