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.collect.ImmutableList; 18 : import com.google.common.collect.ImmutableMap; 19 : import com.google.gerrit.extensions.client.ChangeStatus; 20 : import com.google.gerrit.extensions.client.ReviewerState; 21 : import com.google.gerrit.extensions.client.SubmitType; 22 : import java.sql.Timestamp; 23 : import java.time.Instant; 24 : import java.util.Collection; 25 : import java.util.List; 26 : import java.util.Map; 27 : 28 : /** 29 : * Representation of a change used in the API. Internally {@link 30 : * com.google.gerrit.server.query.change.ChangeData} and {@link com.google.gerrit.entities.Change} 31 : * are used. 32 : * 33 : * <p>Many fields are actually nullable. 34 : */ 35 : public class ChangeInfo { 36 : // ActionJson#copy(List, ChangeInfo) must be adapted if new fields are added that are not 37 : // protected by any ListChangesOption. 38 : 39 : public String id; 40 : public String project; 41 : public String branch; 42 : public String topic; 43 : /** 44 : * The <a href="https://www.gerritcodereview.com/design-docs/attention-set.html">attention set</a> 45 : * for this change. Keyed by account ID. We don't use {@link 46 : * com.google.gerrit.entities.Account.Id} to avoid a circular dependency. 47 : */ 48 : public Map<Integer, AttentionSetInfo> attentionSet; 49 : 50 : public Map<Integer, AttentionSetInfo> removedFromAttentionSet; 51 : 52 : public AccountInfo assignee; 53 : public Collection<String> hashtags; 54 : public String changeId; 55 : public String subject; 56 : public ChangeStatus status; 57 : 58 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 59 : // Instant 60 : public Timestamp created; 61 : public Timestamp updated; 62 : public Timestamp submitted; 63 : 64 : public AccountInfo submitter; 65 : public Boolean starred; 66 : public Collection<String> stars; 67 : public Boolean reviewed; 68 : public SubmitType submitType; 69 : public Boolean mergeable; 70 : public Boolean submittable; 71 : public Integer insertions; 72 : public Integer deletions; 73 : public Integer totalCommentCount; 74 : public Integer unresolvedCommentCount; 75 : public Boolean isPrivate; 76 : public Boolean workInProgress; 77 : public Boolean hasReviewStarted; 78 : public Integer revertOf; 79 : public String submissionId; 80 : public Integer cherryPickOfChange; 81 : public Integer cherryPickOfPatchSet; 82 : public String metaRevId; 83 : 84 : /** 85 : * Whether the change contains conflicts. 86 : * 87 : * <p>If {@code true}, some of the file contents of the change contain git conflict markers to 88 : * indicate the conflicts. 89 : * 90 : * <p>Only set if this change info is returned in response to a request that creates a new change 91 : * or patch set and conflicts are allowed. In particular this field is only populated if the 92 : * change info is returned by one of the following REST endpoints: {@link 93 : * com.google.gerrit.server.restapi.change.CreateChange}, {@link 94 : * com.google.gerrit.server.restapi.change.CreateMergePatchSet}, {@link 95 : * com.google.gerrit.server.restapi.change.CherryPick}, {@link 96 : * com.google.gerrit.server.restapi.change.CherryPickCommit}, {@link 97 : * com.google.gerrit.server.restapi.change.Rebase} 98 : */ 99 : public Boolean containsGitConflicts; 100 : 101 : public Integer _number; 102 : 103 : public AccountInfo owner; 104 : 105 : public Map<String, ActionInfo> actions; 106 : public Map<String, LabelInfo> labels; 107 : public Map<String, Collection<String>> permittedLabels; 108 : public Collection<AccountInfo> removableReviewers; 109 : public Map<ReviewerState, Collection<AccountInfo>> reviewers; 110 : public Map<ReviewerState, Collection<AccountInfo>> pendingReviewers; 111 : public Collection<ReviewerUpdateInfo> reviewerUpdates; 112 : public Collection<ChangeMessageInfo> messages; 113 : 114 : public String currentRevision; 115 : public Map<String, RevisionInfo> revisions; 116 : public Boolean _moreChanges; 117 : 118 : public List<ProblemInfo> problems; 119 : public List<PluginDefinedInfo> plugins; 120 : public Collection<TrackingIdInfo> trackingIds; 121 : public Collection<LegacySubmitRequirementInfo> requirements; 122 : public Collection<SubmitRecordInfo> submitRecords; 123 : public Collection<SubmitRequirementResultInfo> submitRequirements; 124 : 125 104 : public ChangeInfo() {} 126 : 127 1 : public ChangeInfo(ChangeMessageInfo... messages) { 128 1 : this.messages = ImmutableList.copyOf(messages); 129 1 : } 130 : 131 1 : public ChangeInfo(Map<String, RevisionInfo> revisions) { 132 1 : this.revisions = ImmutableMap.copyOf(revisions); 133 1 : } 134 : 135 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 136 : // Instant 137 : @SuppressWarnings("JdkObsolete") 138 : public Instant getCreated() { 139 0 : return created.toInstant(); 140 : } 141 : 142 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 143 : // Instant 144 : @SuppressWarnings("JdkObsolete") 145 : public void setCreated(Instant when) { 146 103 : created = Timestamp.from(when); 147 103 : } 148 : 149 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 150 : // Instant 151 : @SuppressWarnings("JdkObsolete") 152 : public Instant getUpdated() { 153 6 : return updated.toInstant(); 154 : } 155 : 156 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 157 : // Instant 158 : @SuppressWarnings("JdkObsolete") 159 : public void setUpdated(Instant when) { 160 103 : updated = Timestamp.from(when); 161 103 : } 162 : 163 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 164 : // Instant 165 : @SuppressWarnings("JdkObsolete") 166 : public Instant getSubmitted() { 167 6 : return submitted.toInstant(); 168 : } 169 : 170 : // TODO(issue-15508): Migrate timestamp fields in *Info/*Input classes from type Timestamp to 171 : // Instant 172 : @SuppressWarnings("JdkObsolete") 173 : public void setSubmitted(Instant when, AccountInfo who) { 174 55 : submitted = Timestamp.from(when); 175 55 : submitter = who; 176 55 : } 177 : }