Skip to content

Commit 2af65ae

Browse files
committed
Added whereUrisQuery to DMSDK tasks
1 parent a734a61 commit 2af65ae

File tree

9 files changed

+59
-32
lines changed

9 files changed

+59
-32
lines changed

examples/local-testing-project/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Set this to the version you used when running
22
# "gradle -Pversion=(something) publishToMavenLocal" on your local ml-gradle repo
3-
mlGradleVersion=3.0-beta1
3+
mlGradleVersion=3.0-beta2
44

55
mlHost=localhost
66
mlAppName=example

src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,24 @@ class MarkLogicPlugin implements Plugin<Project> {
132132
String dmGroupMessage = "; can also set the properties threadCount, batchSize, applyConsistentSnapshot, " +
133133
"jobName, and logBatches to configure how the Data Movement QueryBatcher operates.";
134134
project.task("mlAddCollections", type: AddCollectionsTask, group: dmGroup, description: "Add all documents, either in a comma-separated list of " +
135-
"collection names specified by the 'whereCollections' property or matching a URI pattern specified by the 'whereUriPattern' property, " +
135+
"collection names specified by the 'whereCollections' property or matching a URI pattern specified by the 'whereUriPattern' property or matching a URIs query specified by the 'whereUrisQuery' property, " +
136136
"to a comma-separated list of collection names specified by the 'collections' property" + dmGroupMessage)
137137
project.task("mlDeleteCollections", type: DeleteCollectionsTask, group: dmGroup, description: "Delete all documents in a comma-separated list of " +
138138
"collection names specified by the 'collections' property" + dmGroupMessage)
139139
project.task("mlRemoveCollections", type: RemoveCollectionsTask, group: dmGroup, description: "Remove all documents, either in a comma-separated list of " +
140-
"collection names specified by the 'whereCollections' property or matching a URI pattern specified by the 'whereUriPattern' property, " +
140+
"collection names specified by the 'whereCollections' property or matching a URI pattern specified by the 'whereUriPattern' property or matching a URIs query specified by the 'whereUrisQuery' property, " +
141141
"from a comma-separated list of collection names specified by the 'collections' property; " +
142142
"if the values of 'whereCollections' and 'collections' are the same, you only need to specify the 'collections' property" + dmGroupMessage)
143143
project.task("mlSetCollections", type: SetCollectionsTask, group: dmGroup, description: "Set collections on all documents, either in a comma-separated list of " +
144-
"collection names specified by the 'whereCollections' property or matching a URI pattern specified by the 'whereUriPattern' property, " +
144+
"collection names specified by the 'whereCollections' property or matching a URI pattern specified by the 'whereUriPattern' property or matching a URIs query specified by the 'whereUrisQuery' property, " +
145145
"to a comma-separated list of collection names specified by the 'collections' property" + dmGroupMessage)
146146

147147
project.task("mlAddPermissions", type: AddPermissionsTask, group: dmGroup, description: "Add permissions, specified as a comma-separated list of roles and capabilities via the 'permissions' property, " +
148-
"to all documents either in the set of collection names specified by the 'collections' property or with URIs matching the pattern specified by the 'whereUriPattern' property" + dmGroupMessage)
148+
"to all documents either in the set of collection names specified by the 'collections' property or with URIs matching the pattern specified by the 'whereUriPattern' property or matching a URIs query specified by the 'whereUrisQuery' property" + dmGroupMessage)
149149
project.task("mlRemovePermissions", type: RemovePermissionsTask, group: dmGroup, description: "Remove permissions, specified as a comma-separated list of roles and capabilities via the 'permissions' property, " +
150-
"from all documents either in the set of collection names specified by the 'collections' property or with URIs matching the pattern specified by the 'whereUriPattern' property" + dmGroupMessage)
150+
"from all documents either in the set of collection names specified by the 'collections' property or with URIs matching the pattern specified by the 'whereUriPattern' property or matching a URIs query specified by the 'whereUrisQuery' property" + dmGroupMessage)
151151
project.task("mlSetPermissions", type: SetPermissionsTask, group: dmGroup, description: "Set permissions, specified as a comma-separated list of roles and capabilities via the 'permissions' property, " +
152-
"on all documents in the set of collection names specified by the 'collections' property or with URIs matching the pattern specified by the 'whereUriPattern' property" + dmGroupMessage)
152+
"on all documents in the set of collection names specified by the 'collections' property or with URIs matching the pattern specified by the 'whereUriPattern' property or matching a URIs query specified by the 'whereUrisQuery' property" + dmGroupMessage)
153153

154154
String devGroup = "ml-gradle Development"
155155
project.task("mlCreateResource", type: CreateResourceTask, group: devGroup, description: "Create a new resource extension in the modules services directory; use -PresourceName and -PresourceType to set the resource name and type (either xqy or sjs)")

src/main/groovy/com/marklogic/gradle/task/datamovement/AddCollectionsTask.groovy

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ class AddCollectionsTask extends DataMovementTask {
99

1010
@TaskAction
1111
void addCollections() {
12-
if (
13-
(!project.hasProperty("whereCollections") && !project.hasProperty("whereUriPattern")) ||
14-
!project.hasProperty("collections")
15-
) {
12+
if (!hasWhereSelectorProperty() || !project.hasProperty("collections")) {
1613
println "Invalid inputs; task description: " + getDescription()
1714
return;
1815
}
@@ -25,14 +22,17 @@ class AddCollectionsTask extends DataMovementTask {
2522

2623
if (hasWhereCollectionsProperty()) {
2724
builder = constructBuilderFromWhereCollections()
28-
message = "documents in collections " + Arrays.asList(this.whereCollections) + message
25+
message = "in collections " + Arrays.asList(this.whereCollections) + message
2926
} else if (hasWhereUriPatternProperty()) {
3027
builder = constructBuilderFromWhereUriPattern()
31-
message = "documents matching URI pattern " + this.whereUriPattern + message
28+
message = "matching URI pattern " + this.whereUriPattern + message
29+
} else if (hasWhereUrisQueryProperty()) {
30+
builder = constructBuilderFromWhereUrisQuery()
31+
message = "matching URIs query " + this.whereUrisQuery + message
3232
}
3333

34-
println "Adding " + message
34+
println "Adding documents " + message
3535
applyWithQueryBatcherBuilder(listener, builder)
36-
println "Finished adding " + message
36+
println "Finished adding documents " + message
3737
}
3838
}

src/main/groovy/com/marklogic/gradle/task/datamovement/AddPermissionsTask.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AddPermissionsTask extends DataMovementTask {
99

1010
@TaskAction
1111
void addPermissions() {
12-
if ((!project.hasProperty("whereCollections") && !project.hasProperty("whereUriPattern")) || !project.hasProperty("permissions")) {
12+
if (!hasWhereSelectorProperty() || !project.hasProperty("permissions")) {
1313
println "Invalid input; task description: " + getDescription()
1414
return;
1515
}
@@ -26,6 +26,9 @@ class AddPermissionsTask extends DataMovementTask {
2626
} else if (hasWhereUriPatternProperty()) {
2727
builder = constructBuilderFromWhereUriPattern()
2828
message += "matching URI pattern " + this.whereUriPattern
29+
} else if (hasWhereUrisQueryProperty()) {
30+
builder = constructBuilderFromWhereUrisQuery()
31+
message += "matching URIs query " + this.whereUrisQuery
2932
}
3033

3134
println "Adding " + message

src/main/groovy/com/marklogic/gradle/task/datamovement/DataMovementTask.groovy

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import com.marklogic.client.ext.datamovement.CollectionsQueryBatcherBuilder
77
import com.marklogic.client.ext.datamovement.QueryBatcherBuilder
88
import com.marklogic.client.ext.datamovement.QueryBatcherTemplate
99
import com.marklogic.client.ext.datamovement.UriPatternQueryBatcherBuilder
10+
import com.marklogic.client.ext.datamovement.UrisQueryQueryBatcherBuilder
1011
import com.marklogic.gradle.task.MarkLogicTask
1112

1213
class DataMovementTask extends MarkLogicTask {
1314

1415
String whereUriPattern
1516
String[] whereCollections
17+
String whereUrisQuery
1618

1719
boolean hasWhereCollectionsProperty() {
1820
return project.hasProperty("whereCollections")
@@ -22,6 +24,14 @@ class DataMovementTask extends MarkLogicTask {
2224
return project.hasProperty("whereUriPattern")
2325
}
2426

27+
boolean hasWhereUrisQueryProperty() {
28+
return project.hasProperty("whereUrisQuery")
29+
}
30+
31+
boolean hasWhereSelectorProperty() {
32+
return hasWhereCollectionsProperty() || hasWhereUriPatternProperty() || hasWhereUrisQueryProperty()
33+
}
34+
2535
QueryBatcherBuilder constructBuilderFromWhereCollections() {
2636
this.whereCollections = getProject().property("whereCollections").split(",")
2737
return new CollectionsQueryBatcherBuilder(this.whereCollections)
@@ -32,6 +42,10 @@ class DataMovementTask extends MarkLogicTask {
3242
return new UriPatternQueryBatcherBuilder(this.whereUriPattern)
3343
}
3444

45+
QueryBatcherBuilder constructBuilderFromWhereUrisQuery() {
46+
this.whereUrisQuery = getProject().property("whereUrisQuery")
47+
return new UrisQueryQueryBatcherBuilder(this.whereUrisQuery)
48+
}
3549
void applyOnCollections(QueryBatchListener listener, String... collections) {
3650
DatabaseClient client = newClient()
3751
try {
@@ -66,7 +80,7 @@ class DataMovementTask extends MarkLogicTask {
6680
* - applyConsistentSnapshot
6781
* - jobName
6882
* - logBatches
69-
*
83+
*
7084
* Can override this method in a subclass to further configure the QueryBatcherTemplate that's returned.
7185
*
7286
* @param client

src/main/groovy/com/marklogic/gradle/task/datamovement/RemoveCollectionsTask.groovy

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ class RemoveCollectionsTask extends DataMovementTask {
2727

2828
if (hasWhereUriPatternProperty()) {
2929
builder = constructBuilderFromWhereUriPattern()
30-
message = "documents matching URI pattern " + this.whereUriPattern + message
30+
message = "matching URI pattern " + this.whereUriPattern + message
31+
}
32+
else if (hasWhereUrisQueryProperty()) {
33+
builder = constructBuilderFromWhereUrisQuery()
34+
message = "matching URIs query " + this.whereUrisQuery + message
3135
}
3236
else {
3337
if (hasWhereCollectionsProperty()) {
@@ -36,11 +40,11 @@ class RemoveCollectionsTask extends DataMovementTask {
3640
this.whereCollections = collections
3741
builder = new CollectionsQueryBatcherBuilder(this.whereCollections)
3842
}
39-
message = "documents in collections " + Arrays.asList(this.whereCollections) + message
43+
message = "in collections " + Arrays.asList(this.whereCollections) + message
4044
}
4145

42-
println "Removing " + message
46+
println "Removing documents " + message
4347
applyWithQueryBatcherBuilder(listener, builder)
44-
println "Finished removing " + message
48+
println "Finished removing documents " + message
4549
}
4650
}

src/main/groovy/com/marklogic/gradle/task/datamovement/RemovePermissionsTask.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class RemovePermissionsTask extends DataMovementTask {
1111

1212
@TaskAction
1313
void removePermissions() {
14-
if ((!project.hasProperty("whereCollections") && !project.hasProperty("whereUriPattern")) || !project.hasProperty("permissions")) {
14+
if (!hasWhereSelectorProperty() || !project.hasProperty("permissions")) {
1515
println "Invalid input; task description: " + getDescription()
1616
return;
1717
}
@@ -28,6 +28,9 @@ class RemovePermissionsTask extends DataMovementTask {
2828
} else if (hasWhereUriPatternProperty()) {
2929
builder = constructBuilderFromWhereUriPattern()
3030
message += "matching URI pattern " + this.whereUriPattern
31+
} else if (hasWhereUrisQueryProperty()) {
32+
builder = constructBuilderFromWhereUrisQuery()
33+
message += "matching URIs query " + this.whereUrisQuery
3134
}
3235

3336
println "Removing " + message

src/main/groovy/com/marklogic/gradle/task/datamovement/SetCollectionsTask.groovy

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ class SetCollectionsTask extends DataMovementTask {
99

1010
@TaskAction
1111
void setCollections() {
12-
if (
13-
(!project.hasProperty("whereCollections") && !project.hasProperty("pattern")) ||
14-
!project.hasProperty("collections")
15-
) {
12+
if (!hasWhereSelectorProperty() || !project.hasProperty("collections")) {
1613
println "Invalid inputs; task description: " + getDescription()
1714
return;
1815
}
@@ -21,18 +18,21 @@ class SetCollectionsTask extends DataMovementTask {
2118
QueryBatchListener listener = new SetCollectionsListener(collections)
2219
QueryBatcherBuilder builder = null
2320

24-
String message = " collections " + Arrays.asList(collections);
21+
String message = " collections " + Arrays.asList(collections) + " on documents ";
2522

2623
if (hasWhereCollectionsProperty()) {
2724
builder = constructBuilderFromWhereCollections()
28-
message += " on documents in collections " + Arrays.asList(this.whereCollections)
25+
message += "in collections " + Arrays.asList(this.whereCollections)
2926
} else if (hasWhereUriPatternProperty()) {
3027
builder = constructBuilderFromWhereUriPattern()
31-
message += " on documents matching URI pattern " + this.whereUriPattern
28+
message += "matching URI pattern " + this.whereUriPattern
29+
} else if (hasWhereUrisQueryProperty()) {
30+
builder = constructBuilderFromWhereUrisQuery()
31+
message += "matching URIs query " + this.whereUrisQuery
3232
}
3333

34-
println "Setting " + message
34+
println "Setting" + message
3535
applyWithQueryBatcherBuilder(listener, builder)
36-
println "Finished setting " + message
36+
println "Finished setting" + message
3737
}
3838
}

src/main/groovy/com/marklogic/gradle/task/datamovement/SetPermissionsTask.groovy

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class SetPermissionsTask extends DataMovementTask {
1111

1212
@TaskAction
1313
void setPermissions() {
14-
if ((!project.hasProperty("whereCollections") && !project.hasProperty("whereUriPattern")) || !project.hasProperty("permissions")) {
14+
if (!hasWhereSelectorProperty() || !project.hasProperty("permissions")) {
1515
println "Invalid input; task description: " + getDescription()
1616
return;
1717
}
@@ -28,6 +28,9 @@ class SetPermissionsTask extends DataMovementTask {
2828
} else if (hasWhereUriPatternProperty()) {
2929
builder = constructBuilderFromWhereUriPattern()
3030
message += "matching URI pattern " + this.whereUriPattern
31+
} else if (hasWhereUrisQueryProperty()) {
32+
builder = constructBuilderFromWhereUrisQuery()
33+
message += "matching URIs query " + this.whereUrisQuery
3134
}
3235

3336
println "Setting " + message

0 commit comments

Comments
 (0)