Line data Source code
1 : // Copyright (C) 2020 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 : * Represents a single user included in the attention set. Used in the API. See {@link 24 : * com.google.gerrit.entities.AttentionSetUpdate} for the internal representation. 25 : * 26 : * <p>See <a href="https://www.gerritcodereview.com/design-docs/attention-set.html">here</a> for 27 : * background. 28 : */ 29 : public class AttentionSetInfo { 30 : /** The user included in the attention set. */ 31 : public AccountInfo account; 32 : 33 : /** The timestamp of the last update. */ 34 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 35 : // Instant 36 : public Timestamp lastUpdate; 37 : 38 : /** The human readable reason why the user was added. */ 39 : public String reason; 40 : 41 : /** 42 : * The user that might be mentioned in {@link #reason} as the one who caused the update. This is 43 : * needed since {@link #reason} contains the account in pseudonymized form and is expanded in the 44 : * frontend. {@code null} if there is no such account. 45 : */ 46 : @Nullable public AccountInfo reasonAccount; 47 : 48 : public AttentionSetInfo( 49 : AccountInfo account, 50 : Timestamp lastUpdate, 51 : String reason, 52 0 : @Nullable AccountInfo reasonAccount) { 53 0 : this.account = account; 54 0 : this.lastUpdate = lastUpdate; 55 0 : this.reason = reason; 56 0 : this.reasonAccount = reasonAccount; 57 0 : } 58 : 59 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 60 : // Instant 61 : @SuppressWarnings("JdkObsolete") 62 : public AttentionSetInfo( 63 49 : AccountInfo account, Instant lastUpdate, String reason, @Nullable AccountInfo reasonAccount) { 64 49 : this.account = account; 65 49 : this.lastUpdate = Timestamp.from(lastUpdate); 66 49 : this.reason = reason; 67 49 : this.reasonAccount = reasonAccount; 68 49 : } 69 : 70 0 : protected AttentionSetInfo() {} 71 : 72 : @Override 73 : public boolean equals(Object o) { 74 0 : if (o instanceof AttentionSetInfo) { 75 0 : AttentionSetInfo attentionSetInfo = (AttentionSetInfo) o; 76 0 : return Objects.equals(account, attentionSetInfo.account) 77 0 : && Objects.equals(lastUpdate, attentionSetInfo.lastUpdate) 78 0 : && Objects.equals(reason, attentionSetInfo.reason) 79 0 : && Objects.equals(reasonAccount, attentionSetInfo.reasonAccount); 80 : } 81 0 : return false; 82 : } 83 : 84 : @Override 85 : public int hashCode() { 86 1 : return Objects.hash(account, lastUpdate, reason, reasonAccount); 87 : } 88 : }