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

          Line data    Source code
       1             : // Copyright (C) 2012 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.extensions.common.CommentInfo;
      20             : import com.google.gerrit.extensions.restapi.Response;
      21             : import com.google.gerrit.extensions.restapi.RestReadView;
      22             : import com.google.gerrit.server.CommentsUtil;
      23             : import com.google.gerrit.server.change.RevisionResource;
      24             : import com.google.gerrit.server.permissions.PermissionBackendException;
      25             : import com.google.inject.Inject;
      26             : import com.google.inject.Provider;
      27             : import com.google.inject.Singleton;
      28             : import java.util.List;
      29             : import java.util.Map;
      30             : 
      31             : @Singleton
      32             : public class ListRevisionDrafts implements RestReadView<RevisionResource> {
      33             :   protected final Provider<CommentJson> commentJson;
      34             :   protected final CommentsUtil commentsUtil;
      35             : 
      36             :   @Inject
      37         145 :   ListRevisionDrafts(Provider<CommentJson> commentJson, CommentsUtil commentsUtil) {
      38         145 :     this.commentJson = commentJson;
      39         145 :     this.commentsUtil = commentsUtil;
      40         145 :   }
      41             : 
      42             :   protected Iterable<HumanComment> listComments(RevisionResource rsrc) {
      43           4 :     return commentsUtil.draftByPatchSetAuthor(
      44           4 :         rsrc.getPatchSet().id(), rsrc.getAccountId(), rsrc.getNotes());
      45             :   }
      46             : 
      47             :   protected boolean includeAuthorInfo() {
      48           4 :     return false;
      49             :   }
      50             : 
      51             :   @Override
      52             :   public Response<Map<String, List<CommentInfo>>> apply(RevisionResource rsrc)
      53             :       throws PermissionBackendException {
      54           8 :     return Response.ok(
      55             :         commentJson
      56           8 :             .get()
      57           8 :             .setFillAccounts(includeAuthorInfo())
      58           8 :             .newHumanCommentFormatter()
      59           8 :             .format(listComments(rsrc)));
      60             :   }
      61             : 
      62             :   public ImmutableList<CommentInfo> getComments(RevisionResource rsrc)
      63             :       throws PermissionBackendException {
      64           7 :     return commentJson
      65           7 :         .get()
      66           7 :         .setFillAccounts(includeAuthorInfo())
      67           7 :         .newHumanCommentFormatter()
      68           7 :         .formatAsList(listComments(rsrc));
      69             :   }
      70             : }

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