LCOV - code coverage report
Current view: top level - server/restapi/change - ListChangeMessages.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 13 13 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 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.entities.ChangeMessage;
      18             : import com.google.gerrit.extensions.common.ChangeMessageInfo;
      19             : import com.google.gerrit.extensions.restapi.Response;
      20             : import com.google.gerrit.extensions.restapi.RestReadView;
      21             : import com.google.gerrit.server.ChangeMessagesUtil;
      22             : import com.google.gerrit.server.account.AccountLoader;
      23             : import com.google.gerrit.server.change.ChangeResource;
      24             : import com.google.gerrit.server.permissions.PermissionBackendException;
      25             : import com.google.inject.Inject;
      26             : import com.google.inject.Singleton;
      27             : import java.util.List;
      28             : import java.util.stream.Collectors;
      29             : 
      30             : @Singleton
      31             : public class ListChangeMessages implements RestReadView<ChangeResource> {
      32             :   private final ChangeMessagesUtil changeMessagesUtil;
      33             :   private final AccountLoader.Factory accountLoaderFactory;
      34             : 
      35             :   @Inject
      36             :   public ListChangeMessages(
      37         145 :       ChangeMessagesUtil changeMessagesUtil, AccountLoader.Factory accountLoaderFactory) {
      38         145 :     this.changeMessagesUtil = changeMessagesUtil;
      39         145 :     this.accountLoaderFactory = accountLoaderFactory;
      40         145 :   }
      41             : 
      42             :   @Override
      43             :   public Response<List<ChangeMessageInfo>> apply(ChangeResource resource)
      44             :       throws PermissionBackendException {
      45           7 :     AccountLoader accountLoader = accountLoaderFactory.create(true);
      46           7 :     List<ChangeMessage> messages = changeMessagesUtil.byChange(resource.getNotes());
      47           7 :     List<ChangeMessageInfo> messageInfos =
      48           7 :         messages.stream()
      49           7 :             .map(
      50             :                 m ->
      51           7 :                     changeMessagesUtil.createChangeMessageInfoWithReplacedTemplates(
      52             :                         m, accountLoader))
      53           7 :             .collect(Collectors.toList());
      54           7 :     accountLoader.fill();
      55           7 :     return Response.ok(messageInfos);
      56             :   }
      57             : }

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