Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Read returned OAI errors during Harvest
Browse files Browse the repository at this point in the history
Roll back Harvest if OAI response contains an error that is not
`noRecordsMatch` which is not a true error condition for us.

closes #212
  • Loading branch information
JPrevost committed Jun 4, 2015
1 parent f49cac0 commit b9fa084
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/workers/Harvester.scala
Expand Up @@ -62,17 +62,31 @@ class Harvester {
var objId: Option[String] = None
var readingId = false
var readingSpec = false
var onError = false
var attributes = ""
while (xml.hasNext) {
xml.next match {
case EvElemStart(_,"error",attrs,_) => onError = true; attributes = attrs.toString
case EvElemStart(_,"identifier",_,_) => readingId = true
case EvElemStart(_,"setSpec",_,_) => readingSpec = true
case EvText(text) if onError => onError = false;
handleOaiError(text, attributes); attributes = ""
case EvText(text) if readingId => objId = Some(text); readingId = false
case EvText(text) if readingSpec => processItem(objId, Some(text)); readingSpec = false
case _ =>
}
}
}

def handleOaiError(errorText: String, errorCode: String) = {
if(errorCode.contains("noRecordsMatch")) {
println("DEBUG: No records matched, but don't abort the Harvest because that's just fine.")
} else {
// Any other errorCode aborts which will generate an email to sysadmins with error details
abortHarvest(errorCode + " " + errorText)
}
}

def processItem(objId: Option[String], collectionKey: Option[String]) = {
println("Got OID:" + objId.getOrElse("Unknown") + " in coll: " + collectionKey.getOrElse("Unknown"))
// look up collection, and process if known & item not already created
Expand Down Expand Up @@ -107,6 +121,8 @@ class Harvester {
val url = harvest.serviceUrl + "?verb=ListIdentifiers&metadataPrefix=oai_dc" +
"&from=" + HubUtils.fmtDate(from) +
"&until=" + HubUtils.fmtDate(until)
// To test handling of no records found, you can set url as below.
// val url = "http://repo.scoap3.org/oai2d?verb=ListIdentifiers&metadataPrefix=oai_dc&from=2012-05-04&until=2012-05-04"
// debug
println("About to call: " + url)

Expand Down

0 comments on commit b9fa084

Please sign in to comment.