class ExplorableDatasetRest {

    @GET
    @Path("{recordIRI}/classes/{classIRI}/instance-details")
    @Produces(MediaType.APPLICATION_JSON)
    @RolesAllowed("user")
    @ApiOperation("Retrieves an aggregated summary of all ontology objects from a Dataset in the local Catalog")
    public Response getInstanceDetails(@Context UriInfo uriInfo,
                                @PathParam("recordIRI") String recordIRI,
                                @PathParam("classIRI") String classIRI,
                                @QueryParam("offset") int offset,
                                @QueryParam("limit") int limit,
                                @DefaultValue("true") @QueryParam("ascending") boolean asc,
                                @DefaultValue("false") @QueryParam("infer") boolean infer) {
        checkStringParam(recordIRI, "The Dataset Record IRI is required.");
        checkStringParam(classIRI, "The Class IRI is required.");
        Resource datasetRecordRsr = factory.createIRI(recordIRI);
        try {
            final List<InstanceDetails> instances = new ArrayList<>();
            if (infer) {
                String classes = getInferredClasses(datasetRecordRsr, factory.createIRI(classIRI));
                String query = String.format(GET_ALL_CLASS_INSTANCES, classes);
                TupleQueryResult results = getQueryResults(datasetRecordRsr, query, "", null);
                instances.addAll(getInstanceDetailsFromQueryResults(results));
            } else {
                TupleQueryResult results = getQueryResults(datasetRecordRsr, GET_CLASSES_INSTANCES, CLASS_BINDING,
                        factory.createIRI(classIRI));
                instances.addAll(getInstanceDetailsFromQueryResults(results));
            }
            Comparator<InstanceDetails> comparator = Comparator.comparing(InstanceDetails::getTitle);
            return createPagedResponse(uriInfo, instances, comparator, asc, limit, offset);
        } catch (MobiException e) {
            throw ErrorUtils.sendError(e, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
        }
    }

}