LCOV - code coverage report
Current view: top level - extensions/common - ApprovalInfo.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 9 28 32.1 %
Date: 2022-11-19 15:00:39 Functions: 2 7 28.6 %

          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.gerrit.common.Nullable;
      18             : import java.sql.Timestamp;
      19             : import java.time.Instant;
      20             : import java.util.Objects;
      21             : 
      22             : /**
      23             :  * Representation of an approval in the REST API.
      24             :  *
      25             :  * <p>This class determines the JSON format of approvals in the REST API.
      26             :  *
      27             :  * <p>An approval is a vote of a user for a label on a change.
      28             :  */
      29             : public class ApprovalInfo extends AccountInfo {
      30             :   /**
      31             :    * Tag that was set when posting the review that created this approval.
      32             :    *
      33             :    * <p>Web UIs may use the tag to filter out approvals, e.g. initially hide approvals that have a
      34             :    * tag that starts with the {@code autogenerated:} prefix.
      35             :    */
      36             :   public String tag;
      37             : 
      38             :   /**
      39             :    * The vote that the user has given for the label.
      40             :    *
      41             :    * <p>If present and zero, the user is permitted to vote on the label. If absent, the user is not
      42             :    * permitted to vote on that label.
      43             :    */
      44             :   public Integer value;
      45             : 
      46             :   /** The time and date describing when the approval was made. */
      47             :   // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to
      48             :   // Instant
      49             :   public Timestamp date;
      50             : 
      51             :   /** Whether this vote was made after the change was submitted. */
      52             :   public Boolean postSubmit;
      53             : 
      54             :   /**
      55             :    * The range the user is authorized to vote on that label.
      56             :    *
      57             :    * <p>If present, the user is permitted to vote on the label regarding the range values. If
      58             :    * absent, the user is not permitted to vote on that label.
      59             :    */
      60             :   public VotingRangeInfo permittedVotingRange;
      61             : 
      62             :   public ApprovalInfo(Integer id) {
      63           0 :     super(id);
      64           0 :   }
      65             : 
      66             :   public ApprovalInfo(
      67             :       Integer id,
      68             :       @Nullable Integer value,
      69             :       @Nullable VotingRangeInfo permittedVotingRange,
      70             :       @Nullable String tag,
      71             :       @Nullable Timestamp date) {
      72           0 :     super(id);
      73           0 :     this.value = value;
      74           0 :     this.permittedVotingRange = permittedVotingRange;
      75           0 :     this.date = date;
      76           0 :     this.tag = tag;
      77           0 :   }
      78             : 
      79             :   public ApprovalInfo(
      80             :       Integer id,
      81             :       @Nullable Integer value,
      82             :       @Nullable VotingRangeInfo permittedVotingRange,
      83             :       @Nullable String tag,
      84             :       @Nullable Instant date) {
      85          76 :     super(id);
      86          76 :     this.value = value;
      87          76 :     this.permittedVotingRange = permittedVotingRange;
      88          76 :     this.tag = tag;
      89          76 :     if (date != null) {
      90          65 :       setDate(date);
      91             :     }
      92          76 :   }
      93             : 
      94             :   // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to
      95             :   // Instant
      96             :   @SuppressWarnings("JdkObsolete")
      97             :   public void setDate(Instant date) {
      98          65 :     this.date = Timestamp.from(date);
      99          65 :   }
     100             : 
     101             :   @Override
     102             :   public boolean equals(Object o) {
     103           0 :     if (o instanceof ApprovalInfo) {
     104           0 :       ApprovalInfo approvalInfo = (ApprovalInfo) o;
     105           0 :       return super.equals(o)
     106           0 :           && Objects.equals(tag, approvalInfo.tag)
     107           0 :           && Objects.equals(value, approvalInfo.value)
     108           0 :           && Objects.equals(date, approvalInfo.date)
     109           0 :           && Objects.equals(postSubmit, approvalInfo.postSubmit)
     110           0 :           && Objects.equals(permittedVotingRange, approvalInfo.permittedVotingRange);
     111             :     }
     112           0 :     return false;
     113             :   }
     114             : 
     115             :   @Override
     116             :   public String toString() {
     117           0 :     return super.toString() + ", value=" + this.value;
     118             :   }
     119             : 
     120             :   @Override
     121             :   public int hashCode() {
     122           0 :     return Objects.hash(super.hashCode(), tag, value, date, postSubmit, permittedVotingRange);
     123             :   }
     124             : }

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