Search in sources :

Example 6 with ActivityEvent

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

Example 7 with ActivityEvent

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
        }
    }
}
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 8 with ActivityEvent

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

Example 9 with ActivityEvent

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());
}
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

ActivityEvent (com.xpn.xwiki.plugin.activitystream.api.ActivityEvent)9 ArrayList (java.util.ArrayList)3 ActivityStreamException (com.xpn.xwiki.plugin.activitystream.api.ActivityStreamException)2 ActivityEventImpl (com.xpn.xwiki.plugin.activitystream.impl.ActivityEventImpl)2 ActivityStreamPlugin (com.xpn.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin)2 Date (java.util.Date)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 WikiReference (org.xwiki.model.reference.WikiReference)2 WatchListEvent (org.xwiki.watchlist.internal.api.WatchListEvent)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 ActivityStream (com.xpn.xwiki.plugin.activitystream.api.ActivityStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Map (java.util.Map)1 Test (org.junit.Test)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 Event (org.xwiki.eventstream.Event)1 Query (org.xwiki.query.Query)1 WatchListEventConverter (org.xwiki.watchlist.internal.WatchListEventConverter)1