ChangeEvent: Add 'who' and 'when' fields and methods

The 'when' field tells when the event occurred, and 'who' tells which
account performed the action that triggered the event.

Deprecate the existing events' get..() methods in favor of getWho().

Change-Id: I3fdae6c5b76eda8494bf3b5c95ea6bb077690d04
This commit is contained in:
David Pursehouse
2016-07-12 12:05:41 +09:00
parent 7923a93f5b
commit ed3cba635e
37 changed files with 178 additions and 99 deletions

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
@ExtensionPoint @ExtensionPoint
public interface ChangeAbandonedListener { public interface ChangeAbandonedListener {
interface Event extends RevisionEvent { interface Event extends RevisionEvent {
@Deprecated
AccountInfo getAbandoner(); AccountInfo getAbandoner();
String getReason(); String getReason();
} }

View File

@@ -14,10 +14,14 @@
package com.google.gerrit.extensions.events; package com.google.gerrit.extensions.events;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
import java.sql.Timestamp;
/** Interface to be extended by Events with a Change. */ /** Interface to be extended by Events with a Change. */
public interface ChangeEvent extends GerritEvent { public interface ChangeEvent extends GerritEvent {
ChangeInfo getChange(); ChangeInfo getChange();
AccountInfo getWho();
Timestamp getWhen();
} }

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
@ExtensionPoint @ExtensionPoint
public interface ChangeMergedListener { public interface ChangeMergedListener {
interface Event extends RevisionEvent { interface Event extends RevisionEvent {
@Deprecated
AccountInfo getMerger(); AccountInfo getMerger();
/** /**
* Represents the merged Revision when the submit strategy is cherry-pick or * Represents the merged Revision when the submit strategy is cherry-pick or

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
@ExtensionPoint @ExtensionPoint
public interface ChangeRestoredListener { public interface ChangeRestoredListener {
interface Event extends RevisionEvent { interface Event extends RevisionEvent {
@Deprecated
AccountInfo getRestorer(); AccountInfo getRestorer();
String getReason(); String getReason();
} }

View File

@@ -24,6 +24,7 @@ import java.util.Map;
@ExtensionPoint @ExtensionPoint
public interface CommentAddedListener { public interface CommentAddedListener {
interface Event extends RevisionEvent { interface Event extends RevisionEvent {
@Deprecated
AccountInfo getAuthor(); AccountInfo getAuthor();
String getComment(); String getComment();
Map<String, ApprovalInfo> getApprovals(); Map<String, ApprovalInfo> getApprovals();

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
@ExtensionPoint @ExtensionPoint
public interface DraftPublishedListener { public interface DraftPublishedListener {
interface Event extends RevisionEvent { interface Event extends RevisionEvent {
@Deprecated
AccountInfo getPublisher(); AccountInfo getPublisher();
} }

View File

@@ -23,6 +23,7 @@ import java.util.Collection;
@ExtensionPoint @ExtensionPoint
public interface HashtagsEditedListener { public interface HashtagsEditedListener {
interface Event extends ChangeEvent { interface Event extends ChangeEvent {
@Deprecated
AccountInfo getEditor(); AccountInfo getEditor();
Collection<String> getHashtags(); Collection<String> getHashtags();
Collection<String> getAddedHashtags(); Collection<String> getAddedHashtags();

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
@ExtensionPoint @ExtensionPoint
public interface RevisionCreatedListener { public interface RevisionCreatedListener {
interface Event extends RevisionEvent { interface Event extends RevisionEvent {
@Deprecated
AccountInfo getUploader(); AccountInfo getUploader();
} }

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.extensions.common.AccountInfo;
@ExtensionPoint @ExtensionPoint
public interface TopicEditedListener { public interface TopicEditedListener {
interface Event extends ChangeEvent { interface Event extends ChangeEvent {
@Deprecated
AccountInfo getEditor(); AccountInfo getEditor();
String getOldTopic(); String getOldTopic();
} }

View File

@@ -171,7 +171,7 @@ public class Abandon implements RestModifyView<ChangeResource, AbandonInput>,
} catch (Exception e) { } catch (Exception e) {
log.error("Cannot email update for change " + change.getId(), e); log.error("Cannot email update for change " + change.getId(), e);
} }
changeAbandoned.fire(change, patchSet, account, msgTxt); changeAbandoned.fire(change, patchSet, account, msgTxt, ctx.getWhen());
} }
} }

View File

@@ -401,7 +401,8 @@ public class ChangeInserter extends BatchUpdate.InsertChangeOp {
* show a transition from an oldValue of 0 to the new value. * show a transition from an oldValue of 0 to the new value.
*/ */
if (fireRevisionCreated) { if (fireRevisionCreated) {
revisionCreated.fire(change, patchSet, ctx.getUser().getAccountId()); revisionCreated.fire(change, patchSet, ctx.getUser().getAccountId(),
ctx.getWhen());
if (approvals != null && !approvals.isEmpty()) { if (approvals != null && !approvals.isEmpty()) {
ChangeControl changeControl = changeControlFactory.controlFor( ChangeControl changeControl = changeControlFactory.controlFor(
ctx.getDb(), change, ctx.getUser()); ctx.getDb(), change, ctx.getUser());

View File

@@ -199,6 +199,7 @@ public class DeleteReviewer implements RestModifyView<ReviewerResource, Input> {
emailReviewers(ctx.getProject(), currChange, del, changeMessage); emailReviewers(ctx.getProject(), currChange, del, changeMessage);
reviewerDeleted.fire(currChange, currPs, reviewer, reviewerDeleted.fire(currChange, currPs, reviewer,
ctx.getUser().asIdentifiedUser().getAccount(),
changeMessage.getMessage(), changeMessage.getMessage(),
newApprovals, oldApprovals, newApprovals, oldApprovals,
ctx.getWhen()); ctx.getWhen());

View File

@@ -274,7 +274,8 @@ public class PatchSetInserter extends BatchUpdate.Op {
} }
if (fireRevisionCreated) { if (fireRevisionCreated) {
revisionCreated.fire(change, patchSet, ctx.getUser().getAccountId()); revisionCreated.fire(change, patchSet, ctx.getUser().getAccountId(),
ctx.getWhen());
} }
} }

View File

@@ -289,7 +289,9 @@ public class PostReviewers implements RestModifyView<ChangeResource, AddReviewer
if (!added.isEmpty()) { if (!added.isEmpty()) {
for (PatchSetApproval psa : added) { for (PatchSetApproval psa : added) {
Account account = accountCache.get(psa.getAccountId()).getAccount(); Account account = accountCache.get(psa.getAccountId()).getAccount();
reviewerAdded.fire(rsrc.getChange(), patchSet, account); reviewerAdded.fire(rsrc.getChange(), patchSet, account,
ctx.getUser().asIdentifiedUser().getAccount(),
ctx.getWhen());
} }
} }
} }

View File

@@ -223,7 +223,8 @@ public class PublishDraftPatchSet implements RestModifyView<RevisionResource, In
@Override @Override
public void postUpdate(Context ctx) throws OrmException { public void postUpdate(Context ctx) throws OrmException {
draftPublished.fire(change, patchSet, ctx.getUser().getAccountId()); draftPublished.fire(change, patchSet, ctx.getUser().getAccountId(),
ctx.getWhen());
if (patchSet.isDraft() && change.getStatus() == Change.Status.DRAFT) { if (patchSet.isDraft() && change.getStatus() == Change.Status.DRAFT) {
// Skip emails if the patch set is still a draft. // Skip emails if the patch set is still a draft.
return; return;

View File

@@ -131,7 +131,8 @@ public class PutTopic implements RestModifyView<ChangeResource, Input>,
if (change != null) { if (change != null) {
topicEdited.fire(change, topicEdited.fire(change,
ctx.getUser().asIdentifiedUser().getAccount(), ctx.getUser().asIdentifiedUser().getAccount(),
oldTopicName); oldTopicName,
ctx.getWhen());
} }
} }
} }

View File

@@ -156,7 +156,8 @@ public class Restore implements RestModifyView<ChangeResource, RestoreInput>,
} }
changeRestored.fire(change, patchSet, changeRestored.fire(change, patchSet,
ctx.getUser().asIdentifiedUser().getAccount(), ctx.getUser().asIdentifiedUser().getAccount(),
Strings.emptyToNull(input.message)); Strings.emptyToNull(input.message),
ctx.getWhen());
} }
} }

View File

@@ -240,7 +240,7 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
@Override @Override
public void postUpdate(Context ctx) throws Exception { public void postUpdate(Context ctx) throws Exception {
changeReverted.fire(change, ins.getChange()); changeReverted.fire(change, ins.getChange(), ctx.getWhen());
Change.Id changeId = ins.getChange().getId(); Change.Id changeId = ins.getChange().getId();
try { try {
RevertedSender cm = RevertedSender cm =

View File

@@ -167,7 +167,7 @@ public class SetHashtagsOp extends BatchUpdate.Op {
public void postUpdate(Context ctx) throws OrmException { public void postUpdate(Context ctx) throws OrmException {
if (updated() && fireEvent) { if (updated() && fireEvent) {
hashtagsEdited.fire(change, ctx.getUser().getAccountId(), updatedHashtags, hashtagsEdited.fire(change, ctx.getUser().getAccountId(), updatedHashtags,
toAdd, toRemove); toAdd, toRemove, ctx.getWhen());
} }
} }

View File

@@ -272,7 +272,7 @@ public class StreamEventsApiListener implements
TopicChangedEvent event = new TopicChangedEvent(change); TopicChangedEvent event = new TopicChangedEvent(change);
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.changer = accountAttributeSupplier(ev.getEditor()); event.changer = accountAttributeSupplier(ev.getWho());
event.oldTopic = ev.getOldTopic(); event.oldTopic = ev.getOldTopic();
dispatcher.get().postEvent(change, event); dispatcher.get().postEvent(change, event);
@@ -291,7 +291,7 @@ public class StreamEventsApiListener implements
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.patchSet = patchSetAttributeSupplier(change, patchSet); event.patchSet = patchSetAttributeSupplier(change, patchSet);
event.uploader = accountAttributeSupplier(ev.getUploader()); event.uploader = accountAttributeSupplier(ev.getWho());
dispatcher.get().postEvent(change, event); dispatcher.get().postEvent(change, event);
} catch (OrmException e) { } catch (OrmException e) {
@@ -354,7 +354,7 @@ public class StreamEventsApiListener implements
HashtagsChangedEvent event = new HashtagsChangedEvent(change); HashtagsChangedEvent event = new HashtagsChangedEvent(change);
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.editor = accountAttributeSupplier(ev.getEditor()); event.editor = accountAttributeSupplier(ev.getWho());
event.hashtags = hashtagArray(ev.getHashtags()); event.hashtags = hashtagArray(ev.getHashtags());
event.added = hashtagArray(ev.getAddedHashtags()); event.added = hashtagArray(ev.getAddedHashtags());
event.removed = hashtagArray(ev.getRemovedHashtags()); event.removed = hashtagArray(ev.getRemovedHashtags());
@@ -396,7 +396,7 @@ public class StreamEventsApiListener implements
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.patchSet = patchSetAttributeSupplier(change, ps); event.patchSet = patchSetAttributeSupplier(change, ps);
event.uploader = accountAttributeSupplier(ev.getPublisher()); event.uploader = accountAttributeSupplier(ev.getWho());
dispatcher.get().postEvent(change, event); dispatcher.get().postEvent(change, event);
} catch (OrmException e) { } catch (OrmException e) {
@@ -413,7 +413,7 @@ public class StreamEventsApiListener implements
CommentAddedEvent event = new CommentAddedEvent(change); CommentAddedEvent event = new CommentAddedEvent(change);
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.author = accountAttributeSupplier(ev.getAuthor()); event.author = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, ps); event.patchSet = patchSetAttributeSupplier(change, ps);
event.comment = ev.getComment(); event.comment = ev.getComment();
event.approvals = approvalsAttributeSupplier( event.approvals = approvalsAttributeSupplier(
@@ -433,7 +433,7 @@ public class StreamEventsApiListener implements
ChangeRestoredEvent event = new ChangeRestoredEvent(change); ChangeRestoredEvent event = new ChangeRestoredEvent(change);
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.restorer = accountAttributeSupplier(ev.getRestorer()); event.restorer = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, event.patchSet = patchSetAttributeSupplier(change,
psUtil.current(db.get(), notes)); psUtil.current(db.get(), notes));
event.reason = ev.getReason(); event.reason = ev.getReason();
@@ -452,7 +452,7 @@ public class StreamEventsApiListener implements
ChangeMergedEvent event = new ChangeMergedEvent(change); ChangeMergedEvent event = new ChangeMergedEvent(change);
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.submitter = accountAttributeSupplier(ev.getMerger()); event.submitter = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, event.patchSet = patchSetAttributeSupplier(change,
psUtil.current(db.get(), notes)); psUtil.current(db.get(), notes));
event.newRev = ev.getNewRevisionId(); event.newRev = ev.getNewRevisionId();
@@ -471,7 +471,7 @@ public class StreamEventsApiListener implements
ChangeAbandonedEvent event = new ChangeAbandonedEvent(change); ChangeAbandonedEvent event = new ChangeAbandonedEvent(change);
event.change = changeAttributeSupplier(change); event.change = changeAttributeSupplier(change);
event.abandoner = accountAttributeSupplier(ev.getAbandoner()); event.abandoner = accountAttributeSupplier(ev.getWho());
event.patchSet = patchSetAttributeSupplier(change, event.patchSet = patchSetAttributeSupplier(change,
psUtil.current(db.get(), notes)); psUtil.current(db.get(), notes));
event.reason = ev.getReason(); event.reason = ev.getReason();

View File

@@ -14,18 +14,36 @@
package com.google.gerrit.server.extensions.events; package com.google.gerrit.server.extensions.events;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.events.ChangeEvent; import com.google.gerrit.extensions.events.ChangeEvent;
import java.sql.Timestamp;
public abstract class AbstractChangeEvent implements ChangeEvent { public abstract class AbstractChangeEvent implements ChangeEvent {
private final ChangeInfo changeInfo; private final ChangeInfo changeInfo;
private final AccountInfo who;
private final Timestamp when;
protected AbstractChangeEvent(ChangeInfo change) { protected AbstractChangeEvent(ChangeInfo change, AccountInfo who,
Timestamp when) {
this.changeInfo = change; this.changeInfo = change;
this.who = who;
this.when = when;
} }
@Override @Override
public ChangeInfo getChange() { public ChangeInfo getChange() {
return changeInfo; return changeInfo;
} }
@Override
public AccountInfo getWho() {
return who;
}
@Override
public Timestamp getWhen() {
return when;
}
} }

View File

@@ -14,17 +14,21 @@
package com.google.gerrit.server.extensions.events; package com.google.gerrit.server.extensions.events;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.RevisionInfo; import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.events.RevisionEvent; import com.google.gerrit.extensions.events.RevisionEvent;
import java.sql.Timestamp;
public abstract class AbstractRevisionEvent extends AbstractChangeEvent public abstract class AbstractRevisionEvent extends AbstractChangeEvent
implements RevisionEvent { implements RevisionEvent {
private final RevisionInfo revisionInfo; private final RevisionInfo revisionInfo;
protected AbstractRevisionEvent(ChangeInfo change, RevisionInfo revision) { protected AbstractRevisionEvent(ChangeInfo change, RevisionInfo revision,
super(change); AccountInfo who, Timestamp when) {
super(change, who, when);
revisionInfo = revision; revisionInfo = revision;
} }

View File

@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp;
public class ChangeAbandoned { public class ChangeAbandoned {
private static final Logger log = private static final Logger log =
@@ -47,11 +48,11 @@ public class ChangeAbandoned {
} }
public void fire(ChangeInfo change, RevisionInfo revision, public void fire(ChangeInfo change, RevisionInfo revision,
AccountInfo abandoner, String reason) { AccountInfo abandoner, String reason, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revision, abandoner, reason); Event event = new Event(change, revision, abandoner, reason, when);
for (ChangeAbandonedListener l : listeners) { for (ChangeAbandonedListener l : listeners) {
try { try {
l.onChangeAbandoned(event); l.onChangeAbandoned(event);
@@ -61,7 +62,8 @@ public class ChangeAbandoned {
} }
} }
public void fire(Change change, PatchSet ps, Account abandoner, String reason) { public void fire(Change change, PatchSet ps, Account abandoner, String reason,
Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
@@ -69,7 +71,7 @@ public class ChangeAbandoned {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.revisionInfo(change.getProject(), ps), util.revisionInfo(change.getProject(), ps),
util.accountInfo(abandoner), util.accountInfo(abandoner),
reason); reason, when);
} catch (PatchListNotAvailableException | GpgException | IOException } catch (PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -82,8 +84,8 @@ public class ChangeAbandoned {
private final String reason; private final String reason;
Event(ChangeInfo change, RevisionInfo revision, AccountInfo abandoner, Event(ChangeInfo change, RevisionInfo revision, AccountInfo abandoner,
String reason) { String reason, Timestamp when) {
super(change, revision); super(change, revision, abandoner, when);
this.abandoner = abandoner; this.abandoner = abandoner;
this.reason = reason; this.reason = reason;
} }

View File

@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp;
public class ChangeMerged { public class ChangeMerged {
private static final Logger log = private static final Logger log =
@@ -47,11 +48,11 @@ public class ChangeMerged {
} }
public void fire(ChangeInfo change, RevisionInfo revision, public void fire(ChangeInfo change, RevisionInfo revision,
AccountInfo merger, String newRevisionId) { AccountInfo merger, String newRevisionId, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revision, merger, newRevisionId); Event event = new Event(change, revision, merger, newRevisionId, when);
for (ChangeMergedListener l : listeners) { for (ChangeMergedListener l : listeners) {
try { try {
l.onChangeMerged(event); l.onChangeMerged(event);
@@ -62,7 +63,7 @@ public class ChangeMerged {
} }
public void fire(Change change, PatchSet ps, Account merger, public void fire(Change change, PatchSet ps, Account merger,
String newRevisionId) { String newRevisionId, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
@@ -70,7 +71,7 @@ public class ChangeMerged {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.revisionInfo(change.getProject(), ps), util.revisionInfo(change.getProject(), ps),
util.accountInfo(merger), util.accountInfo(merger),
newRevisionId); newRevisionId, when);
} catch (PatchListNotAvailableException | GpgException | IOException } catch (PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -83,8 +84,8 @@ public class ChangeMerged {
private final String newRevisionId; private final String newRevisionId;
Event(ChangeInfo change, RevisionInfo revision, AccountInfo merger, Event(ChangeInfo change, RevisionInfo revision, AccountInfo merger,
String newRevisionId) { String newRevisionId, Timestamp when) {
super(change, revision); super(change, revision, merger, when);
this.merger = merger; this.merger = merger;
this.newRevisionId = newRevisionId; this.newRevisionId = newRevisionId;
} }

View File

@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp;
public class ChangeRestored { public class ChangeRestored {
private static final Logger log = private static final Logger log =
@@ -47,11 +48,11 @@ public class ChangeRestored {
} }
public void fire(ChangeInfo change, RevisionInfo revision, public void fire(ChangeInfo change, RevisionInfo revision,
AccountInfo restorer, String reason) { AccountInfo restorer, String reason, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revision, restorer, reason); Event event = new Event(change, revision, restorer, reason, when);
for (ChangeRestoredListener l : listeners) { for (ChangeRestoredListener l : listeners) {
try { try {
l.onChangeRestored(event); l.onChangeRestored(event);
@@ -61,7 +62,8 @@ public class ChangeRestored {
} }
} }
public void fire(Change change, PatchSet ps, Account restorer, String reason) { public void fire(Change change, PatchSet ps, Account restorer, String reason,
Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
@@ -69,7 +71,7 @@ public class ChangeRestored {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.revisionInfo(change.getProject(), ps), util.revisionInfo(change.getProject(), ps),
util.accountInfo(restorer), util.accountInfo(restorer),
reason); reason, when);
} catch (PatchListNotAvailableException | GpgException | IOException } catch (PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -83,8 +85,8 @@ public class ChangeRestored {
private String reason; private String reason;
Event(ChangeInfo change, RevisionInfo revision, AccountInfo restorer, Event(ChangeInfo change, RevisionInfo revision, AccountInfo restorer,
String reason) { String reason, Timestamp when) {
super(change, revision); super(change, revision, restorer, when);
this.restorer = restorer; this.restorer = restorer;
this.reason = reason; this.reason = reason;
} }

View File

@@ -24,6 +24,8 @@ import com.google.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
public class ChangeReverted { public class ChangeReverted {
private static final Logger log = private static final Logger log =
LoggerFactory.getLogger(ChangeReverted.class); LoggerFactory.getLogger(ChangeReverted.class);
@@ -38,22 +40,23 @@ public class ChangeReverted {
this.util = util; this.util = util;
} }
public void fire(Change change, Change revertChange) { public void fire(Change change, Change revertChange, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
try { try {
fire(util.changeInfo(change), util.changeInfo(revertChange)); fire(util.changeInfo(change), util.changeInfo(revertChange), when);
} catch (OrmException e) { } catch (OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
} }
} }
public void fire (ChangeInfo change, ChangeInfo revertChange) { public void fire (ChangeInfo change, ChangeInfo revertChange,
Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revertChange); Event event = new Event(change, revertChange, when);
for (ChangeRevertedListener l : listeners) { for (ChangeRevertedListener l : listeners) {
try { try {
l.onChangeReverted(event); l.onChangeReverted(event);
@@ -67,8 +70,8 @@ public class ChangeReverted {
implements ChangeRevertedListener.Event { implements ChangeRevertedListener.Event {
private final ChangeInfo revertChange; private final ChangeInfo revertChange;
Event(ChangeInfo change, ChangeInfo revertChange) { Event(ChangeInfo change, ChangeInfo revertChange, Timestamp when) {
super(change); super(change, revertChange.owner, when);
this.revertChange = revertChange; this.revertChange = revertChange;
} }

View File

@@ -51,12 +51,12 @@ public class CommentAdded {
public void fire(ChangeInfo change, RevisionInfo revision, AccountInfo author, public void fire(ChangeInfo change, RevisionInfo revision, AccountInfo author,
String comment, Map<String, ApprovalInfo> approvals, String comment, Map<String, ApprovalInfo> approvals,
Map<String, ApprovalInfo> oldApprovals) { Map<String, ApprovalInfo> oldApprovals, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event( Event event = new Event(
change, revision, author, comment, approvals, oldApprovals); change, revision, author, comment, approvals, oldApprovals, when);
for (CommentAddedListener l : listeners) { for (CommentAddedListener l : listeners) {
try { try {
l.onCommentAdded(event); l.onCommentAdded(event);
@@ -68,7 +68,7 @@ public class CommentAdded {
public void fire(Change change, PatchSet ps, Account author, public void fire(Change change, PatchSet ps, Account author,
String comment, Map<String, Short> approvals, String comment, Map<String, Short> approvals,
Map<String, Short> oldApprovals, Timestamp ts) { Map<String, Short> oldApprovals, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
@@ -77,8 +77,9 @@ public class CommentAdded {
util.revisionInfo(change.getProject(), ps), util.revisionInfo(change.getProject(), ps),
util.accountInfo(author), util.accountInfo(author),
comment, comment,
util.approvals(author, approvals, ts), util.approvals(author, approvals, when),
util.approvals(author, oldApprovals, ts)); util.approvals(author, oldApprovals, when),
when);
} catch (PatchListNotAvailableException | GpgException | IOException } catch (PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -95,8 +96,8 @@ public class CommentAdded {
Event(ChangeInfo change, RevisionInfo revision, AccountInfo author, Event(ChangeInfo change, RevisionInfo revision, AccountInfo author,
String comment, Map<String, ApprovalInfo> approvals, String comment, Map<String, ApprovalInfo> approvals,
Map<String, ApprovalInfo> oldApprovals) { Map<String, ApprovalInfo> oldApprovals, Timestamp when) {
super(change, revision); super(change, revision, author, when);
this.author = author; this.author = author;
this.comment = comment; this.comment = comment;
this.approvals = approvals; this.approvals = approvals;

View File

@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp;
public class DraftPublished { public class DraftPublished {
private static final Logger log = private static final Logger log =
@@ -47,11 +48,11 @@ public class DraftPublished {
} }
public void fire(ChangeInfo change, RevisionInfo revision, public void fire(ChangeInfo change, RevisionInfo revision,
AccountInfo publisher) { AccountInfo publisher, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revision, publisher); Event event = new Event(change, revision, publisher, when);
for (DraftPublishedListener l : listeners) { for (DraftPublishedListener l : listeners) {
try { try {
l.onDraftPublished(event); l.onDraftPublished(event);
@@ -61,11 +62,13 @@ public class DraftPublished {
} }
} }
public void fire(Change change, PatchSet patchSet, Account.Id accountId) { public void fire(Change change, PatchSet patchSet, Account.Id accountId,
Timestamp when) {
try { try {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.revisionInfo(change.getProject(), patchSet), util.revisionInfo(change.getProject(), patchSet),
util.accountInfo(accountId)); util.accountInfo(accountId),
when);
} catch (PatchListNotAvailableException | GpgException | IOException } catch (PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -76,8 +79,9 @@ public class DraftPublished {
implements DraftPublishedListener.Event { implements DraftPublishedListener.Event {
private final AccountInfo publisher; private final AccountInfo publisher;
Event(ChangeInfo change, RevisionInfo revision, AccountInfo publisher) { Event(ChangeInfo change, RevisionInfo revision, AccountInfo publisher,
super(change, revision); Timestamp when) {
super(change, revision, publisher, when);
this.publisher = publisher; this.publisher = publisher;
} }

View File

@@ -27,6 +27,7 @@ import com.google.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
import java.util.Collection; import java.util.Collection;
import java.util.Set; import java.util.Set;
@@ -44,12 +45,13 @@ public class HashtagsEdited {
this.util = util; this.util = util;
} }
public void fire(ChangeInfo change, AccountInfo editor, Collection<String> hashtags, public void fire(ChangeInfo change, AccountInfo editor,
Collection<String> added, Collection<String> removed) { Collection<String> hashtags, Collection<String> added,
Collection<String> removed, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, editor, hashtags, added, removed); Event event = new Event(change, editor, hashtags, added, removed, when);
for (HashtagsEditedListener l : listeners) { for (HashtagsEditedListener l : listeners) {
try { try {
l.onHashtagsEdited(event); l.onHashtagsEdited(event);
@@ -60,15 +62,16 @@ public class HashtagsEdited {
} }
public void fire(Change change, Id accountId, public void fire(Change change, Id accountId,
ImmutableSortedSet<String> updatedHashtags, Set<String> toAdd, ImmutableSortedSet<String> hashtags, Set<String> added,
Set<String> toRemove) { Set<String> removed, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
try { try {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.accountInfo(accountId), util.accountInfo(accountId),
updatedHashtags, toAdd, toRemove); hashtags, added, removed,
when);
} catch (OrmException e) { } catch (OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
} }
@@ -83,8 +86,8 @@ public class HashtagsEdited {
private Collection<String> removedHashtags; private Collection<String> removedHashtags;
Event(ChangeInfo change, AccountInfo editor, Collection<String> updated, Event(ChangeInfo change, AccountInfo editor, Collection<String> updated,
Collection<String> added, Collection<String> removed) { Collection<String> added, Collection<String> removed, Timestamp when) {
super(change); super(change, editor, when);
this.editor = editor; this.editor = editor;
this.updatedHashtags = updated; this.updatedHashtags = updated;
this.addedHashtags = added; this.addedHashtags = added;

View File

@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp;
public class ReviewerAdded { public class ReviewerAdded {
private static final Logger log = private static final Logger log =
@@ -47,11 +48,11 @@ public class ReviewerAdded {
} }
public void fire(ChangeInfo change, RevisionInfo revision, public void fire(ChangeInfo change, RevisionInfo revision,
AccountInfo reviewer) { AccountInfo reviewer, AccountInfo adder, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revision, reviewer); Event event = new Event(change, revision, reviewer, adder, when);
for (ReviewerAddedListener l : listeners) { for (ReviewerAddedListener l : listeners) {
try { try {
l.onReviewerAdded(event); l.onReviewerAdded(event);
@@ -61,14 +62,17 @@ public class ReviewerAdded {
} }
} }
public void fire(Change change, PatchSet patchSet, Account account) { public void fire(Change change, PatchSet patchSet, Account account,
Account adder, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
try { try {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.revisionInfo(change.getProject(), patchSet), util.revisionInfo(change.getProject(), patchSet),
util.accountInfo(account)); util.accountInfo(account),
util.accountInfo(adder),
when);
} catch (PatchListNotAvailableException | GpgException | IOException } catch (PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -79,8 +83,9 @@ public class ReviewerAdded {
implements ReviewerAddedListener.Event { implements ReviewerAddedListener.Event {
private final AccountInfo reviewer; private final AccountInfo reviewer;
Event(ChangeInfo change, RevisionInfo revision, AccountInfo reviewer) { Event(ChangeInfo change, RevisionInfo revision, AccountInfo reviewer,
super(change, revision); AccountInfo adder, Timestamp when) {
super(change, revision, adder, when);
this.reviewer = reviewer; this.reviewer = reviewer;
} }

View File

@@ -50,14 +50,14 @@ public class ReviewerDeleted {
} }
public void fire(ChangeInfo change, RevisionInfo revision, public void fire(ChangeInfo change, RevisionInfo revision,
AccountInfo reviewer, String message, AccountInfo reviewer, AccountInfo remover, String message,
Map<String, ApprovalInfo> newApprovals, Map<String, ApprovalInfo> newApprovals,
Map<String, ApprovalInfo> oldApprovals) { Map<String, ApprovalInfo> oldApprovals, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revision, reviewer, message, Event event = new Event(change, revision, reviewer, remover, message,
newApprovals, oldApprovals); newApprovals, oldApprovals, when);
for (ReviewerDeletedListener listener : listeners) { for (ReviewerDeletedListener listener : listeners) {
try { try {
listener.onReviewerDeleted(event); listener.onReviewerDeleted(event);
@@ -68,9 +68,9 @@ public class ReviewerDeleted {
} }
public void fire(Change change, PatchSet patchSet, Account reviewer, public void fire(Change change, PatchSet patchSet, Account reviewer,
String message, Account remover, String message,
Map<String, Short> newApprovals, Map<String, Short> newApprovals,
Map<String, Short> oldApprovals, Timestamp ts) { Map<String, Short> oldApprovals, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
@@ -78,9 +78,11 @@ public class ReviewerDeleted {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.revisionInfo(change.getProject(), patchSet), util.revisionInfo(change.getProject(), patchSet),
util.accountInfo(reviewer), util.accountInfo(reviewer),
util.accountInfo(remover),
message, message,
util.approvals(reviewer, newApprovals, ts), util.approvals(reviewer, newApprovals, when),
util.approvals(reviewer, oldApprovals, ts)); util.approvals(reviewer, oldApprovals, when),
when);
} catch (PatchListNotAvailableException | GpgException | IOException } catch (PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -96,9 +98,10 @@ public class ReviewerDeleted {
private final Map<String, ApprovalInfo> oldApprovals; private final Map<String, ApprovalInfo> oldApprovals;
Event(ChangeInfo change, RevisionInfo revision, AccountInfo reviewer, Event(ChangeInfo change, RevisionInfo revision, AccountInfo reviewer,
String comment, Map<String, ApprovalInfo> newApprovals, AccountInfo remover, String comment,
Map<String, ApprovalInfo> oldApprovals) { Map<String, ApprovalInfo> newApprovals,
super(change, revision); Map<String, ApprovalInfo> oldApprovals, Timestamp when) {
super(change, revision, remover, when);
this.reviewer = reviewer; this.reviewer = reviewer;
this.comment = comment; this.comment = comment;
this.newApprovals = newApprovals; this.newApprovals = newApprovals;

View File

@@ -31,6 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp;
public class RevisionCreated { public class RevisionCreated {
private static final Logger log = private static final Logger log =
@@ -47,11 +48,11 @@ public class RevisionCreated {
} }
public void fire(ChangeInfo change, RevisionInfo revision, public void fire(ChangeInfo change, RevisionInfo revision,
AccountInfo uploader) { AccountInfo uploader, Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, revision, uploader); Event event = new Event(change, revision, uploader, when);
for (RevisionCreatedListener l : listeners) { for (RevisionCreatedListener l : listeners) {
try { try {
l.onRevisionCreated(event); l.onRevisionCreated(event);
@@ -61,14 +62,16 @@ public class RevisionCreated {
} }
} }
public void fire(Change change, PatchSet patchSet, Account.Id uploader) { public void fire(Change change, PatchSet patchSet, Account.Id uploader,
Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
try { try {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.revisionInfo(change.getProject(), patchSet), util.revisionInfo(change.getProject(), patchSet),
util.accountInfo(uploader)); util.accountInfo(uploader),
when);
} catch ( PatchListNotAvailableException | GpgException | IOException } catch ( PatchListNotAvailableException | GpgException | IOException
| OrmException e) { | OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
@@ -79,8 +82,9 @@ public class RevisionCreated {
implements RevisionCreatedListener.Event { implements RevisionCreatedListener.Event {
private final AccountInfo uploader; private final AccountInfo uploader;
Event(ChangeInfo change, RevisionInfo revision, AccountInfo uploader) { Event(ChangeInfo change, RevisionInfo revision, AccountInfo uploader,
super(change, revision); Timestamp when) {
super(change, revision, uploader, when);
this.uploader = uploader; this.uploader = uploader;
} }

View File

@@ -26,6 +26,8 @@ import com.google.inject.Inject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
public class TopicEdited { public class TopicEdited {
private static final Logger log = private static final Logger log =
LoggerFactory.getLogger(TopicEdited.class); LoggerFactory.getLogger(TopicEdited.class);
@@ -40,11 +42,12 @@ public class TopicEdited {
this.util = util; this.util = util;
} }
public void fire(ChangeInfo change, AccountInfo editor, String oldTopic) { public void fire(ChangeInfo change, AccountInfo editor, String oldTopic,
Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
Event event = new Event(change, editor, oldTopic); Event event = new Event(change, editor, oldTopic, when);
for (TopicEditedListener l : listeners) { for (TopicEditedListener l : listeners) {
try { try {
l.onTopicEdited(event); l.onTopicEdited(event);
@@ -54,14 +57,16 @@ public class TopicEdited {
} }
} }
public void fire(Change change, Account account, String oldTopicName) { public void fire(Change change, Account account, String oldTopicName,
Timestamp when) {
if (!listeners.iterator().hasNext()) { if (!listeners.iterator().hasNext()) {
return; return;
} }
try { try {
fire(util.changeInfo(change), fire(util.changeInfo(change),
util.accountInfo(account), util.accountInfo(account),
oldTopicName); oldTopicName,
when);
} catch (OrmException e) { } catch (OrmException e) {
log.error("Couldn't fire event", e); log.error("Couldn't fire event", e);
} }
@@ -72,8 +77,9 @@ public class TopicEdited {
private final AccountInfo editor; private final AccountInfo editor;
private final String oldTopic; private final String oldTopic;
Event(ChangeInfo change, AccountInfo editor, String oldTopic) { Event(ChangeInfo change, AccountInfo editor, String oldTopic,
super(change); Timestamp when) {
super(change, editor, when);
this.editor = editor; this.editor = editor;
this.oldTopic = oldTopic; this.oldTopic = oldTopic;
} }

View File

@@ -196,7 +196,8 @@ public class MergedByPushOp extends BatchUpdate.Op {
changeMerged.fire(change, patchSet, changeMerged.fire(change, patchSet,
ctx.getUser().asIdentifiedUser().getAccount(), ctx.getUser().asIdentifiedUser().getAccount(),
patchSet.getRevision().get()); patchSet.getRevision().get(),
ctx.getWhen());
} }
private PatchSetInfo getPatchSetInfo(ChangeContext ctx) throws IOException { private PatchSetInfo getPatchSetInfo(ChangeContext ctx) throws IOException {

View File

@@ -398,7 +398,8 @@ public class ReplaceOp extends BatchUpdate.Op {
} }
} }
revisionCreated.fire(change, newPatchSet, ctx.getUser().getAccountId()); revisionCreated.fire(change, newPatchSet, ctx.getUser().getAccountId(),
ctx.getWhen());
try { try {
fireCommentAddedEvent(ctx); fireCommentAddedEvent(ctx);
} catch (Exception e) { } catch (Exception e) {

View File

@@ -527,7 +527,8 @@ abstract class SubmitStrategyOp extends BatchUpdate.Op {
updatedChange, updatedChange,
mergedPatchSet, mergedPatchSet,
args.accountCache.get(submitter.getAccountId()).getAccount(), args.accountCache.get(submitter.getAccountId()).getAccount(),
args.mergeTip.getCurrentTip().name()); args.mergeTip.getCurrentTip().name(),
ctx.getWhen());
} }
} }