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
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations