LCOV - code coverage report
Current view: top level - extensions/common - AccountInfo.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 22 31 71.0 %
Date: 2022-11-19 15:00:39 Functions: 5 7 71.4 %

          Line data    Source code
       1             : // Copyright (C) 2014 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.extensions.common;
      16             : 
      17             : import com.google.common.base.MoreObjects;
      18             : import java.util.List;
      19             : import java.util.Objects;
      20             : 
      21             : /**
      22             :  * Representation of an account in the REST API.
      23             :  *
      24             :  * <p>This class determines the JSON format of accounts in the REST API.
      25             :  *
      26             :  * <p>This class defines fields for account properties that are frequently used. Additional fields
      27             :  * are defined in {@link AccountDetailInfo}.
      28             :  */
      29             : public class AccountInfo {
      30             :   /**
      31             :    * Tags are additional properties of an account. These are just tags known to Gerrit core. Plugins
      32             :    * may define their own.
      33             :    */
      34           0 :   public static final class Tags {
      35             :     /** Tag indicating that this account is a service user. */
      36             :     public static final String SERVICE_USER = "SERVICE_USER";
      37             :   }
      38             : 
      39             :   /** The numeric ID of the account. */
      40             :   public Integer _accountId;
      41             : 
      42             :   /** The full name of the user. */
      43             :   public String name;
      44             : 
      45             :   /**
      46             :    * The display name of the user. This allows users to control how their name is displayed in the
      47             :    * UI. It will likely be unset for most users. This account property is just a way to opt out of
      48             :    * the host wide default strategy of choosing the display name, see
      49             :    * accounts.accountDefaultDisplayName in the server config. The default strategy is not applied by
      50             :    * the backend. The display name will just be left unset, and the client has to load and apply the
      51             :    * default strategy.
      52             :    */
      53             :   public String displayName;
      54             : 
      55             :   /** The preferred email address of the user. */
      56             :   public String email;
      57             : 
      58             :   /** List of the secondary email addresses of the user. */
      59             :   public List<String> secondaryEmails;
      60             : 
      61             :   /** The username of the user. */
      62             :   public String username;
      63             : 
      64             :   /** List of avatars of the user. */
      65             :   public List<AvatarInfo> avatars;
      66             : 
      67             :   /**
      68             :    * Whether the query would deliver more results if not limited. Only set on the last account that
      69             :    * is returned as a query result.
      70             :    */
      71             :   public Boolean _moreAccounts;
      72             : 
      73             :   /** Status message of the account (e.g. 'OOO' for out-of-office). */
      74             :   public String status;
      75             : 
      76             :   /** Whether the account is inactive. */
      77             :   public Boolean inactive;
      78             : 
      79             :   /** Tags, such as whether this account is a service user. */
      80             :   public List<String> tags;
      81             : 
      82         151 :   public AccountInfo(Integer id) {
      83         151 :     this._accountId = id;
      84         151 :   }
      85             : 
      86             :   /** To be used ONLY in connection with unregistered reviewers and CCs. */
      87          11 :   public AccountInfo(String name, String email) {
      88          11 :     this.name = name;
      89          11 :     this.email = email;
      90          11 :   }
      91             : 
      92             :   @Override
      93             :   public boolean equals(Object o) {
      94           8 :     if (o instanceof AccountInfo) {
      95           8 :       AccountInfo accountInfo = (AccountInfo) o;
      96           8 :       return Objects.equals(_accountId, accountInfo._accountId)
      97           7 :           && Objects.equals(name, accountInfo.name)
      98           7 :           && Objects.equals(displayName, accountInfo.displayName)
      99           7 :           && Objects.equals(email, accountInfo.email)
     100           7 :           && Objects.equals(secondaryEmails, accountInfo.secondaryEmails)
     101           7 :           && Objects.equals(username, accountInfo.username)
     102           7 :           && Objects.equals(avatars, accountInfo.avatars)
     103           7 :           && Objects.equals(_moreAccounts, accountInfo._moreAccounts)
     104           7 :           && Objects.equals(status, accountInfo.status)
     105           8 :           && Objects.equals(tags, accountInfo.tags);
     106             :     }
     107           2 :     return false;
     108             :   }
     109             : 
     110             :   @Override
     111             :   public String toString() {
     112           0 :     return MoreObjects.toStringHelper(this)
     113           0 :         .add("id", _accountId)
     114           0 :         .add("name", name)
     115           0 :         .add("displayname", displayName)
     116           0 :         .add("email", email)
     117           0 :         .add("username", username)
     118           0 :         .add("tags", tags)
     119           0 :         .toString();
     120             :   }
     121             : 
     122             :   @Override
     123             :   public int hashCode() {
     124          23 :     return Objects.hash(
     125             :         _accountId,
     126             :         name,
     127             :         displayName,
     128             :         email,
     129             :         secondaryEmails,
     130             :         username,
     131             :         avatars,
     132             :         _moreAccounts,
     133             :         status,
     134             :         tags);
     135             :   }
     136             : 
     137          10 :   protected AccountInfo() {}
     138             : }

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