private void insertComments()

in src/main/java/com/googlesource/gerrit/plugins/importer/ReplayInlineCommentsStep.java [176:222]


  private void insertComments(PatchSet ps, Account.Id author, Collection<CommentInfo> comments)
      throws OrmException, IOException, NoSuchChangeException, PatchListNotAvailableException {
    ChangeNotes notes = changeNotesFactory.createChecked(db, change);

    Map<String, Comment> drafts = scanDraftComments(notes, ps, author);

    List<Comment> del = Lists.newArrayList();
    List<Comment> ups = Lists.newArrayList();

    for (CommentInfo c : comments) {
      String parent = Url.decode(c.inReplyTo);
      Comment e = drafts.remove(Url.decode(c.id));

      if (e == null) {
        e =
            new Comment(
                new Comment.Key(Url.decode(c.id), c.path, ps.getId().get()),
                author,
                c.updated,
                c.side == Side.PARENT ? (short) 0 : (short) 1,
                c.message,
                serverId,
                c.unresolved == null ? false : c.unresolved);
      } else if (parent != null) {
        e.parentUuid = parent;
      }
      setCommentRevId(e, patchListCache, change, ps);
      if (c.range != null) {
        e.setRange(
            new CommentRange(
                c.range.startLine, c.range.startCharacter, c.range.endLine, c.range.endCharacter));
        e.lineNbr = c.range.endLine;
      } else {
        e.lineNbr = c.line == null ? 0 : c.line;
      }
      ups.add(e);
    }

    Iterables.addAll(del, drafts.values());
    ChangeUpdate update =
        updateFactory.create(notes, genericUserFactory.create(author), TimeUtil.nowTs());
    update.setPatchSetId(ps.getId());

    commentsUtil.deleteComments(db, update, del);
    commentsUtil.putComments(db, update, Status.PUBLISHED, ups);
    update.commit();
  }