Skip to content

Commit 650bc1a

Browse files
committed
#418 New task for copying search options around
1 parent bd7f43c commit 650bc1a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.marklogic.gradle.task.client
2+
3+
import com.marklogic.client.DatabaseClient
4+
import com.marklogic.gradle.task.MarkLogicTask
5+
import org.gradle.api.tasks.TaskAction
6+
7+
/**
8+
* Addresses a problem common to DHF options where search options are loaded via the final server and thus only
9+
* available via that server, but a user would like to use them via the staging server too.
10+
*/
11+
class CopySearchOptionsTask extends MarkLogicTask {
12+
13+
DatabaseClient client
14+
String group = "Default"
15+
String sourceServer
16+
String targetServer
17+
String optionsFilename
18+
19+
@TaskAction
20+
void copySearchOptions() {
21+
DatabaseClient databaseClient
22+
if (client != null) {
23+
databaseClient = client
24+
} else {
25+
databaseClient = getAppConfig().newModulesDatabaseClient()
26+
}
27+
28+
def script = "declareUpdate();\nconst uri = '/${group}/${sourceServer}/rest-api/options/${optionsFilename}';\n"
29+
script += "xdmp.documentInsert('/${group}/${targetServer}/rest-api/options/${optionsFilename}', cts.doc(uri), " +
30+
"xdmp.documentGetPermissions(uri), xdmp.documentGetCollections(uri))";
31+
println "Copying search options via:\n" + script
32+
databaseClient.newServerEval().javascript(script).eval()
33+
}
34+
35+
}

0 commit comments

Comments
 (0)