Class ChangeData

java.lang.Object
com.google.gerrit.server.query.change.ChangeData

public class ChangeData extends Object
ChangeData provides lazily loaded interface to change metadata loaded from NoteDb. It can be constructed by loading from NoteDb, or calling setters. The latter happens when ChangeData is retrieved through the change index. This happens for Applications that are performance sensitive (eg. dashboard loads, git protocol negotiation) but can tolerate staleness. In that case, setting lazyLoad=false disables loading from NoteDb, so we don't accidentally enable a slow path.
  • Method Details

    • asChanges

      public static List<Change> asChanges(List<ChangeData> changeDatas)
    • asMap

      public static Map<Change.Id,ChangeData> asMap(List<ChangeData> changes)
    • ensureChangeLoaded

      public static void ensureChangeLoaded(Iterable<ChangeData> changes)
    • ensureAllPatchSetsLoaded

      public static void ensureAllPatchSetsLoaded(Iterable<ChangeData> changes)
    • ensureCurrentPatchSetLoaded

      public static void ensureCurrentPatchSetLoaded(Iterable<ChangeData> changes)
    • ensureCurrentApprovalsLoaded

      public static void ensureCurrentApprovalsLoaded(Iterable<ChangeData> changes)
    • ensureMessagesLoaded

      public static void ensureMessagesLoaded(Iterable<ChangeData> changes)
    • ensureReviewedByLoadedForOpenChanges

      public static void ensureReviewedByLoadedForOpenChanges(Iterable<ChangeData> changes)
    • createForTest

      public static ChangeData createForTest(Project.NameKey project, Change.Id id, int currentPatchSetId, org.eclipse.jgit.lib.ObjectId commitId)
      Create an instance for testing only.

      Attempting to lazy load data will fail with NPEs. Callers may consider manually setting fields that can be set.

      Parameters:
      project - project name
      id - change ID
      currentPatchSetId - current patchset number
      commitId - commit SHA1 of the current patchset
      Returns:
      instance for testing.
    • createForTest

      public static ChangeData createForTest(Project.NameKey project, Change.Id id, int currentPatchSetId, org.eclipse.jgit.lib.ObjectId commitId, ChangeNumberVirtualIdAlgorithm virtualIdAlgo, ChangeNotes changeNotes)
      Create an instance for testing only.

      Attempting to lazy load data will fail with NPEs. Callers may consider manually setting fields that can be set.

      Parameters:
      project - project name
      id - change ID
      currentPatchSetId - current patchset number
      commitId - commit SHA1 of the current patchset
      virtualIdAlgo - algorithm for virtualising the Change number
      changeNotes - notes associated with the Change
      Returns:
      instance for testing.
    • setStorageConstraint

      @CanIgnoreReturnValue public ChangeData setStorageConstraint(ChangeData.StorageConstraint storageConstraint)
      If false, omit fields that require database/repo IO.

      This is used to enforce that the dashboard is rendered from the index only. If lazyLoad is on, the ChangeData object will load from the database ("lazily") when a field accessor is called.

    • getStorageConstraint

      public ChangeData.StorageConstraint getStorageConstraint()
    • lazyload

      public boolean lazyload()
      Returns true if we allow reading data from NoteDb.
    • getAllUsersNameForIndexing

      public AllUsersName getAllUsersNameForIndexing()
    • setFailedParsingFromIndex

      public void setFailedParsingFromIndex(Boolean val)
    • hasFailedParsingFromIndex

      public boolean hasFailedParsingFromIndex()
    • setCurrentFilePaths

      public void setCurrentFilePaths(List<String> filePaths)
    • currentFilePaths

      public List<String> currentFilePaths()
    • changedLines

      public Optional<ChangeData.ChangedLines> changedLines()
    • setChangedLines

      public void setChangedLines(int insertions, int deletions)
    • setLinesInserted

      public void setLinesInserted(int insertions)
    • setLinesDeleted

      public void setLinesDeleted(int deletions)
    • setNoChangedLines

      public void setNoChangedLines()
    • getId

      public Change.Id getId()
    • ensureChangeServerId

      public static void ensureChangeServerId(Iterable<ChangeData> changes)
    • changeServerId

      public String changeServerId()
    • virtualId

      public Change.Id virtualId()
    • project

      public Project.NameKey project()
    • branchOrThrow

      public BranchNameKey branchOrThrow()
    • isPrivateOrThrow

      public boolean isPrivateOrThrow()
    • setMetaRevision

      @CanIgnoreReturnValue public ChangeData setMetaRevision(org.eclipse.jgit.lib.ObjectId metaRevision)
    • metaRevision

      public Optional<org.eclipse.jgit.lib.ObjectId> metaRevision()
    • metaRevisionOrThrow

      public org.eclipse.jgit.lib.ObjectId metaRevisionOrThrow()
    • change

      public Change change()
    • setChange

      public void setChange(Change c)
    • reloadChange

      @CanIgnoreReturnValue public Change reloadChange()
    • getLabelTypes

      public LabelTypes getLabelTypes()
    • notes

      public ChangeNotes notes()
    • currentPatchSet

      public PatchSet currentPatchSet()
    • currentApprovals

      public List<PatchSetApproval> currentApprovals()
    • setCurrentApprovals

      public void setCurrentApprovals(List<PatchSetApproval> approvals)
    • commitMessage

      public String commitMessage()
    • commitFooters

      public List<org.eclipse.jgit.revwalk.FooterLine> commitFooters()
      Returns the list of commit footers (which may be empty).
    • trackingFooters

      public com.google.common.collect.ListMultimap<String,String> trackingFooters()
    • getAuthor

      public org.eclipse.jgit.lib.PersonIdent getAuthor()
    • getCommitter

      public org.eclipse.jgit.lib.PersonIdent getCommitter()
    • attentionSet

      public com.google.common.collect.ImmutableSet<AttentionSetUpdate> attentionSet()
      Returns the most recent update (i.e. status) per user.
    • getMergedOn

      public Optional<Instant> getMergedOn() throws com.google.gerrit.exceptions.StorageException
      Returns the Optional value of time when the change was merged.

      The value can be set from index field, see setMergedOn(java.time.Instant) or loaded from the database (available in ChangeNotes)

      Returns:
      Optional value of time when the change was merged.
      Throws:
      com.google.gerrit.exceptions.StorageException - if lazyLoad is off, ChangeNotes can not be loaded because we do not expect to call the database.
    • setMergedOn

      public void setMergedOn(Instant mergedOn)
      Sets the value e.g. when loading from index.
    • setAttentionSet

      public void setAttentionSet(com.google.common.collect.ImmutableSet<AttentionSetUpdate> attentionSet)
      Sets the specified attention set. If two or more entries refer to the same user, throws an IllegalStateException.
    • patchSets

      public Collection<PatchSet> patchSets()
      Returns patches for the change, in patch set ID order.
    • setPatchSets

      public void setPatchSets(Collection<PatchSet> patchSets)
    • patchSet

      public PatchSet patchSet(PatchSet.Id psId)
      Returns patch with the given ID, or null if it does not exist.
    • approvals

      public com.google.common.collect.ListMultimap<PatchSet.Id,PatchSetApproval> approvals()
      Returns all patch set approvals for the change, keyed by ID, ordered by timestamp within each patch set.
    • conditionallyLoadApprovalsWithCopied

      public com.google.common.collect.ListMultimap<PatchSet.Id,PatchSetApproval> conditionallyLoadApprovalsWithCopied()
    • getSubmitApproval

      public Optional<PatchSetApproval> getSubmitApproval()
    • reviewers

      public ReviewerSet reviewers()
    • setReviewers

      public void setReviewers(ReviewerSet reviewers)
    • reviewersByEmail

      public ReviewerByEmailSet reviewersByEmail()
    • setReviewersByEmail

      public void setReviewersByEmail(ReviewerByEmailSet reviewersByEmail)
    • getReviewersByEmail

      public ReviewerByEmailSet getReviewersByEmail()
    • setPendingReviewers

      public void setPendingReviewers(ReviewerSet pendingReviewers)
    • getPendingReviewers

      public ReviewerSet getPendingReviewers()
    • pendingReviewers

      public ReviewerSet pendingReviewers()
    • setPendingReviewersByEmail

      public void setPendingReviewersByEmail(ReviewerByEmailSet pendingReviewersByEmail)
    • getPendingReviewersByEmail

      public ReviewerByEmailSet getPendingReviewersByEmail()
    • pendingReviewersByEmail

      public ReviewerByEmailSet pendingReviewersByEmail()
    • reviewerUpdates

      public List<ReviewerStatusUpdate> reviewerUpdates()
    • setReviewerUpdates

      public void setReviewerUpdates(List<ReviewerStatusUpdate> reviewerUpdates)
    • getReviewerUpdates

      public List<ReviewerStatusUpdate> getReviewerUpdates()
    • publishedComments

      public Collection<HumanComment> publishedComments()
    • robotComments

      public Collection<RobotComment> robotComments()
    • unresolvedCommentCount

      public Integer unresolvedCommentCount()
    • setUnresolvedCommentCount

      public void setUnresolvedCommentCount(Integer count)
    • totalCommentCount

      public Integer totalCommentCount()
    • setTotalCommentCount

      public void setTotalCommentCount(Integer count)
    • messages

      public List<ChangeMessage> messages()
    • submitRequirementsIncludingLegacy

      public Map<SubmitRequirement,SubmitRequirementResult> submitRequirementsIncludingLegacy()
      Similar to submitRequirements(), except that it also converts submit records resulting from the evaluation of legacy submit rules to submit requirements.
    • submitRequirements

      public Map<SubmitRequirement,SubmitRequirementResult> submitRequirements()
      Get all evaluated submit requirements for this change, including those from parent projects. For closed changes, submit requirements are read from the change notes. For active changes, submit requirements are evaluated online.

      For changes loaded from the index, the value will be set from index field ChangeField.STORED_SUBMIT_REQUIREMENTS_FIELD.

    • setSubmitRequirements

      public void setSubmitRequirements(Map<SubmitRequirement,SubmitRequirementResult> submitRequirements)
    • submitRecords

      public List<SubmitRecord> submitRecords(SubmitRuleOptions options)
    • setSubmitRecords

      public void setSubmitRecords(SubmitRuleOptions options, List<SubmitRecord> records)
    • submitTypeRecord

      public SubmitTypeRecord submitTypeRecord()
    • setMergeable

      public void setMergeable(Boolean mergeable)
    • isMergeable

      public Boolean isMergeable()
    • isMerge

      public Boolean isMerge()
    • editsByUser

      public Set<Account.Id> editsByUser()
    • editRefs

      public com.google.common.collect.Table<Account.Id,PatchSet.Id,org.eclipse.jgit.lib.Ref> editRefs()
    • draftsByUser

      public Set<Account.Id> draftsByUser()
    • isReviewedBy

      public boolean isReviewedBy(Account.Id accountId)
    • reviewedBy

      public Set<Account.Id> reviewedBy()
    • setReviewedBy

      public void setReviewedBy(Set<Account.Id> reviewedBy)
    • hashtags

      public Set<String> hashtags()
    • setHashtags

      public void setHashtags(Set<String> hashtags)
    • customKeyedValues

      public Map<String,String> customKeyedValues()
    • setCustomKeyedValues

      public void setCustomKeyedValues(Map<String,String> customKeyedValues)
    • stars

      public com.google.common.collect.ImmutableList<Account.Id> stars()
    • setStars

      public void setStars(List<Account.Id> accountIds)
    • isStarred

      public boolean isStarred(Account.Id accountId)
    • isPureRevert

      public Boolean isPureRevert()
      Returns null if revertOf is null; true if the change is a pure revert; false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getRefStates

      public com.google.common.collect.SetMultimap<Project.NameKey,RefState> getRefStates()
    • setRefStates

      public void setRefStates(com.google.common.collect.ImmutableSetMultimap<Project.NameKey,RefState> refStates)
    • getRefStatePatterns

      public com.google.common.collect.ImmutableList<byte[]> getRefStatePatterns()
    • setRefStatePatterns

      public void setRefStatePatterns(Iterable<byte[]> refStatePatterns)