ReviewerResource: Don't inherit from ChangeResource
Prefer composition to inheritance. This one was particularly confusing because of the two different users/controls (caller and reviewer). Continue the disambiguating started by the previous commit and give methods slightly more descriptive names. Change-Id: I3ce101d32cb133698c20869649576808f3240d4b
This commit is contained in:
@@ -75,7 +75,7 @@ public class DeleteReviewer implements RestModifyView<ReviewerResource, Input> {
|
||||
throws AuthException, ResourceNotFoundException, OrmException,
|
||||
IOException {
|
||||
ChangeControl control = rsrc.getControl();
|
||||
Change.Id changeId = rsrc.getId();
|
||||
Change.Id changeId = rsrc.getChangeId();
|
||||
ReviewDb db = dbProvider.get();
|
||||
ChangeUpdate update = updateFactory.create(rsrc.getControl());
|
||||
|
||||
@@ -103,13 +103,13 @@ public class DeleteReviewer implements RestModifyView<ReviewerResource, Input> {
|
||||
if (del.isEmpty()) {
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
ChangeUtil.bumpRowVersionNotLastUpdatedOn(rsrc.getId(), db);
|
||||
ChangeUtil.bumpRowVersionNotLastUpdatedOn(rsrc.getChangeId(), db);
|
||||
db.patchSetApprovals().delete(del);
|
||||
update.removeReviewer(rsrc.getReviewerUser().getAccountId());
|
||||
|
||||
if (msg.length() > 0) {
|
||||
ChangeMessage changeMessage =
|
||||
new ChangeMessage(new ChangeMessage.Key(rsrc.getId(),
|
||||
new ChangeMessage(new ChangeMessage.Key(rsrc.getChangeId(),
|
||||
ChangeUtil.messageUUID(db)),
|
||||
control.getUser().getAccountId(),
|
||||
TimeUtil.nowTs(), rsrc.getChange().currentPatchSetId());
|
||||
@@ -138,7 +138,8 @@ public class DeleteReviewer implements RestModifyView<ReviewerResource, Input> {
|
||||
ReviewerResource rsrc) throws OrmException {
|
||||
final Account.Id user = rsrc.getReviewerUser().getAccountId();
|
||||
return Iterables.filter(
|
||||
approvalsUtil.byChange(db, rsrc.getNotes()).values(),
|
||||
approvalsUtil.byChange(db, rsrc.getChangeResource().getNotes())
|
||||
.values(),
|
||||
new Predicate<PatchSetApproval>() {
|
||||
@Override
|
||||
public boolean apply(PatchSetApproval input) {
|
||||
|
@@ -70,11 +70,9 @@ public class DeleteVote implements RestModifyView<VoteResource, Input> {
|
||||
public Response<?> apply(VoteResource rsrc, Input input)
|
||||
throws RestApiException, UpdateException {
|
||||
ReviewerResource r = rsrc.getReviewer();
|
||||
ChangeControl ctl = r.getControl();
|
||||
Change change = r.getChange();
|
||||
try (BatchUpdate bu = batchUpdateFactory.create(db.get(),
|
||||
change.getProject(), ctl.getUser().asIdentifiedUser(),
|
||||
TimeUtil.nowTs())) {
|
||||
change.getProject(), r.getControl().getUser(), TimeUtil.nowTs())) {
|
||||
bu.addOp(change.getId(),
|
||||
new Op(r.getReviewerUser().getAccountId(), rsrc.getLabel()));
|
||||
bu.execute();
|
||||
|
@@ -150,10 +150,11 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
||||
private PostResult putAccount(ReviewerResource rsrc) throws OrmException,
|
||||
IOException {
|
||||
Account member = rsrc.getReviewerUser().getAccount();
|
||||
ChangeControl control = rsrc.getControl();
|
||||
ChangeControl control = rsrc.getReviewerControl();
|
||||
PostResult result = new PostResult();
|
||||
if (isValidReviewer(member, control)) {
|
||||
addReviewers(rsrc, result, ImmutableMap.of(member.getId(), control));
|
||||
addReviewers(rsrc.getChangeResource(), result,
|
||||
ImmutableMap.of(member.getId(), control));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ public class ReviewerJson {
|
||||
for (ReviewerResource rsrc : rsrcs) {
|
||||
ReviewerInfo info = format(new ReviewerInfo(
|
||||
rsrc.getReviewerUser().getAccountId()),
|
||||
rsrc.getUserControl());
|
||||
rsrc.getReviewerControl());
|
||||
loader.put(info);
|
||||
infos.add(info);
|
||||
}
|
||||
|
@@ -14,48 +14,64 @@
|
||||
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
|
||||
public class ReviewerResource extends ChangeResource {
|
||||
public class ReviewerResource implements RestResource {
|
||||
public static final TypeLiteral<RestView<ReviewerResource>> REVIEWER_KIND =
|
||||
new TypeLiteral<RestView<ReviewerResource>>() {};
|
||||
|
||||
public static interface Factory {
|
||||
ReviewerResource create(ChangeResource rsrc, IdentifiedUser user);
|
||||
ReviewerResource create(ChangeResource rsrc, Account.Id id);
|
||||
ReviewerResource create(ChangeResource change, Account.Id id);
|
||||
}
|
||||
|
||||
private final ChangeResource change;
|
||||
private final IdentifiedUser user;
|
||||
|
||||
@AssistedInject
|
||||
ReviewerResource(@Assisted ChangeResource rsrc,
|
||||
@Assisted IdentifiedUser user) {
|
||||
super(rsrc);
|
||||
this.user = user;
|
||||
ReviewerResource(IdentifiedUser.GenericFactory userFactory,
|
||||
@Assisted ChangeResource change,
|
||||
@Assisted Account.Id id) {
|
||||
this.change = change;
|
||||
this.user = userFactory.create(id);
|
||||
}
|
||||
|
||||
@AssistedInject
|
||||
ReviewerResource(IdentifiedUser.GenericFactory userFactory,
|
||||
@Assisted ChangeResource rsrc,
|
||||
@Assisted Account.Id id) {
|
||||
this(rsrc, userFactory.create(id));
|
||||
public ChangeResource getChangeResource() {
|
||||
return change;
|
||||
}
|
||||
|
||||
public Change.Id getChangeId() {
|
||||
return change.getId();
|
||||
}
|
||||
|
||||
public Change getChange() {
|
||||
return change.getChange();
|
||||
}
|
||||
|
||||
public IdentifiedUser getReviewerUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the control for the caller's user (as opposed to the reviewer's
|
||||
* user as returned by {@link #getReviewerControl()}).
|
||||
*/
|
||||
public ChangeControl getControl() {
|
||||
return change.getControl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the control for the reviewer's user (as opposed to the caller's
|
||||
* user as returned by {@link #getControl()}).
|
||||
*/
|
||||
public ChangeControl getUserControl() {
|
||||
return getControl().forUser(user);
|
||||
public ChangeControl getReviewerControl() {
|
||||
return change.getControl().forUser(user);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user