### Eclipse Workspace Patch 1.0 #P xwiki-core-observation-api Index: src/main/java/org/xwiki/observation/event/DocumentRollbackEvent.java =================================================================== --- src/main/java/org/xwiki/observation/event/DocumentRollbackEvent.java (revision 0) +++ src/main/java/org/xwiki/observation/event/DocumentRollbackEvent.java (revision 0) @@ -0,0 +1,86 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + * + */ +package org.xwiki.observation.event; + +import org.xwiki.observation.event.filter.EventFilter; + +/** + * An event triggered when a document is rolled back. + * + * @version $Id: $ + */ +public class DocumentRollbackEvent extends AbstractDocumentEvent +{ + /** + * The version identifier for this Serializable class. Increment only if the serialized form of the class + * changes. + */ + private static final long serialVersionUID = 1L; + + /** + * Rolled back document version. + */ + private String version; + + /** + * Constructor initializing the event filter with an + * {@link org.xwiki.observation.event.filter.AlwaysMatchingEventFilter}, meaning that this event will match any + * other document save event. + */ + public DocumentRollbackEvent() + { + super(); + } + + /** + * Constructor initializing the event filter with a {@link org.xwiki.observation.event.filter.FixedNameEventFilter}, + * meaning that this event will match only save events affecting the same document. + * + * @param documentName the name of the saved document to match + * @param version the version to which we rolled back to + */ + public DocumentRollbackEvent(String documentName, String version) + { + super(documentName); + this.version = version; + } + + /** + * Constructor using a custom {@link EventFilter}. + * + * @param eventFilter the filter to use for matching events + */ + public DocumentRollbackEvent(EventFilter eventFilter) + { + super(eventFilter); + } + + /** + * Retrieves the version to which we rolled back to. + * + * @return version the rolled back version + */ + public String getVersion() + { + return version; + } + +} #P xwiki-core Index: src/main/java/com/xpn/xwiki/XWiki.java =================================================================== --- src/main/java/com/xpn/xwiki/XWiki.java (revision 33144) +++ src/main/java/com/xpn/xwiki/XWiki.java (working copy) @@ -112,6 +112,7 @@ import com.xpn.xwiki.internal.event.CommentDeletedEvent; import com.xpn.xwiki.internal.event.CommentUpdatedEvent; import org.xwiki.observation.event.DocumentDeleteEvent; +import org.xwiki.observation.event.DocumentRollbackEvent; import org.xwiki.observation.event.DocumentSaveEvent; import org.xwiki.observation.event.DocumentUpdateEvent; import org.xwiki.observation.event.Event; @@ -1448,7 +1449,7 @@ if (originalDocument.isNew()) { getNotificationManager().verify(doc, originalDocument, XWikiDocChangeNotificationInterface.EVENT_NEW, context); - if (om != null) { + if (om != null && !context.getAction().equals("rollback")) { //event will be triggered from xwiki.rollback om.notify(new DocumentSaveEvent(doc.getPrefixedFullName()), doc, context); } } else { @@ -7358,6 +7359,12 @@ saveDocument(rolledbackDoc, context.getMessageTool().get("core.comment.rollback", params), context); + //notify the listeners through Observation Manager + ObservationManager om = Utils.getComponent(ObservationManager.class); + if (om != null) { + om.notify(new DocumentRollbackEvent(rolledbackDoc.getPrefixedFullName(), rev), rolledbackDoc, context); + } + return rolledbackDoc; } #P activitystream Index: src/main/java/com/xpn/xwiki/plugin/activitystream/api/ActivityEventType.java =================================================================== --- src/main/java/com/xpn/xwiki/plugin/activitystream/api/ActivityEventType.java (revision 32198) +++ src/main/java/com/xpn/xwiki/plugin/activitystream/api/ActivityEventType.java (working copy) @@ -85,4 +85,9 @@ * Annotation deletion. */ String DELETE_ANNOTATION = "deleteAnnotation"; + + /** + * Rollback action. + */ + String ROLLBACK = "rollback"; } Index: src/main/java/com/xpn/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java =================================================================== --- src/main/java/com/xpn/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java (revision 33146) +++ src/main/java/com/xpn/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java (working copy) @@ -37,6 +37,7 @@ import org.xwiki.observation.EventListener; import org.xwiki.observation.ObservationManager; import org.xwiki.observation.event.DocumentDeleteEvent; +import org.xwiki.observation.event.DocumentRollbackEvent; import org.xwiki.observation.event.DocumentSaveEvent; import org.xwiki.observation.event.DocumentUpdateEvent; import org.xwiki.observation.event.Event; @@ -110,6 +111,7 @@ add(new AnnotationAddedEvent()); add(new AnnotationDeletedEvent()); add(new AnnotationUpdatedEvent()); + add(new DocumentRollbackEvent()); } }; @@ -943,10 +945,14 @@ eventType = ActivityEventType.DELETE_ANNOTATION; displayTitle = currentDoc.getDisplayTitle(context); additionalIdentifier = ((AnnotationDeletedEvent) event).getIdentifier(); - } else { // update annotation + } else if (event instanceof AnnotationUpdatedEvent) { // update annotation eventType = ActivityEventType.UPDATE_ANNOTATION; displayTitle = currentDoc.getDisplayTitle(context); additionalIdentifier = ((AnnotationUpdatedEvent) event).getIdentifier(); + } else { // document rollback + eventType = ActivityEventType.ROLLBACK; + displayTitle = currentDoc.getDisplayTitle(context); + additionalIdentifier = ((DocumentRollbackEvent) event).getVersion(); } List params = new ArrayList();