class CatalogRest {

    @GET
    @Path("{catalogId}/records/{recordId}/branches/{branchId}/difference")
    @RolesAllowed("user")
    @ApiOperation("Gets the difference between the two provided Branches' HEAD Commits.")
    @ResourceId(type = ValueType.PATH, value = "recordId")
    public Response getDifference(@PathParam("catalogId") String catalogId,
                           @PathParam("recordId") String recordId,
                           @PathParam("branchId") String branchId,
                           @QueryParam("targetId") String targetBranchId,
                           @DefaultValue("jsonld") @QueryParam("format") String rdfFormat) {
        try {
            checkStringParam(targetBranchId, "Target branch is required");
            Resource catalogIRI = vf.createIRI(catalogId);
            Resource recordIRI = vf.createIRI(recordId);
            Commit sourceHead = catalogManager.getHeadCommit(catalogIRI, recordIRI, vf.createIRI(branchId));
            Commit targetHead = catalogManager.getHeadCommit(catalogIRI, recordIRI, vf.createIRI(targetBranchId));
            Difference diff = catalogManager.getDifference(sourceHead.getResource(), targetHead.getResource());
            return Response.ok(getDifferenceJsonString(diff, rdfFormat, transformer, bNodeService),
                    MediaType.APPLICATION_JSON).build();
        } 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);
        }
    }

}