Skip to content

Instantly share code, notes, and snippets.

@olivermt
Created April 24, 2012 11:00
Show Gist options
  • Select an option

  • Save olivermt/2478786 to your computer and use it in GitHub Desktop.

Select an option

Save olivermt/2478786 to your computer and use it in GitHub Desktop.
void parseXML(xml) {
//println "Now parsing ${this.class.name}"
name = xml.name
println "Now parsing ${name}"
site = xml.site
setCountry(xml.country.text())
region = xml.region
if(!xml.dateStartCollection.isEmpty()){
dateStartCollection = new Date().parse("yyyy-MM-dd", xml.dateStartCollection.text())
}
if(!xml.dateEndCollection.isEmpty()){
dateEndCollection = new Date().parse("yyyy-MM-dd", xml.dateEndCollection.text())
}
if(!xml.collectedby.isEmpty()) {
xml.collectedby.each {
def companyInstance = Company.findByName(it.name.text()) ?: throwRuntimeException("Company named " + it.name.text() + " described in \"collectedby\" does not exist.")
addToCollectedby(companyInstance)
}
}
if(!xml.dateApproved.isEmpty()){
dateApproved = new Date().parse("yyyy-MM-dd", xml.dateApproved.text())
}
if(!xml.approvedBy.isEmpty()) {
def personInstance = User.findByName(xml.approvedBy.text()) ?: throwRuntimeException("Person named " + xml.approvedBy.text() + " described in \"approvedby\" does not exist.")
approvedBy = personInstance
}
if(!xml.dateIssued.isEmpty()){
dateIssued = new Date().parse("yyyy-MM-dd", xml.dateIssued.text())
}
if(!xml.issuedby.isEmpty()) {
def companyInstance = Company.findByName(xml.issuedby.text()) ?: throwRuntimeException("Company named " + xml.issuedby.text() + " described in \"issuedby\" does not exist.")
issuedby = companyInstance
}
if(!xml.dateUpdated.isEmpty()){
dateUpdated = new Date().parse("yyyy-MM-dd", xml.dateUpdated.text())
}
if(!xml.updatedby.isEmpty()) {
def personInstance = User.findByName(xml.updatedby.text()) ?: throwRuntimeException("Person named " + xml.updatedby.text() + " described in \"updatedby\" does not exist.")
updatedby = personInstance
}
//Only allow upload of data to companies that already exist
if(!xml.owner.isEmpty()) {
def companyInstance = Company.findByName(xml.owner.text()) ?: throwRuntimeException("Company named " + xml.owner.text() + " described in \"owner\" does not exist.")
owner = companyInstance
}
setDataSetScale(xml.dataSetScale.text())
dataSummary = xml.dataSummary
location = xml.location
comment = xml.comment
if(!xml.outcropPhysicalDescription.isEmpty()) {
outcropPhysicalDescription = new PhysicalDescription()
outcropPhysicalDescription.outcrop = this
outcropPhysicalDescription.parseXML(xml.outcropPhysicalDescription)
}
if(!xml.modernSystemPhysicalDescription.isEmpty()) {
modernSystemPhysicalDescription = new ModernSystemPhysicalDescription()
modernSystemPhysicalDescription.outcrop = this
modernSystemPhysicalDescription.parseXML(xml.modernSystemPhysicalDescription)
}
if(!xml.literatureReference.isEmpty()) {
xml.literatureReference.each {
Literature lit = new Literature()
lit.parseXML(it)
addToLiteratureReference(lit)
}
}
if(!xml.section.isEmpty()) {
xml.section.each {
OutcropSection oc = new OutcropSection()
oc.parseXML(it)
addToSection(oc)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment