Package com.google.gerrit.server
Class ApprovalsUtil
- java.lang.Object
-
- com.google.gerrit.server.ApprovalsUtil
-
public class ApprovalsUtil extends Object
Utility functions to manipulate patchset approvals.Approvals are overloaded, they represent both approvals and reviewers which should be CCed on a change. To ensure that reviewers are not lost there must always be an approval on each patchset for each reviewer, even if the reviewer hasn't actually given a score to the change. To mark the "no score" case, a dummy approval, which may live in any of the available categories, with a score of 0 is used.
The methods in this class only modify the gwtorm database.
-
-
Constructor Summary
Constructors Constructor Description ApprovalsUtil(NotesMigration migration, IdentifiedUser.GenericFactory userFactory, ApprovalCopier copier, PermissionBackend permissionBackend)
-
Method Summary
-
-
-
Constructor Detail
-
ApprovalsUtil
@Inject public ApprovalsUtil(NotesMigration migration, IdentifiedUser.GenericFactory userFactory, ApprovalCopier copier, PermissionBackend permissionBackend)
-
-
Method Detail
-
sortApprovals
public static List<PatchSetApproval> sortApprovals(Iterable<PatchSetApproval> approvals)
-
newApproval
public static PatchSetApproval newApproval(PatchSet.Id psId, CurrentUser user, LabelId labelId, int value, Date when)
-
getReviewers
public ReviewerSet getReviewers(ReviewDb db, ChangeNotes notes) throws com.google.gwtorm.server.OrmException
Get all reviewers for a change.- Parameters:
db
- review database.notes
- change notes.- Returns:
- reviewers for the change.
- Throws:
com.google.gwtorm.server.OrmException
- if reviewers for the change could not be read.
-
getReviewers
public ReviewerSet getReviewers(ChangeNotes notes, Iterable<PatchSetApproval> allApprovals) throws com.google.gwtorm.server.OrmException
Get all reviewers and CCed accounts for a change.- Parameters:
allApprovals
- all approvals to consider; must all belong to the same change.- Returns:
- reviewers for the change.
- Throws:
com.google.gwtorm.server.OrmException
- if reviewers for the change could not be read.
-
getReviewerUpdates
public List<ReviewerStatusUpdate> getReviewerUpdates(ChangeNotes notes) throws com.google.gwtorm.server.OrmException
Get updates to reviewer set. Always returns empty list for ReviewDb.- Parameters:
notes
- change notes.- Returns:
- reviewer updates for the change.
- Throws:
com.google.gwtorm.server.OrmException
- if reviewer updates for the change could not be read.
-
addReviewers
public List<PatchSetApproval> addReviewers(ReviewDb db, ChangeUpdate update, LabelTypes labelTypes, Change change, PatchSet ps, PatchSetInfo info, Iterable<Account.Id> wantReviewers, Collection<Account.Id> existingReviewers) throws com.google.gwtorm.server.OrmException
- Throws:
com.google.gwtorm.server.OrmException
-
addReviewers
public List<PatchSetApproval> addReviewers(ReviewDb db, ChangeNotes notes, ChangeUpdate update, LabelTypes labelTypes, Change change, Iterable<Account.Id> wantReviewers) throws com.google.gwtorm.server.OrmException
- Throws:
com.google.gwtorm.server.OrmException
-
addCcs
public Collection<Account.Id> addCcs(ChangeNotes notes, ChangeUpdate update, Collection<Account.Id> wantCCs) throws com.google.gwtorm.server.OrmException
Adds accounts to a change as reviewers in the CC state.- Parameters:
notes
- change notes.update
- change update.wantCCs
- accounts to CC.- Returns:
- whether a change was made.
- Throws:
com.google.gwtorm.server.OrmException
-
addApprovalsForNewPatchSet
public Iterable<PatchSetApproval> addApprovalsForNewPatchSet(ReviewDb db, ChangeUpdate update, LabelTypes labelTypes, PatchSet ps, CurrentUser user, Map<String,Short> approvals) throws RestApiException, com.google.gwtorm.server.OrmException, PermissionBackendException
Adds approvals to ChangeUpdate for a new patch set, and writes to ReviewDb.- Parameters:
db
- review database.update
- change update.labelTypes
- label types for the containing project.ps
- patch set being approved.user
- user adding approvals.approvals
- approvals to add.- Throws:
RestApiException
com.google.gwtorm.server.OrmException
PermissionBackendException
-
checkLabel
public static void checkLabel(LabelTypes labelTypes, String name, Short value) throws BadRequestException
- Throws:
BadRequestException
-
byChange
public com.google.common.collect.ListMultimap<PatchSet.Id,PatchSetApproval> byChange(ReviewDb db, ChangeNotes notes) throws com.google.gwtorm.server.OrmException
- Throws:
com.google.gwtorm.server.OrmException
-
byPatchSet
public Iterable<PatchSetApproval> byPatchSet(ReviewDb db, ChangeNotes notes, CurrentUser user, PatchSet.Id psId, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.Config repoConfig) throws com.google.gwtorm.server.OrmException
- Throws:
com.google.gwtorm.server.OrmException
-
byPatchSetUser
public Iterable<PatchSetApproval> byPatchSetUser(ReviewDb db, ChangeNotes notes, CurrentUser user, PatchSet.Id psId, Account.Id accountId, org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.Config repoConfig) throws com.google.gwtorm.server.OrmException
- Throws:
com.google.gwtorm.server.OrmException
-
getSubmitter
public PatchSetApproval getSubmitter(ReviewDb db, ChangeNotes notes, PatchSet.Id c)
-
getSubmitter
public static PatchSetApproval getSubmitter(PatchSet.Id c, Iterable<PatchSetApproval> approvals)
-
-