LCOV - code coverage report
Current view: top level - server/restapi/change - ListPortedComments.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 19 19 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2020 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.restapi.change;
      16             : 
      17             : import com.google.common.collect.ImmutableList;
      18             : import com.google.gerrit.entities.HumanComment;
      19             : import com.google.gerrit.entities.PatchSet;
      20             : import com.google.gerrit.extensions.common.CommentInfo;
      21             : import com.google.gerrit.extensions.restapi.Response;
      22             : import com.google.gerrit.extensions.restapi.RestReadView;
      23             : import com.google.gerrit.server.CommentsUtil;
      24             : import com.google.gerrit.server.change.RevisionResource;
      25             : import com.google.gerrit.server.permissions.PermissionBackendException;
      26             : import com.google.inject.Inject;
      27             : import com.google.inject.Provider;
      28             : import com.google.inject.Singleton;
      29             : import java.util.List;
      30             : import java.util.Map;
      31             : 
      32             : @Singleton
      33             : public class ListPortedComments implements RestReadView<RevisionResource> {
      34             : 
      35             :   private final CommentsUtil commentsUtil;
      36             :   private final CommentPorter commentPorter;
      37             :   private final Provider<CommentJson> commentJson;
      38             : 
      39             :   @Inject
      40             :   public ListPortedComments(
      41         145 :       Provider<CommentJson> commentJson, CommentsUtil commentsUtil, CommentPorter commentPorter) {
      42         145 :     this.commentJson = commentJson;
      43         145 :     this.commentsUtil = commentsUtil;
      44         145 :     this.commentPorter = commentPorter;
      45         145 :   }
      46             : 
      47             :   @Override
      48             :   public Response<Map<String, List<CommentInfo>>> apply(RevisionResource revisionResource)
      49             :       throws PermissionBackendException {
      50           2 :     PatchSet targetPatchset = revisionResource.getPatchSet();
      51             : 
      52           2 :     List<HumanComment> allComments =
      53           2 :         commentsUtil.publishedHumanCommentsByChange(revisionResource.getNotes());
      54           2 :     ImmutableList<HumanComment> portedComments =
      55           2 :         commentPorter.portComments(
      56           2 :             revisionResource.getNotes(),
      57             :             targetPatchset,
      58             :             allComments,
      59           2 :             ImmutableList.of(new UnresolvedCommentFilter()));
      60           2 :     return Response.ok(format(portedComments));
      61             :   }
      62             : 
      63             :   private Map<String, List<CommentInfo>> format(List<HumanComment> comments)
      64             :       throws PermissionBackendException {
      65           2 :     return commentJson
      66           2 :         .get()
      67           2 :         .setFillAccounts(true)
      68           2 :         .setFillPatchSet(true)
      69           2 :         .newHumanCommentFormatter()
      70           2 :         .format(comments);
      71             :   }
      72             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750