-
Notifications
You must be signed in to change notification settings - Fork 221
/
import-sample-data-into-demo.sc
40 lines (32 loc) · 1.31 KB
/
import-sample-data-into-demo.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Run with: `amm import-sample-data-into-demo.sc username password`
// https://ammonite.io/#AmmoniteArgumentsinScripts
@main
def main(username: String, password: String): Unit = {
val root = os.pwd / os.RelPath("data/orbeon/fr")
val crudEndPoint = "https://demo.orbeon.com/demo/fr/service/persistence/crud/"
os.walk(root) filter
os.isFile filterNot
(_.ext == "DS_Store") filterNot
(_.baseName.contains("copy")) filterNot
(_.ext.endsWith("~")) foreach { p =>
println(s"processing file: ${p.relativeTo(root)}")
val mediatype = p.ext match {
case "jpg" => "image/jpeg"
case "xml" | "xhtml" => "application/xml"
case _ => "application/octet-stream"
}
// Version 2 temporarily as on demo we have this and have a /new bug
val formVersion = if (p.toString.contains("orbeon/controls")) 2 else 1
val r =
requests.put(
crudEndPoint + p.relativeTo(root),
auth = new requests.RequestAuth.Basic(username, password),
data = new java.io.File(p.toString),
headers = Map(
"Content-Type" -> mediatype,
"Orbeon-Form-Definition-Version" -> formVersion.toString
)
)
println(s"${r.statusCode}")
}
}