@POST
 public Response post(
     @Auth AuthModelT authModel, ModelT model, @Context HttpServletRequest request)
     throws HttpCodeException {
   ModelT insertedModel = man.insert(getAuthContext(authModel), model);
   if (insertedModel == null) {
     throw new HttpInternalServerErrorException("Could not create " + modelClass.getSimpleName());
   }
   return res().success(res().modelData(insertedModel));
 }
 @Path("/count")
 @GET
 public Response count(@Auth AuthModelT authModel, @Context HttpServletRequest request)
     throws HttpCodeException {
   long count = man.count(getContext(authModel));
   if (count < 0) {
     throw new HttpInternalServerErrorException(
         "Could not retrieve count for " + modelClass.getSimpleName());
   }
   return res().success(res().rawData("count", count));
 }
 @GET
 public Response findModels(
     @Auth AuthModelT authModel,
     @QueryParam("limit") Optional<Integer> limit,
     @QueryParam("offset") Optional<Integer> offset,
     @QueryParam("sort") Optional<String> sort,
     @Context HttpServletRequest request)
     throws HttpCodeException {
   ResultsSet<ModelT> results = man.find(getContext(authModel, limit, offset, sort));
   return res().success(res().listData(results));
 }
 @Path("/bulk")
 @DELETE
 public Response deleteBulk(
     @Auth AuthModelT authModel, List<PrimaryKeyT> ids, @Context HttpServletRequest request)
     throws HttpCodeException {
   // TODO: implement transaction
   Map<Serializable, Boolean> resultMap = Maps.newHashMap();
   for (PrimaryKeyT id : ids) {
     resultMap.put(id, man.delete(getAuthContext(authModel), id));
   }
   return res().success(res().boolMap("deletedIds", resultMap));
 }
 @Path("/bulk")
 @PUT
 public Response updateBulk(
     @Auth AuthModelT authModel, List<ModelT> models, @Context HttpServletRequest request)
     throws HttpCodeException {
   // TODO: implement transaction
   List<ModelT> updatedModels = Lists.newArrayList();
   for (ModelT model : models) {
     updatedModels.add(man.update(getAuthContext(authModel), model));
   }
   return res().success(res().modelData(updatedModels));
 }
 @Path("/{id}")
 @DELETE
 public Response delete(
     @Auth AuthModelT authModel,
     @PathParam("id") PrimaryKeyT id,
     @Context HttpServletRequest request)
     throws HttpCodeException {
   if (!man.delete(getAuthContext(authModel), id)) {
     throw new HttpInternalServerErrorException(
         "Failed to delete " + modelClass.getSimpleName() + " with id " + id);
   }
   return res().success(null);
 }
 @Path("/{id}")
 @GET
 public Response findModel(
     @Auth AuthModelT authModel,
     @PathParam("id") PrimaryKeyT id,
     @Context HttpServletRequest request)
     throws HttpCodeException {
   ModelT model = man.find(getAuthContext(authModel), id);
   if (model == null) {
     throw new HttpNotFoundException(
         "Could not find " + modelClass.getSimpleName() + " with id " + id);
   }
   return res().success(res().modelData(model));
 }
 @Path("/{id}")
 @PUT
 public Response update(
     @Auth AuthModelT authModel,
     @PathParam("id") PrimaryKeyT id,
     ModelT model,
     @Context HttpServletRequest request)
     throws HttpCodeException {
   if (!id.equals(model.getId())) {
     throw new HttpInternalServerErrorException("Invalid Request: ID's do not match");
   }
   ModelT updatedModel = man.update(getAuthContext(authModel), model);
   if (updatedModel == null) {
     throw new HttpInternalServerErrorException(
         "Could not update the " + modelClass.getSimpleName());
   }
   return res().success(res().modelData(updatedModel));
 }
 @Path("/bulk")
 @POST
 public Response postBulk(
     @Auth AuthModelT authModel, List<ModelT> models, @Context HttpServletRequest request)
     throws HttpCodeException {
   // TODO: Implement transaction
   List<ModelT> insertedModels = Lists.newArrayList();
   for (ModelT model : models) {
     insertedModels.add(man.insert(getAuthContext(authModel), model));
   }
   return res()
       .success(
           res()
               .listData(
                   ResultsSet.<ModelT>builder()
                       .results(insertedModels)
                       .limit(insertedModels.size())
                       .offset(0)
                       .total((long) insertedModels.size())
                       .build()));
 }