Search in sources :

Example 1 with QueryByStringFilterConverter

use of org.forgerock.openam.rest.query.QueryByStringFilterConverter in project OpenAM by OpenRock.

the class ScriptResource method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler resultHandler) {
    final QueryFilter<JsonPointer> filter = request.getQueryFilter();
    try {
        final Set<ScriptConfiguration> configs;
        if (filter == null) {
            configs = serviceFactory.create(getContextSubject(context), getRealm(context)).getAll();
        } else {
            QueryFilter<String> stringQueryFilter = filter.accept(new QueryByStringFilterConverter(), null);
            configs = serviceFactory.create(getContextSubject(context), getRealm(context)).get(stringQueryFilter);
        }
        List<ResourceResponse> results = new ArrayList<>();
        for (ScriptConfiguration configuration : configs) {
            String id = configuration.getId();
            results.add(newResourceResponse(id, null, asJson(configuration)));
        }
        QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
        return QueryResponsePresentation.perform(resultHandler, request, results);
    } catch (ScriptException se) {
        return exceptionMappingHandler.handleError(context, request, se).asPromise();
    }
}
Also used : ScriptException(org.forgerock.openam.scripting.ScriptException) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryByStringFilterConverter(org.forgerock.openam.rest.query.QueryByStringFilterConverter) ArrayList(java.util.ArrayList) ScriptConfiguration(org.forgerock.openam.scripting.service.ScriptConfiguration) JsonPointer(org.forgerock.json.JsonPointer)

Aggregations

ArrayList (java.util.ArrayList)1 JsonPointer (org.forgerock.json.JsonPointer)1 ResourceResponse (org.forgerock.json.resource.ResourceResponse)1 Responses.newResourceResponse (org.forgerock.json.resource.Responses.newResourceResponse)1 QueryByStringFilterConverter (org.forgerock.openam.rest.query.QueryByStringFilterConverter)1 ScriptException (org.forgerock.openam.scripting.ScriptException)1 ScriptConfiguration (org.forgerock.openam.scripting.service.ScriptConfiguration)1