示例#1
0
 @Override
 public Object apply(FileResource resource, Input input) throws OrmException {
   ReviewDb db = dbProvider.get();
   AccountPatchReview apr = getExisting(db, resource);
   if (apr == null) {
     db.accountPatchReviews()
         .insert(
             Collections.singleton(
                 new AccountPatchReview(resource.getPatchKey(), resource.getAccountId())));
     return Response.created("");
   } else {
     return Response.ok("");
   }
 }
  @Override
  public Response<CommentInfo> apply(RevisionResource rsrc, DraftInput in)
      throws RestApiException, UpdateException, OrmException {
    if (Strings.isNullOrEmpty(in.path)) {
      throw new BadRequestException("path must be non-empty");
    } else if (in.message == null || in.message.trim().isEmpty()) {
      throw new BadRequestException("message must be non-empty");
    } else if (in.line != null && in.line < 0) {
      throw new BadRequestException("line must be >= 0");
    } else if (in.line != null && in.range != null && in.line != in.range.endLine) {
      throw new BadRequestException("range endLine must be on the same line as the comment");
    }

    try (BatchUpdate bu =
        updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
      Op op = new Op(rsrc.getPatchSet().getId(), in);
      bu.addOp(rsrc.getChange().getId(), op);
      bu.execute();
      return Response.created(
          commentJson.get().setFillAccounts(false).newCommentFormatter().format(op.comment));
    }
  }