LCOV - code coverage report
Current view: top level - server/restapi/change - ChangeMessages.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) 2018 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.extensions.common.ChangeMessageInfo;
      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.change.ChangeMessageResource;
      24             : import com.google.gerrit.server.change.ChangeResource;
      25             : import com.google.inject.Inject;
      26             : import com.google.inject.Singleton;
      27             : import java.util.List;
      28             : 
      29             : @Singleton
      30             : public class ChangeMessages implements ChildCollection<ChangeResource, ChangeMessageResource> {
      31             :   private final DynamicMap<RestView<ChangeMessageResource>> views;
      32             :   private final ListChangeMessages listChangeMessages;
      33             : 
      34             :   @Inject
      35             :   ChangeMessages(
      36         145 :       DynamicMap<RestView<ChangeMessageResource>> views, ListChangeMessages listChangeMessages) {
      37         145 :     this.views = views;
      38         145 :     this.listChangeMessages = listChangeMessages;
      39         145 :   }
      40             : 
      41             :   @Override
      42             :   public DynamicMap<RestView<ChangeMessageResource>> views() {
      43           1 :     return views;
      44             :   }
      45             : 
      46             :   @Override
      47             :   public ListChangeMessages list() {
      48           7 :     return listChangeMessages;
      49             :   }
      50             : 
      51             :   @Override
      52             :   public ChangeMessageResource parse(ChangeResource parent, IdString id) throws Exception {
      53           3 :     String uuid = id.get();
      54             : 
      55           3 :     List<ChangeMessageInfo> changeMessages = listChangeMessages.apply(parent).value();
      56           3 :     int index = -1;
      57           3 :     for (int i = 0; i < changeMessages.size(); ++i) {
      58           3 :       ChangeMessageInfo changeMessage = changeMessages.get(i);
      59           3 :       if (changeMessage.id.equals(uuid)) {
      60           3 :         index = i;
      61           3 :         break;
      62             :       }
      63             :     }
      64             : 
      65           3 :     if (index < 0) {
      66           1 :       throw new ResourceNotFoundException(String.format("change message %s not found", uuid));
      67             :     }
      68             : 
      69           3 :     return new ChangeMessageResource(parent, changeMessages.get(index), index);
      70             :   }
      71             : }

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