Search in sources :

Example 6 with ActivityStreamException

use of com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException in project xwiki-platform by xwiki.

the class ActivityStreamCleanerJob method executeJob.

@Override
protected void executeJob(JobExecutionContext jobContext) throws JobExecutionException {
    ActivityStreamPlugin plugin = (ActivityStreamPlugin) getXWikiContext().getWiki().getPlugin(ActivityStreamPlugin.PLUGIN_NAME, getXWikiContext());
    List<Object> parameters = new ArrayList<Object>();
    int days = ActivityStreamCleaner.getNumberOfDaysToKeep(getXWikiContext());
    if (days > 0) {
        parameters.add(DateUtils.addDays(new Date(), days * -1));
        try {
            List<ActivityEvent> events = plugin.getActivityStream().searchEvents("date < ?", false, true, 0, 0, parameters, getXWikiContext());
            for (ActivityEvent event : events) {
                plugin.getActivityStream().deleteActivityEvent(event, getXWikiContext());
            }
        } catch (ActivityStreamException e) {
        // TODO
        }
    }
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ArrayList(java.util.ArrayList) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) Date(java.util.Date) ActivityStreamPlugin(com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)

Example 7 with ActivityStreamException

use of com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException in project xwiki-platform by xwiki.

the class ActivityStreamImpl method loadActivityEvent.

/**
 * @param event the event
 * @param bTransaction true if inside a transaction
 * @param context the XWiki Context
 * @return the event
 * @throws ActivityStreamException
 */
private ActivityEventImpl loadActivityEvent(ActivityEvent event, boolean bTransaction, XWikiContext context) throws ActivityStreamException {
    boolean bTransactionMutable = bTransaction;
    ActivityEventImpl act = null;
    String eventId = event.getEventId();
    if (useLocalStore()) {
        // load event from the local database
        XWikiHibernateStore hibstore = context.getWiki().getHibernateStore();
        try {
            if (bTransactionMutable) {
                hibstore.checkHibernate(context);
                bTransactionMutable = hibstore.beginTransaction(false, context);
            }
            Session session = hibstore.getSession(context);
            Query query = session.createQuery("select act.eventId from ActivityEventImpl as act where act.eventId = :eventId");
            query.setString("eventId", eventId);
            if (query.uniqueResult() != null) {
                act = new ActivityEventImpl();
                session.load(act, eventId);
            }
            if (bTransactionMutable) {
                hibstore.endTransaction(context, false, false);
            }
        } catch (Exception e) {
            throw new ActivityStreamException();
        } finally {
            try {
                if (bTransactionMutable) {
                    hibstore.endTransaction(context, false, false);
                }
            } catch (Exception e) {
            // Do nothing.
            }
        }
    } else if (useMainStore()) {
        // load event from the main database
        String oriDatabase = context.getWikiId();
        context.setWikiId(context.getMainXWiki());
        XWikiHibernateStore hibstore = context.getWiki().getHibernateStore();
        try {
            if (bTransactionMutable) {
                hibstore.checkHibernate(context);
                bTransactionMutable = hibstore.beginTransaction(false, context);
            }
            Session session = hibstore.getSession(context);
            Query query = session.createQuery("select act.eventId from ActivityEventImpl as act where act.eventId = :eventId");
            query.setString("eventId", eventId);
            if (query.uniqueResult() != null) {
                act = new ActivityEventImpl();
                session.load(act, eventId);
            }
            if (bTransactionMutable) {
                hibstore.endTransaction(context, false, false);
            }
        } catch (Exception e) {
            throw new ActivityStreamException();
        } finally {
            context.setWikiId(oriDatabase);
            try {
                if (bTransactionMutable) {
                    hibstore.endTransaction(context, false, false);
                }
            } catch (Exception e) {
            // Do nothing.
            }
        }
    }
    return act;
}
Also used : XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) Query(org.hibernate.Query) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) XWikiException(com.xpn.xwiki.XWikiException) MalformedURLException(java.net.MalformedURLException) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) Session(org.hibernate.Session)

Example 8 with ActivityStreamException

use of com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException in project xwiki-platform by xwiki.

the class ActivityStreamImpl method searchUniquePages.

@Override
public List<Object[]> searchUniquePages(String optionalWhereClause, List<Object> parametersValues, int maxItems, int startAt, XWikiContext context) throws ActivityStreamException {
    StringBuffer searchHql = new StringBuffer();
    List<Object[]> results;
    searchHql.append("select act.page, max(act.date) from ActivityEventImpl as act");
    addHiddenEventsFilter(searchHql);
    addOptionalEventsFilter(searchHql, optionalWhereClause);
    searchHql.append(" group by act.page order by 2 desc");
    String originalDatabase = context.getWikiId();
    try {
        context.setWikiId(context.getMainXWiki());
        results = context.getWiki().getStore().search(searchHql.toString(), maxItems, startAt, parametersValues, context);
    } catch (XWikiException e) {
        throw new ActivityStreamException(e);
    } finally {
        context.setWikiId(originalDatabase);
    }
    return results;
}
Also used : ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) XWikiException(com.xpn.xwiki.XWikiException)

Example 9 with ActivityStreamException

use of com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException in project xwiki-platform by xwiki.

the class ActivityStreamImpl method searchDailyPages.

@Override
public List<Object[]> searchDailyPages(String optionalWhereClause, List<Object> parametersValues, int maxItems, int startAt, XWikiContext context) throws ActivityStreamException {
    StringBuffer searchHql = new StringBuffer();
    List<Object[]> results = new ArrayList<Object[]>();
    searchHql.append("select year(act.date), month(act.date), day(act.date), act.page, max(act.date), act.wiki " + "from ActivityEventImpl as act");
    addHiddenEventsFilter(searchHql);
    addOptionalEventsFilter(searchHql, optionalWhereClause);
    searchHql.append(" group by year(act.date), month(act.date), day(act.date), act.page, act.wiki " + "order by 5 desc");
    String originalDatabase = context.getWikiId();
    try {
        context.setWikiId(context.getMainXWiki());
        List<Object[]> rawResults = context.getWiki().getStore().search(searchHql.toString(), maxItems, startAt, parametersValues, context);
        for (Object[] rawResult : rawResults) {
            results.add(new Object[] { rawResult[3], rawResult[4], rawResult[5] });
        }
    } catch (XWikiException e) {
        throw new ActivityStreamException(e);
    } finally {
        context.setWikiId(originalDatabase);
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) XWikiException(com.xpn.xwiki.XWikiException)

Example 10 with ActivityStreamException

use of com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException in project xwiki-platform by xwiki.

the class ActivityStreamImpl method searchEvents.

@Override
public List<ActivityEvent> searchEvents(String fromHql, String hql, boolean filter, boolean globalSearch, int nb, int start, List<Object> parameterValues, XWikiContext context) throws ActivityStreamException {
    StringBuffer searchHql = new StringBuffer();
    List<ActivityEvent> results;
    if (filter) {
        searchHql.append("select act from ActivityEventImpl as act, ActivityEventImpl as act2 ");
        searchHql.append(fromHql);
        searchHql.append(" where act.eventId=act2.eventId and ");
        addHiddenEventsFilter(searchHql);
        searchHql.append(hql);
        searchHql.append(" group by act.requestId having (act.priority)=max(act2.priority) order by act.date desc");
    } else {
        searchHql.append("select act from ActivityEventImpl as act ");
        searchHql.append(fromHql);
        searchHql.append(" where ");
        addHiddenEventsFilter(searchHql);
        searchHql.append(hql);
        searchHql.append(" order by act.date desc");
    }
    if (globalSearch) {
        // Search in the main database
        String oriDatabase = context.getWikiId();
        try {
            context.setWikiId(context.getMainXWiki());
            results = context.getWiki().getStore().search(searchHql.toString(), nb, start, parameterValues, context);
        } catch (XWikiException e) {
            throw new ActivityStreamException(e);
        } finally {
            context.setWikiId(oriDatabase);
        }
    } else {
        try {
            // Search in the local database
            results = context.getWiki().getStore().search(searchHql.toString(), nb, start, parameterValues, context);
        } catch (XWikiException e) {
            throw new ActivityStreamException(e);
        }
    }
    return results;
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ActivityStreamException(com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)11 XWikiException (com.xpn.xwiki.XWikiException)6 XWikiContext (com.xpn.xwiki.XWikiContext)5 ActivityStreamPlugin (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)4 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)3 XWikiHibernateStore (com.xpn.xwiki.store.XWikiHibernateStore)3 ArrayList (java.util.ArrayList)3 Session (org.hibernate.Session)3 EventStreamDeletedEvent (org.xwiki.eventstream.events.EventStreamDeletedEvent)3 MalformedURLException (java.net.MalformedURLException)2 EventStreamAddedEvent (org.xwiki.eventstream.events.EventStreamAddedEvent)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 AttachmentAddedEvent (com.xpn.xwiki.internal.event.AttachmentAddedEvent)1 AttachmentDeletedEvent (com.xpn.xwiki.internal.event.AttachmentDeletedEvent)1 AttachmentUpdatedEvent (com.xpn.xwiki.internal.event.AttachmentUpdatedEvent)1 CommentAddedEvent (com.xpn.xwiki.internal.event.CommentAddedEvent)1 CommentDeletedEvent (com.xpn.xwiki.internal.event.CommentDeletedEvent)1 CommentUpdatedEvent (com.xpn.xwiki.internal.event.CommentUpdatedEvent)1 Date (java.util.Date)1 Query (org.hibernate.Query)1