Search in sources :

Example 1 with LocaleContext

use of com.sun.identity.common.LocaleContext in project OpenAM by OpenRock.

the class UmaLabelResource method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context serverContext, QueryRequest queryRequest, QueryResourceHandler queryResultHandler) {
    if (!queryRequest.getQueryFilter().toString().equals("true")) {
        return new BadRequestException("Invalid query").asPromise();
    }
    Set<ResourceSetLabel> labels;
    try {
        labels = labelStore.list(getRealm(serverContext), getUserName(serverContext));
    } catch (ResourceException e) {
        return new BadRequestException("Error retrieving labels.").asPromise();
    }
    LocaleContext localeContext = localeContextProvider.get();
    localeContext.setLocale(serverContext);
    for (ResourceSetLabel label : labels) {
        try {
            label = resolveLabelName(contextHelper.getRealm(serverContext), label, localeContext, serverContext);
        } catch (InternalServerErrorException e) {
            debug.error("Could not resolve Resource Server label name. id: {}, name: {}", label.getId(), label.getName(), e);
        }
        queryResultHandler.handleResource(newResourceResponse(label.getId(), String.valueOf(label.asJson().getObject().hashCode()), label.asJson()));
    }
    return newResultPromise(newQueryResponse());
}
Also used : LocaleContext(com.sun.identity.common.LocaleContext) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) ResourceSetLabel(org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)

Aggregations

LocaleContext (com.sun.identity.common.LocaleContext)1 BadRequestException (org.forgerock.json.resource.BadRequestException)1 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)1 ResourceException (org.forgerock.json.resource.ResourceException)1 ResourceSetLabel (org.forgerock.openam.oauth2.resources.labels.ResourceSetLabel)1