class ResourceSetResource implements CollectionResourceProvider {

    @Override
    public Promise<QueryResponse, ResourceException> queryCollection(final Context context, final QueryRequest request,
            final QueryResourceHandler handler) {

        final String userId = getUserId(context);
        final ResourceSetWithPolicyQuery query;
        try {
            if (request.getQueryId() != null && request.getQueryId().equals("*")) {
                query = new ResourceSetWithPolicyQuery();
                query.setResourceSetQuery(QueryFilter.<String>alwaysTrue());
            } else if (request.getQueryFilter() != null) {
                query = beforeQueryResourceSets(userId, request)
                        .accept(new ResourceSetQueryFilter(context), new ResourceSetWithPolicyQuery());
            } else {
                return new BadRequestException("Invalid query").asPromise();
            }
        } catch (UnsupportedOperationException e) {
            return new NotSupportedException(e.getMessage()).asPromise();
        }

        boolean augmentWithPolicies = augmentWithPolicies(request);
        String realm = getRealm(context);
        return resourceSetService.getResourceSets(context, realm, query, userId, augmentWithPolicies)
                .thenAsync(new AsyncFunction<Collection<ResourceSetDescription>, QueryResponse, ResourceException>() {
                    @Override
                    public Promise<QueryResponse, ResourceException> apply(Collection<ResourceSetDescription> resourceSets) {
                        try {
                            List<ResourceResponse> resources = new ArrayList<>();
                            for (ResourceSetDescription resourceSet : resourceSets) {
                                resources.add(newResource(resourceSet.getId(),
                                        getResourceSetJson(resourceSet, userId)));
                            }
                            QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
                            return QueryResponsePresentation.perform(handler, request, resources);
                        } catch (ResourceException e) {
                            return e.asPromise();
                        }
                    }
                });
    }

    @Inject public  ResourceSetResource(ResourceSetService resourceSetService, ContextHelper contextHelper,
            UmaLabelsStore umaLabelsStore, ResourceSetDescriptionValidator validator,
            ExtensionFilterManager extensionFilterManager);

}