Search in sources :

Example 1 with ActivityEventImpl

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;
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) ActivityEventImpl(com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl)

Example 2 with ActivityEventImpl

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);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) ActivityEventImpl(com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl) DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException)

Example 3 with ActivityEventImpl

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());
}
Also used : ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) WatchListEvent(org.xwiki.watchlist.internal.api.WatchListEvent) ActivityEventImpl(com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl) WikiReference(org.xwiki.model.reference.WikiReference) Date(java.util.Date) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

ActivityEventImpl (com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl)3 ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)2 DataMigrationException (com.xpn.xwiki.store.migration.DataMigrationException)1 Date (java.util.Date)1 Test (org.junit.Test)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1 Query (org.xwiki.query.Query)1 QueryException (org.xwiki.query.QueryException)1 WatchListEvent (org.xwiki.watchlist.internal.api.WatchListEvent)1