Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for totalPagedResultsPolicy in scripts (#188) #189

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,19 @@

package org.forgerock.openidm.script;

import java.lang.IllegalArgumentException;
import java.lang.NoSuchMethodException;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.forgerock.script.scope.Function;
import org.forgerock.script.scope.FunctionFactory;
import org.forgerock.script.scope.Parameter;
import org.forgerock.services.context.Context;
import org.forgerock.json.JsonValue;
import org.forgerock.json.resource.ActionRequest;
import org.forgerock.json.resource.ActionResponse;
import org.forgerock.json.resource.BadRequestException;
import org.forgerock.json.resource.ConnectionFactory;
import org.forgerock.json.resource.CountPolicy;
import org.forgerock.json.resource.CreateRequest;
import org.forgerock.json.resource.DeleteRequest;
import org.forgerock.json.resource.NotFoundException;
Expand All @@ -58,9 +49,13 @@
import org.forgerock.json.resource.ReadRequest;
import org.forgerock.json.resource.Request;
import org.forgerock.json.resource.Requests;
import org.forgerock.json.resource.ResourceResponse;
import org.forgerock.json.resource.ResourceException;
import org.forgerock.json.resource.ResourceResponse;
import org.forgerock.json.resource.UpdateRequest;
import org.forgerock.script.scope.Function;
import org.forgerock.script.scope.FunctionFactory;
import org.forgerock.script.scope.Parameter;
import org.forgerock.services.context.Context;
import org.forgerock.util.Factory;
import org.forgerock.util.LazyMap;

Expand Down Expand Up @@ -619,6 +614,7 @@ public JsonValue call(Parameter scope, final Function<?> callback, Object... arg
if (null != queryResponse) {
result.put("pagedResultsCookie", queryResponse.getPagedResultsCookie());
result.put("totalPagedResults", queryResponse.getTotalPagedResults());
result.put("totalPagedResultsPolicy", queryResponse.getTotalPagedResultsPolicy().name());
}
if (null != results) {
result.put("result", results);
Expand Down Expand Up @@ -680,6 +676,15 @@ private final QueryResponse query(final Parameter scope, String resourceContaine
qr.setPagedResultsOffset(params.get(name).required().asInteger());
} else if (name.equalsIgnoreCase("_pageSize")) {
qr.setPageSize(params.get(name).required().asInteger());
} else if (name.equalsIgnoreCase("_totalPagedResultsPolicy")) {
final String s = params.get(name).required().asString();
try {
qr.setTotalPagedResultsPolicy(CountPolicy.valueOf(s));
} catch (IllegalArgumentException e) {
// FIXME: i18n.
throw new BadRequestException("The value '" + s + "' for parameter '"
+ name + "' could not be parsed as a valid count policy");
}
} else if (name.equalsIgnoreCase("_queryFilter")) {
final String s = params.get(name).required().asString();
try {
Expand All @@ -688,7 +693,6 @@ private final QueryResponse query(final Parameter scope, String resourceContaine
// FIXME: i18n.
throw new BadRequestException("The value '" + s + "' for parameter '"
+ name + "' could not be parsed as a valid query filter");

}
} else {
setAdditionalParameter(qr, name, params.get(name));
Expand Down
7 changes: 6 additions & 1 deletion openidm-script/src/test/resources/container/resource.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,20 @@ def queryParams1 = [
_queryId: "query-all-ids"
]
def queryParams2 = [
_queryFilter: "nickName eq \"Babs\""
_queryFilter: "nickName eq \"Babs\"",
_pageSize: 42,
_totalPagedResultsPolicy: "EXACT"
]

try {
def userQ1 = router.query("Users", queryParams1)
} catch (NotSupportedException e) {
//expected
}

def userQ2 = router.query("Users", queryParams2)
assert userQ2.totalPagedResultsPolicy == "EXACT"

def userQ3 = router.query("Users", queryParams2, callback)

def printResult = { resource, error ->
Expand Down
9 changes: 8 additions & 1 deletion openidm-script/src/test/resources/container/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,22 @@ var queryParams1 = {
"_queryId": "query-all-ids"
}
var queryParams2 = {
"_queryFilter": "nickName eq \"Babs\""
"_queryFilter": "nickName eq \"Babs\"",
"_pageSize": 42,
"_totalPagedResultsPolicy": "EXACT"
}

try {
var userQ1 = router.query("Users", queryParams1)
} catch (e) {
//expected
}

var userQ2 = router.query("Users", queryParams2)
if (userQ2.totalPagedResultsPolicy != "EXACT") {
throw { "message": "Expected total paged results policy not set" };
}

var userQ3 = router.query("Users", queryParams2, callback)

var printResult = function (resource, error) {
Expand Down
4 changes: 2 additions & 2 deletions openidm-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@

<configuration>
<installDirectory>${project.parent.basedir}</installDirectory>
<nodeVersion>v20.9.0</nodeVersion>
<npmVersion>10.2.3</npmVersion>
<nodeVersion>v20.15.0</nodeVersion>
<npmVersion>10.7.0</npmVersion>
<nodeDownloadRoot>https://nodejs.org/dist/</nodeDownloadRoot>
<npmDownloadRoot>https://wrensecurity.jfrog.io/artifactory/api/npm/npm-virtual/npm/-/</npmDownloadRoot>
</configuration>
Expand Down
Loading