use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent in project xwiki-platform by xwiki.
the class EventConverter method convertEventToActivity.
/**
* Converts a new {@link Event} to the old {@link ActivityEvent}.
*
* @param e the event to transform
* @return the equivalent activity event
*/
public ActivityEvent convertEventToActivity(Event e) {
ActivityEvent result = new ActivityEventImpl();
result.setApplication(e.getApplication());
result.setBody(e.getBody());
result.setDate(e.getDate());
result.setEventId(e.getId());
result.setPage(this.compactSerializer.serialize(e.getDocument(), e.getWiki()));
if (e.getDocumentTitle() != null) {
result.setParam1(e.getDocumentTitle());
}
if (e.getRelatedEntity() != null) {
result.setParam2(this.serializer.serialize(e.getRelatedEntity()));
}
result.setPriority((e.getImportance().ordinal() + 1) * 10);
result.setRequestId(e.getGroupId());
result.setSpace(this.compactSerializer.serialize(e.getSpace(), e.getWiki()));
result.setStream(e.getStream());
result.setTitle(e.getTitle());
result.setType(e.getType());
if (e.getUrl() != null) {
result.setUrl(e.getUrl().toString());
}
result.setUser(this.serializer.serialize(e.getUser()));
result.setVersion(e.getDocumentVersion());
result.setWiki(this.serializer.serialize(e.getWiki()));
result.setParameters(e.getParameters());
result.setTarget(e.getTarget());
return result;
}
use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent 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.ActivityEvent 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;
}
use of com.xpn.xwiki.plugin.activitystream.api.ActivityEvent in project xwiki-platform by xwiki.
the class ActivityEventWatchListEventConverterTest method testConversion.
@Test
public void testConversion() throws Exception {
// Input.
ActivityEvent activityEvent = new ActivityEventImpl();
activityEvent.setWiki("xwiki");
activityEvent.setPage("Space1.Space2.Page");
activityEvent.setType("update");
activityEvent.setUser("xwiki:XWiki.SomeUser");
activityEvent.setVersion("1.3");
activityEvent.setDate(new Date());
// Mocks
DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Space1", "Space2"), "Page");
WikiReference wikiReference = new WikiReference(activityEvent.getWiki());
EntityReferenceResolver<String> resolver = mocker.getInstance(EntityReferenceResolver.TYPE_STRING, "explicit");
// Note: cheating a bit, it should return an entityReference instead of documentReference, but we are fine.
when(resolver.resolve(activityEvent.getPage(), EntityType.DOCUMENT, wikiReference)).thenReturn(documentReference);
DocumentReference userReference = new DocumentReference("xwiki", "XWiki", "SomeUser");
when(resolver.resolve(activityEvent.getUser(), EntityType.DOCUMENT, wikiReference)).thenReturn(userReference);
// Convert.
WatchListEvent watchListEvent = mocker.getComponentUnderTest().convert(activityEvent);
// Test the output.
assertEquals(documentReference, watchListEvent.getDocumentReference());
assertEquals(activityEvent.getWiki(), watchListEvent.getDocumentReference().getWikiReference().getName());
assertEquals(activityEvent.getType(), watchListEvent.getType());
assertEquals(userReference, watchListEvent.getAuthorReference());
assertEquals(1, watchListEvent.getAuthorReferences().size());
assertEquals(activityEvent.getVersion(), watchListEvent.getVersion());
assertEquals(1, watchListEvent.getVersions().size());
assertEquals(activityEvent.getDate(), watchListEvent.getDate());
assertEquals(1, watchListEvent.getDates().size());
}
Aggregations