Search in sources :

Example 1 with EventStreamDeletedEvent

use of org.xwiki.eventstream.events.EventStreamDeletedEvent in project xwiki-platform by xwiki.

the class ActivityStreamImpl method deleteActivityEvent.

@Override
public void deleteActivityEvent(ActivityEvent event, XWikiContext context) throws ActivityStreamException {
    boolean bTransaction = true;
    ActivityEventImpl evImpl = loadActivityEvent(event, true, context);
    String oriDatabase = context.getWikiId();
    if (useLocalStore()) {
        XWikiHibernateStore hibstore;
        // delete event from the local database
        if (context.getWikiId().equals(event.getWiki())) {
            hibstore = context.getWiki().getHibernateStore();
        } else {
            context.setWikiId(event.getWiki());
            hibstore = context.getWiki().getHibernateStore();
        }
        try {
            if (bTransaction) {
                hibstore.checkHibernate(context);
                bTransaction = hibstore.beginTransaction(context);
            }
            Session session = hibstore.getSession(context);
            session.delete(evImpl);
            if (bTransaction) {
                hibstore.endTransaction(context, true);
            }
        } catch (XWikiException e) {
            throw new ActivityStreamException();
        } finally {
            try {
                if (bTransaction) {
                    hibstore.endTransaction(context, false);
                }
                if (context.getWikiId().equals(oriDatabase)) {
                    context.setWikiId(oriDatabase);
                }
            } catch (Exception e) {
            // Do nothing.
            }
        }
    }
    if (useMainStore()) {
        // delete event from the main database
        context.setWikiId(context.getMainXWiki());
        XWikiHibernateStore hibstore = context.getWiki().getHibernateStore();
        try {
            if (bTransaction) {
                hibstore.checkHibernate(context);
                bTransaction = hibstore.beginTransaction(context);
            }
            Session session = hibstore.getSession(context);
            session.delete(evImpl);
            if (bTransaction) {
                hibstore.endTransaction(context, true);
            }
        } catch (XWikiException e) {
            throw new ActivityStreamException();
        } finally {
            try {
                if (bTransaction) {
                    hibstore.endTransaction(context, false);
                }
                context.setWikiId(oriDatabase);
            } catch (Exception e) {
            // Do nothing
            }
        }
    }
    this.sendEventStreamEvent(new EventStreamDeletedEvent(), event);
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) EventStreamDeletedEvent(org.xwiki.eventstream.events.EventStreamDeletedEvent) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) XWikiException(com.xpn.xwiki.XWikiException) XWikiException(com.xpn.xwiki.XWikiException) MalformedURLException(java.net.MalformedURLException) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) Session(org.hibernate.Session)

Example 2 with EventStreamDeletedEvent

use of org.xwiki.eventstream.events.EventStreamDeletedEvent in project xwiki-platform by xwiki.

the class BridgeEventStream method deleteEvent.

@Override
public void deleteEvent(Event e) {
    try {
        XWikiContext context = getXWikiContext();
        ActivityStreamPlugin plugin = getPlugin(context);
        plugin.getActivityStream().deleteActivityEvent(eventConverter.convertEventToActivity(e), context);
        this.observationManager.notify(new EventStreamDeletedEvent(), e);
    } catch (ActivityStreamException ex) {
    // Unlikely; nothing we can do
    }
}
Also used : EventStreamDeletedEvent(org.xwiki.eventstream.events.EventStreamDeletedEvent) XWikiContext(com.xpn.xwiki.XWikiContext) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Aggregations

ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)2 EventStreamDeletedEvent (org.xwiki.eventstream.events.EventStreamDeletedEvent)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 ActivityStreamPlugin (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)1 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)1 MalformedURLException (java.net.MalformedURLException)1 Session (org.hibernate.Session)1