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

          Line data    Source code
       1             : // Copyright (C) 2017 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.FixSuggestion;
      18             : import com.google.gerrit.entities.RobotComment;
      19             : import com.google.gerrit.extensions.registration.DynamicMap;
      20             : import com.google.gerrit.extensions.restapi.ChildCollection;
      21             : import com.google.gerrit.extensions.restapi.IdString;
      22             : import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
      23             : import com.google.gerrit.extensions.restapi.RestView;
      24             : import com.google.gerrit.server.CommentsUtil;
      25             : import com.google.gerrit.server.change.FixResource;
      26             : import com.google.gerrit.server.change.RevisionResource;
      27             : import com.google.gerrit.server.notedb.ChangeNotes;
      28             : import com.google.inject.Inject;
      29             : import com.google.inject.Singleton;
      30             : import java.util.List;
      31             : import java.util.Objects;
      32             : 
      33             : @Singleton
      34             : public class Fixes implements ChildCollection<RevisionResource, FixResource> {
      35             : 
      36             :   private final DynamicMap<RestView<FixResource>> views;
      37             :   private final CommentsUtil commentsUtil;
      38             : 
      39             :   @Inject
      40         145 :   Fixes(DynamicMap<RestView<FixResource>> views, CommentsUtil commentsUtil) {
      41         145 :     this.views = views;
      42         145 :     this.commentsUtil = commentsUtil;
      43         145 :   }
      44             : 
      45             :   @Override
      46             :   public RestView<RevisionResource> list() throws ResourceNotFoundException {
      47           1 :     throw new ResourceNotFoundException();
      48             :   }
      49             : 
      50             :   @Override
      51             :   public FixResource parse(RevisionResource revisionResource, IdString id)
      52             :       throws ResourceNotFoundException {
      53           2 :     String fixId = id.get();
      54           2 :     ChangeNotes changeNotes = revisionResource.getNotes();
      55             : 
      56           2 :     List<RobotComment> robotComments =
      57           2 :         commentsUtil.robotCommentsByPatchSet(changeNotes, revisionResource.getPatchSet().id());
      58           2 :     for (RobotComment robotComment : robotComments) {
      59           2 :       for (FixSuggestion fixSuggestion : robotComment.fixSuggestions) {
      60           2 :         if (Objects.equals(fixId, fixSuggestion.fixId)) {
      61           2 :           return new FixResource(revisionResource, fixSuggestion.replacements);
      62             :         }
      63           1 :       }
      64           1 :     }
      65           1 :     throw new ResourceNotFoundException(id);
      66             :   }
      67             : 
      68             :   @Override
      69             :   public DynamicMap<RestView<FixResource>> views() {
      70           1 :     return views;
      71             :   }
      72             : }

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