ChangeControl: Add getId() method
Change-Id: I7d559df16e431f6440b031ed80dd1025efa0a71a
This commit is contained in:
parent
f0f2533e3e
commit
c815d90811
@ -72,7 +72,7 @@ public class StarredChanges implements
|
||||
user.asyncStarredChanges();
|
||||
|
||||
ChangeResource change = changes.parse(TopLevelResource.INSTANCE, id);
|
||||
if (user.getStarredChanges().contains(change.getChange().getId())) {
|
||||
if (user.getStarredChanges().contains(change.getId())) {
|
||||
return new AccountResource.StarredChange(user, change);
|
||||
}
|
||||
throw new ResourceNotFoundException(id);
|
||||
@ -141,7 +141,7 @@ public class StarredChanges implements
|
||||
dbProvider.get().starredChanges().insert(Collections.singleton(
|
||||
new StarredChange(new StarredChange.Key(
|
||||
rsrc.getUser().getAccountId(),
|
||||
change.getChange().getId()))));
|
||||
change.getId()))));
|
||||
} catch (OrmDuplicateKeyException e) {
|
||||
return Response.none();
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
return Integer.toString(change.getChange().getId().get());
|
||||
return Integer.toString(change.getId().get());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -177,7 +177,7 @@ public class ChangeEdits implements
|
||||
if (edit.isPresent()) {
|
||||
throw new ResourceConflictException(String.format(
|
||||
"edit already exists for the change %s",
|
||||
resource.getChange().getChangeId()));
|
||||
resource.getId()));
|
||||
}
|
||||
edit = createEdit();
|
||||
if (!Strings.isNullOrEmpty(path)) {
|
||||
|
@ -49,6 +49,10 @@ public class ChangeResource implements RestResource, HasETag {
|
||||
return control;
|
||||
}
|
||||
|
||||
public Change.Id getId() {
|
||||
return getControl().getId();
|
||||
}
|
||||
|
||||
public Change getChange() {
|
||||
return getControl().getChange();
|
||||
}
|
||||
@ -90,7 +94,7 @@ public class ChangeResource implements RestResource, HasETag {
|
||||
public String getETag() {
|
||||
CurrentUser user = control.getUser();
|
||||
Hasher h = Hashing.md5().newHasher()
|
||||
.putBoolean(user.getStarredChanges().contains(getChange().getId()));
|
||||
.putBoolean(user.getStarredChanges().contains(getId()));
|
||||
prepareETag(h, user);
|
||||
return h.hash().toString();
|
||||
}
|
||||
|
@ -85,8 +85,7 @@ public class DeleteDraftChange implements
|
||||
public UiAction.Description getDescription(ChangeResource rsrc) {
|
||||
try {
|
||||
return new UiAction.Description()
|
||||
.setTitle(String.format("Delete draft change %d",
|
||||
rsrc.getChange().getChangeId()))
|
||||
.setTitle("Delete draft change " + rsrc.getId())
|
||||
.setVisible(allowDrafts
|
||||
&& rsrc.getChange().getStatus() == Status.DRAFT
|
||||
&& rsrc.getControl().canDeleteDraft(dbProvider.get()));
|
||||
|
@ -75,7 +75,7 @@ public class DeleteReviewer implements RestModifyView<ReviewerResource, Input> {
|
||||
throws AuthException, ResourceNotFoundException, OrmException,
|
||||
IOException {
|
||||
ChangeControl control = rsrc.getControl();
|
||||
Change.Id changeId = rsrc.getChange().getId();
|
||||
Change.Id changeId = rsrc.getId();
|
||||
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.getChange().getId(), db);
|
||||
ChangeUtil.bumpRowVersionNotLastUpdatedOn(rsrc.getId(), db);
|
||||
db.patchSetApprovals().delete(del);
|
||||
update.removeReviewer(rsrc.getUser().getAccountId());
|
||||
|
||||
if (msg.length() > 0) {
|
||||
ChangeMessage changeMessage =
|
||||
new ChangeMessage(new ChangeMessage.Key(rsrc.getChange().getId(),
|
||||
new ChangeMessage(new ChangeMessage.Key(rsrc.getId(),
|
||||
ChangeUtil.messageUUID(db)),
|
||||
control.getUser().getAccountId(),
|
||||
TimeUtil.nowTs(), rsrc.getChange().currentPatchSetId());
|
||||
|
@ -237,8 +237,7 @@ public class PatchSetInserter extends BatchUpdate.Op {
|
||||
|
||||
if (message != null) {
|
||||
changeMessage = new ChangeMessage(
|
||||
new ChangeMessage.Key(
|
||||
ctl.getChange().getId(), ChangeUtil.messageUUID(db)),
|
||||
new ChangeMessage.Key(ctl.getId(), ChangeUtil.messageUUID(db)),
|
||||
ctx.getUser().getAccountId(), ctx.getWhen(), patchSet.getId());
|
||||
changeMessage.setMessage(message);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class PostHashtags
|
||||
req.getChange().getProject(), req.getControl().getUser(),
|
||||
TimeUtil.nowTs())) {
|
||||
SetHashtagsOp op = hashtagsFactory.create(input);
|
||||
bu.addOp(req.getChange().getId(), op);
|
||||
bu.addOp(req.getId(), op);
|
||||
bu.execute();
|
||||
return Response.<ImmutableSortedSet<String>> ok(op.getUpdatedHashtags());
|
||||
}
|
||||
|
@ -230,9 +230,9 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
||||
ReviewDb db = dbProvider.get();
|
||||
ChangeUpdate update = updateFactory.create(rsrc.getControl());
|
||||
List<PatchSetApproval> added;
|
||||
db.changes().beginTransaction(rsrc.getChange().getId());
|
||||
db.changes().beginTransaction(rsrc.getId());
|
||||
try {
|
||||
ChangeUtil.bumpRowVersionNotLastUpdatedOn(rsrc.getChange().getId(), db);
|
||||
ChangeUtil.bumpRowVersionNotLastUpdatedOn(rsrc.getId(), db);
|
||||
added = approvalsUtil.addReviewers(db, rsrc.getNotes(), update,
|
||||
rsrc.getControl().getLabelTypes(), rsrc.getChange(),
|
||||
reviewers.keySet());
|
||||
@ -243,7 +243,7 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
|
||||
|
||||
update.commit();
|
||||
CheckedFuture<?, IOException> indexFuture =
|
||||
indexer.indexAsync(rsrc.getChange().getId());
|
||||
indexer.indexAsync(rsrc.getId());
|
||||
result.reviewers = Lists.newArrayListWithCapacity(added.size());
|
||||
for (PatchSetApproval psa : added) {
|
||||
// New reviewers have value 0, don't bother normalizing.
|
||||
|
@ -77,7 +77,7 @@ public class PutTopic implements RestModifyView<ChangeResource, Input>,
|
||||
Op op = new Op(ctl, input != null ? input : new Input());
|
||||
try (BatchUpdate u = batchUpdateFactory.create(dbProvider.get(),
|
||||
req.getChange().getProject(), ctl.getUser(), TimeUtil.nowTs())) {
|
||||
u.addOp(req.getChange().getId(), op);
|
||||
u.addOp(req.getId(), op);
|
||||
u.execute();
|
||||
}
|
||||
return Strings.isNullOrEmpty(op.newTopicName)
|
||||
|
@ -87,7 +87,7 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
|
||||
Op op = new Op(input);
|
||||
try (BatchUpdate u = batchUpdateFactory.create(dbProvider.get(),
|
||||
req.getChange().getProject(), ctl.getUser(), TimeUtil.nowTs())) {
|
||||
u.addOp(req.getChange().getId(), op).execute();
|
||||
u.addOp(req.getId(), op).execute();
|
||||
}
|
||||
return json.create(ChangeJson.NO_OPTIONS).format(op.change);
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
||||
// Chance of collision rises; look at all patch sets on the change.
|
||||
List<RevisionResource> out = Lists.newArrayList();
|
||||
for (PatchSet ps : dbProvider.get().patchSets()
|
||||
.byChange(change.getChange().getId())) {
|
||||
.byChange(change.getId())) {
|
||||
if (ps.getRevision() != null && ps.getRevision().get().startsWith(id)) {
|
||||
out.add(new RevisionResource(change, ps));
|
||||
}
|
||||
@ -141,7 +141,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
||||
private List<RevisionResource> byLegacyPatchSetId(ChangeResource change,
|
||||
String id) throws OrmException {
|
||||
PatchSet ps = dbProvider.get().patchSets().get(new PatchSet.Id(
|
||||
change.getChange().getId(),
|
||||
change.getId(),
|
||||
Integer.parseInt(id)));
|
||||
if (ps != null) {
|
||||
return Collections.singletonList(new RevisionResource(change, ps));
|
||||
@ -161,8 +161,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
||||
throws AuthException, IOException {
|
||||
Optional<ChangeEdit> edit = editUtil.byChange(change.getChange());
|
||||
if (edit.isPresent()) {
|
||||
PatchSet ps = new PatchSet(new PatchSet.Id(
|
||||
change.getChange().getId(), 0));
|
||||
PatchSet ps = new PatchSet(new PatchSet.Id(change.getId(), 0));
|
||||
ps.setRevision(edit.get().getRevision());
|
||||
if (revid == null || edit.get().getRevision().equals(revid)) {
|
||||
return Collections.singletonList(
|
||||
@ -174,7 +173,7 @@ public class Revisions implements ChildCollection<ChangeResource, RevisionResour
|
||||
|
||||
private static List<RevisionResource> toResources(final ChangeResource change,
|
||||
Iterable<PatchSet> patchSets) {
|
||||
final Change.Id changeId = change.getChange().getId();
|
||||
final Change.Id changeId = change.getId();
|
||||
return FluentIterable.from(patchSets)
|
||||
.filter(new Predicate<PatchSet>() {
|
||||
@Override
|
||||
|
@ -116,7 +116,7 @@ public class LabelNormalizer {
|
||||
LabelTypes labelTypes = ctl.getLabelTypes();
|
||||
for (PatchSetApproval psa : approvals) {
|
||||
Change.Id changeId = psa.getKey().getParentKey().getParentKey();
|
||||
checkArgument(changeId.equals(ctl.getChange().getId()),
|
||||
checkArgument(changeId.equals(ctl.getId()),
|
||||
"Approval %s does not match change %s",
|
||||
psa.getKey(), ctl.getChange().getKey());
|
||||
if (psa.isSubmit()) {
|
||||
|
@ -86,8 +86,7 @@ public abstract class AbstractChangeUpdate extends VersionedMetaData {
|
||||
}
|
||||
|
||||
public void setPatchSetId(PatchSet.Id psId) {
|
||||
checkArgument(psId == null
|
||||
|| psId.getParentKey().equals(getChange().getId()));
|
||||
checkArgument(psId == null || psId.getParentKey().equals(ctl.getId()));
|
||||
this.psId = psId;
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
|
||||
IdentifiedUser user = ctl.getUser().asIdentifiedUser();
|
||||
this.accountId = user.getAccountId();
|
||||
this.changeNotes = getChangeNotes().load();
|
||||
this.draftNotes = draftNotesFactory.create(ctl.getChange().getId(),
|
||||
this.draftNotes = draftNotesFactory.create(ctl.getId(),
|
||||
user.getAccountId());
|
||||
|
||||
this.upsertComments = Lists.newArrayList();
|
||||
@ -273,7 +273,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
|
||||
|
||||
@Override
|
||||
protected String getRefName() {
|
||||
return RefNames.refsDraftComments(accountId, getChange().getId());
|
||||
return RefNames.refsDraftComments(accountId, ctl.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -387,7 +387,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
|
||||
|
||||
@Override
|
||||
protected String getRefName() {
|
||||
return ChangeNoteUtil.changeRefName(getChange().getId());
|
||||
return ChangeNoteUtil.changeRefName(ctl.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,7 +90,7 @@ public class ChangeControl {
|
||||
throws NoSuchChangeException, OrmException {
|
||||
ChangeControl c = controlFor(change, user);
|
||||
if (!c.isVisible(db.get())) {
|
||||
throw new NoSuchChangeException(c.getChange().getId());
|
||||
throw new NoSuchChangeException(c.getId());
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@ -153,6 +153,10 @@ public class ChangeControl {
|
||||
return getProjectControl().getProject();
|
||||
}
|
||||
|
||||
public Change.Id getId() {
|
||||
return notes.getChangeId();
|
||||
}
|
||||
|
||||
public Change getChange() {
|
||||
return notes.getChange();
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public class ChangeData {
|
||||
this.patchListCache = patchListCache;
|
||||
this.notesMigration = notesMigration;
|
||||
this.mergeabilityCache = mergeabilityCache;
|
||||
legacyId = c.getChange().getId();
|
||||
legacyId = c.getId();
|
||||
change = c.getChange();
|
||||
changeControl = c;
|
||||
notes = c.getNotes();
|
||||
|
@ -108,6 +108,7 @@ public class TestChanges {
|
||||
ChangeNotes notes = new ChangeNotes(repoManager, migration, allUsers, c)
|
||||
.load();
|
||||
expect(ctl.getNotes()).andStubReturn(notes);
|
||||
expect(ctl.getId()).andStubReturn(c.getId());
|
||||
EasyMock.replay(ctl);
|
||||
return ctl;
|
||||
}
|
||||
|
@ -107,9 +107,8 @@ public class SetReviewersCommand extends SshCommand {
|
||||
ok &= modifyOne(rsrc);
|
||||
} catch (Exception err) {
|
||||
ok = false;
|
||||
Change.Id changeId = rsrc.getChange().getId();
|
||||
log.error("Error updating reviewers on change " + changeId, err);
|
||||
writeError("fatal", "internal error while updating " + changeId);
|
||||
log.error("Error updating reviewers on change " + rsrc.getId(), err);
|
||||
writeError("fatal", "internal error while updating " + rsrc.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,7 +179,7 @@ public class SetReviewersCommand extends SshCommand {
|
||||
|
||||
case 1:
|
||||
ChangeControl ctl = toAdd.get(0);
|
||||
changes.put(ctl.getChange().getId(), changesCollection.parse(ctl));
|
||||
changes.put(ctl.getId(), changesCollection.parse(ctl));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user