Skip to content

Instantly share code, notes, and snippets.

@mikesname
Last active December 11, 2015 11:29
Show Gist options
  • Save mikesname/4594442 to your computer and use it in GitHub Desktop.
Save mikesname/4594442 to your computer and use it in GitHub Desktop.
Attempt to bodge together a Play 2.0 CLI management command... the file was bunged in the test package in order to have the running() and FakeApplication() utils available. It was executed with something like: play "run-main test.XMLtoGeoff"
package test
import play.api.test.Helpers.running
import play.api.test.FakeApplication
import models.Repository
import scala.io.Source
import controllers.Collections.processSource
import importers.USHMM
object XMLtoGeoff {
def getGeoff(repo: Repository, xmlfile: String) = {
processSource(Source.fromFile(xmlfile)) { doc =>
USHMM.docToGeoff("repo%d".format(repo.id), doc).map { geoffline =>
println(geoffline)
}
}
}
def main(args: Array[String]) = {
args match {
case Array(reposlug, xmlfile, _*) => {
running(FakeApplication()) {
Repository.fetchByFieldOption("slug", reposlug).map { maybeRepo =>
println("Running: " + maybeRepo)
maybeRepo match {
case Some(repo) => getGeoff(repo, xmlfile)
case None => sys.error("Repository not found: " + reposlug)
}
}
}
}
case _ => sys.error("Usage: <repo-slug> <xmlfile>")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment