LCOV - code coverage report
Current view: top level - server/change - ReviewerResource.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 29 35 82.9 %
Date: 2022-11-19 15:00:39 Functions: 12 13 92.3 %

          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.change;
      16             : 
      17             : import static com.google.common.base.Preconditions.checkArgument;
      18             : 
      19             : import com.google.gerrit.common.Nullable;
      20             : import com.google.gerrit.entities.Account;
      21             : import com.google.gerrit.entities.Address;
      22             : import com.google.gerrit.entities.Change;
      23             : import com.google.gerrit.extensions.restapi.RestResource;
      24             : import com.google.gerrit.extensions.restapi.RestView;
      25             : import com.google.gerrit.server.IdentifiedUser;
      26             : import com.google.inject.TypeLiteral;
      27             : import com.google.inject.assistedinject.Assisted;
      28             : import com.google.inject.assistedinject.AssistedInject;
      29             : 
      30             : public class ReviewerResource implements RestResource {
      31         152 :   public static final TypeLiteral<RestView<ReviewerResource>> REVIEWER_KIND =
      32         152 :       new TypeLiteral<>() {};
      33             : 
      34             :   public interface Factory {
      35             :     ReviewerResource create(ChangeResource change, Account.Id id);
      36             : 
      37             :     ReviewerResource create(RevisionResource revision, Account.Id id);
      38             :   }
      39             : 
      40             :   private final ChangeResource change;
      41             :   private final RevisionResource revision;
      42             :   @Nullable private final IdentifiedUser user;
      43             :   @Nullable private final Address address;
      44             : 
      45             :   @AssistedInject
      46             :   ReviewerResource(
      47             :       IdentifiedUser.GenericFactory userFactory,
      48             :       @Assisted ChangeResource change,
      49          18 :       @Assisted Account.Id id) {
      50          18 :     this.change = change;
      51          18 :     this.user = userFactory.create(id);
      52          18 :     this.revision = null;
      53          18 :     this.address = null;
      54          18 :   }
      55             : 
      56             :   @AssistedInject
      57             :   ReviewerResource(
      58             :       IdentifiedUser.GenericFactory userFactory,
      59             :       @Assisted RevisionResource revision,
      60           5 :       @Assisted Account.Id id) {
      61           5 :     this.revision = revision;
      62           5 :     this.change = revision.getChangeResource();
      63           5 :     this.user = userFactory.create(id);
      64           5 :     this.address = null;
      65           5 :   }
      66             : 
      67           7 :   public ReviewerResource(ChangeResource change, Address address) {
      68           7 :     this.change = change;
      69           7 :     this.address = address;
      70           7 :     this.revision = null;
      71           7 :     this.user = null;
      72           7 :   }
      73             : 
      74           0 :   public ReviewerResource(RevisionResource revision, Address address) {
      75           0 :     this.revision = revision;
      76           0 :     this.change = revision.getChangeResource();
      77           0 :     this.address = address;
      78           0 :     this.user = null;
      79           0 :   }
      80             : 
      81             :   public ChangeResource getChangeResource() {
      82          19 :     return change;
      83             :   }
      84             : 
      85             :   public RevisionResource getRevisionResource() {
      86          13 :     return revision;
      87             :   }
      88             : 
      89             :   public Change.Id getChangeId() {
      90           2 :     return change.getId();
      91             :   }
      92             : 
      93             :   public Change getChange() {
      94          18 :     return change.getChange();
      95             :   }
      96             : 
      97             :   public IdentifiedUser getReviewerUser() {
      98          19 :     checkArgument(user != null, "no user provided");
      99          19 :     return user;
     100             :   }
     101             : 
     102             :   public Address getReviewerByEmail() {
     103           7 :     checkArgument(address != null, "no address provided");
     104           7 :     return address;
     105             :   }
     106             : 
     107             :   /**
     108             :    * Check if this resource was constructed by email or by {@code Account.Id}.
     109             :    *
     110             :    * @return true if the resource was constructed by providing an {@code Address}; false if the
     111             :    *     resource was constructed by providing an {@code Account.Id}.
     112             :    */
     113             :   public boolean isByEmail() {
     114          16 :     return user == null;
     115             :   }
     116             : }

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