### Eclipse Workspace Patch 1.0 #P activitystream Index: src/main/java/com/xpn/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java =================================================================== --- src/main/java/com/xpn/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java (revision 33630) +++ src/main/java/com/xpn/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java (working copy) @@ -88,6 +88,11 @@ private static final String EVENT_ID_ELEMENTS_SEPARATOR = "-"; /** + * Character used as a separator between wikiname and username + */ + private static final String WIKI_SPACE_SEPARATOR = ":"; + + /** * The name of the listener. */ private static final String LISTENER_NAME = "activitystream"; @@ -154,7 +159,7 @@ private void prepareEvent(ActivityEvent event, XWikiDocument doc, XWikiContext context) { if (event.getUser() == null) { - event.setUser(context.getUser()); + event.setUser(buildAbsoluteUsername(context.getDatabase(), context.getUser())); } if (event.getWiki() == null) { @@ -190,11 +195,10 @@ private String generateEventId(ActivityEvent event, XWikiContext context) { String keySeparator = EVENT_ID_ELEMENTS_SEPARATOR; - String wikiSpaceSeparator = ":"; String key = event.getStream() + keySeparator + event.getApplication() + keySeparator + event.getWiki() - + wikiSpaceSeparator + event.getPage() + keySeparator + event.getType(); + + WIKI_SPACE_SEPARATOR + event.getPage() + keySeparator + event.getType(); long hash = key.hashCode(); if (hash < 0) { hash = -hash; @@ -411,7 +415,7 @@ event.setVersion(doc.getVersion()); event.setParams(params); // This might be wrong once non-altering events will be logged. - event.setUser(doc.getAuthor()); + event.setUser(buildAbsoluteUsername(context.getDatabase(), doc.getAuthor())); addActivityEvent(event, doc, context); } @@ -983,8 +987,8 @@ * * @see ActivityStream#searchUniquePages(String, int, int, XWikiContext)) */ - public List searchUniquePages(String optionalWhereClause, int maxItems, int startAt, - XWikiContext context) throws ActivityStreamException + public List searchUniquePages(String optionalWhereClause, int maxItems, int startAt, XWikiContext context) + throws ActivityStreamException { return searchUniquePages(optionalWhereClause, null, maxItems, startAt, context); } @@ -994,8 +998,8 @@ * * @see ActivityStream#searchUniquePages(String, List, int, int, XWikiContext)) */ - public List searchUniquePages(String optionalWhereClause, List parametersValues, - int maxItems, int startAt, XWikiContext context) throws ActivityStreamException + public List searchUniquePages(String optionalWhereClause, List parametersValues, int maxItems, + int startAt, XWikiContext context) throws ActivityStreamException { StringBuffer searchHql = new StringBuffer(); List results; @@ -1026,8 +1030,8 @@ * * @see ActivityStream#searchDailyPages(String, int, int, XWikiContext)) */ - public List searchDailyPages(String optionalWhereClause, int maxItems, int startAt, - XWikiContext context) throws ActivityStreamException + public List searchDailyPages(String optionalWhereClause, int maxItems, int startAt, XWikiContext context) + throws ActivityStreamException { return searchDailyPages(optionalWhereClause, null, maxItems, startAt, context); } @@ -1037,8 +1041,8 @@ * * @see ActivityStream#searchDailyPages(String, List, int, int, XWikiContext)) */ - public List searchDailyPages(String optionalWhereClause, List parametersValues, - int maxItems, int startAt, XWikiContext context) throws ActivityStreamException + public List searchDailyPages(String optionalWhereClause, List parametersValues, int maxItems, + int startAt, XWikiContext context) throws ActivityStreamException { StringBuffer searchHql = new StringBuffer(); List results = new ArrayList(); @@ -1067,4 +1071,17 @@ return results; } + + /** + * Builds an absolute form of the username "wiki:XWiki.Admin" for example + * + * @param wikiName - the name of the wiki + * @param user - the user + */ + + private String buildAbsoluteUsername(String wikiName, String user) + { + return wikiName + WIKI_SPACE_SEPARATOR + user; + } + }