class CommitRest {

    @GET
    @Path("{commitId}/history")
    @Produces(MediaType.APPLICATION_JSON)
    @RolesAllowed("user")
    @ApiOperation("Retrieves the Commit history specified by the provided ID.")
    public Response getCommitHistory(@Context UriInfo uriInfo,
                              @PathParam("commitId") String commitId,
                              @QueryParam("targetId") String targetId,
                              @QueryParam("entityId") String entityId,
                              @QueryParam("offset") int offset,
                              @QueryParam("limit") int limit) {
        long start = System.currentTimeMillis();
        try {
            LinksUtils.validateParams(limit, offset);

            try {
                final List<Commit> commits;

                if (StringUtils.isBlank(targetId) && StringUtils.isBlank(entityId)) {
                    commits = catalogManager.getCommitChain(vf.createIRI(commitId));
                } else if (StringUtils.isNotBlank(targetId) && StringUtils.isBlank(entityId)) {
                    commits = catalogManager.getCommitChain(vf.createIRI(commitId), vf.createIRI(targetId));
                } else if (StringUtils.isBlank(targetId) && StringUtils.isNotBlank(entityId)) {
                    commits = catalogManager.getCommitEntityChain(vf.createIRI(commitId), vf.createIRI(entityId));
                } else {
                    commits = catalogManager.getCommitEntityChain(vf.createIRI(commitId), vf.createIRI(targetId),
                            vf.createIRI(entityId));
                }

                Stream<Commit> result = commits.stream();

                if (limit > 0) {
                    result = result.skip(offset)
                            .limit(limit);
                }

                ArrayNode commitChain = mapper.createArrayNode();

                result.map(r -> createCommitJson(r, vf, engineManager))
                        .forEach(commitChain::add);

                return createPaginatedResponseWithJsonNode(uriInfo, commitChain, commits.size(), limit, offset);
            } catch (IllegalArgumentException ex) {
                throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST);
            } catch (IllegalStateException | MobiException ex) {
                throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
            }
        } finally {
            logger.trace("getCommitHistory took {}ms", System.currentTimeMillis() - start);
        }
    }

}