use of com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl 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.impl.ActivityEventImpl in project xwiki-platform by xwiki.
the class RecordableEventMigrator method hibernateMigrate.
@Override
protected void hibernateMigrate() throws DataMigrationException, XWikiException {
String hql = "select event from ActivityEventImpl event where event.page LIKE concat(event.wiki, ':%')";
try {
List<ActivityEventImpl> events;
do {
Query query = queryManager.createQuery(hql, Query.HQL);
query.setLimit(50);
events = query.execute();
for (ActivityEventImpl event : events) {
fixEvent(event);
}
} while (!events.isEmpty());
} catch (QueryException e) {
throw new DataMigrationException("Failed to fix RecordableEvent problems.", e);
}
}
use of com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl 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