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

          Line data    Source code
       1             : // Copyright (C) 2013 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.gerrit.entities.HumanComment;
      18             : import com.google.gerrit.extensions.registration.DynamicMap;
      19             : import com.google.gerrit.extensions.restapi.ChildCollection;
      20             : import com.google.gerrit.extensions.restapi.IdString;
      21             : import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
      22             : import com.google.gerrit.extensions.restapi.RestView;
      23             : import com.google.gerrit.server.CommentsUtil;
      24             : import com.google.gerrit.server.change.HumanCommentResource;
      25             : import com.google.gerrit.server.change.RevisionResource;
      26             : import com.google.gerrit.server.notedb.ChangeNotes;
      27             : import com.google.inject.Inject;
      28             : import com.google.inject.Singleton;
      29             : 
      30             : @Singleton
      31             : public class Comments implements ChildCollection<RevisionResource, HumanCommentResource> {
      32             :   private final DynamicMap<RestView<HumanCommentResource>> views;
      33             :   private final ListRevisionComments list;
      34             :   private final CommentsUtil commentsUtil;
      35             : 
      36             :   @Inject
      37             :   Comments(
      38             :       DynamicMap<RestView<HumanCommentResource>> views,
      39             :       ListRevisionComments list,
      40         145 :       CommentsUtil commentsUtil) {
      41         145 :     this.views = views;
      42         145 :     this.list = list;
      43         145 :     this.commentsUtil = commentsUtil;
      44         145 :   }
      45             : 
      46             :   @Override
      47             :   public DynamicMap<RestView<HumanCommentResource>> views() {
      48           1 :     return views;
      49             :   }
      50             : 
      51             :   @Override
      52             :   public ListRevisionComments list() {
      53           1 :     return list;
      54             :   }
      55             : 
      56             :   @Override
      57             :   public HumanCommentResource parse(RevisionResource rev, IdString id)
      58             :       throws ResourceNotFoundException {
      59           4 :     String uuid = id.get();
      60           4 :     ChangeNotes notes = rev.getNotes();
      61             : 
      62           4 :     for (HumanComment c : commentsUtil.publishedByPatchSet(notes, rev.getPatchSet().id())) {
      63           4 :       if (uuid.equals(c.key.uuid)) {
      64           4 :         return new HumanCommentResource(rev, c);
      65             :       }
      66           2 :     }
      67           1 :     throw new ResourceNotFoundException(id);
      68             :   }
      69             : }

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