Author: ludovic
Date: 2008-02-10 23:38:10 +0100 (Sun, 10 Feb 2008)
New Revision: 7476

Added:
   xwiki-products/curriki/trunk/plugins/activitystream/src/main/resources/
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/resources/activitystream.hbm.xml
   xwiki-products/curriki/trunk/plugins/currikiactivitystream/
   xwiki-products/curriki/trunk/plugins/currikiactivitystream/pom.xml
   xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/
   xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/
   xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/
   xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/impl/
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/impl/CurrikiActivityStream.java
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPlugin.java
   
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPluginApi.java
Modified:
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityEventImpl.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPlugin.java
   
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
Log:
CURRIKI-1569 Activity Stream Core storage

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
    2008-02-10 22:32:26 UTC (rev 7475)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityEvent.java
    2008-02-10 22:38:10 UTC (rev 7476)
@@ -20,6 +20,7 @@
 package org.xwiki.plugin.activitystream.api;
 
 import java.util.Date;
+import java.util.List;
 
 import com.xpn.xwiki.XWikiContext;
 
@@ -268,4 +269,10 @@
      * @return
      */
     String getDisplayUser(XWikiContext context);
+
+    /**
+     * Set all params at once
+     * @param params
+     */
+    void setParams(List params);
 }

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
   2008-02-10 22:32:26 UTC (rev 7475)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/api/ActivityStream.java
   2008-02-10 22:38:10 UTC (rev 7476)
@@ -36,6 +36,13 @@
     void initClasses(XWikiContext context) throws XWikiException;
 
     /**
+     * Tranforms space name into stream name
+     * @param space
+     * @return
+     */
+    String getStreamName(String space);
+
+    /**
      * Adding and activity event. The Id does not need to be filled as it will 
be created. Date and
      * Wiki are optional
      * 
@@ -46,12 +53,18 @@
     void addActivityEvent(ActivityEvent event, XWikiContext context)
         throws ActivityStreamException;
 
-    void addActivityEvent(String type, String title, XWikiContext context)
+    void addActivityEvent(String streamName, String type, String title, 
XWikiContext context)
         throws ActivityStreamException;
 
-    void addDocumentActivityEvent(XWikiDocument doc, String type, String title,
+    void addActivityEvent(String streamName, String type, String title, List 
params, XWikiContext context)
+        throws ActivityStreamException;
+
+    void addDocumentActivityEvent(String streamName, XWikiDocument doc, String 
type, String title,
         XWikiContext context) throws ActivityStreamException;
 
+    void addDocumentActivityEvent(String streamName, XWikiDocument doc, String 
type, String title, List params,
+        XWikiContext context) throws ActivityStreamException;
+
     List searchEvents(String hql, boolean filter, int nb, int start, 
XWikiContext context)
         throws ActivityStreamException;
 

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityEventImpl.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityEventImpl.java
       2008-02-10 22:32:26 UTC (rev 7475)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityEventImpl.java
       2008-02-10 22:38:10 UTC (rev 7476)
@@ -20,6 +20,7 @@
 package org.xwiki.plugin.activitystream.impl;
 
 import java.util.Date;
+import java.util.List;
 
 import org.xwiki.plugin.activitystream.api.ActivityEvent;
 
@@ -85,6 +86,26 @@
         return context.getWiki().getLocalUserName(user, context);
     }
 
+    public void setParams(List params) {
+        if (params!=null) {
+            if (params.size()>0) {
+                setParam1(params.get(0).toString());
+            }
+            if (params.size()>1) {
+                setParam1(params.get(1).toString());
+            }
+            if (params.size()>2) {
+                setParam1(params.get(2).toString());
+            }
+            if (params.size()>3) {
+                setParam1(params.get(3).toString());
+            }
+            if (params.size()>4) {
+                setParam1(params.get(4).toString());
+            }
+        }
+    }
+
     public String getEventId()
     {
         return eventId;

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
      2008-02-10 22:32:26 UTC (rev 7475)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/impl/ActivityStreamImpl.java
      2008-02-10 22:38:10 UTC (rev 7476)
@@ -20,6 +20,7 @@
 package org.xwiki.plugin.activitystream.impl;
 
 import java.util.List;
+import java.util.ArrayList;
 
 import org.apache.commons.lang.RandomStringUtils;
 import org.hibernate.Session;
@@ -43,28 +44,33 @@
     {
         // listen to notifications
         context.getWiki().getNotificationManager().addGeneralRule(
-            new DocChangeRule(this, true, true));
+                new DocChangeRule(this));
     }
 
-    protected void prepareEvent(ActivityEvent event, XWikiContext context)
+    protected void prepareEvent(ActivityEvent event, XWikiDocument doc, 
XWikiContext context)
     {
+        if (doc==null)
+            doc = context.getDoc();
+
         if (event.getUser() == null) {
             event.setUser(context.getUser());
         }
         if (event.getStream() == null) {
-            event.setStream(context.getUser());
+            String space =  (doc==null) ? "" : doc.getSpace();
+
+            event.setStream(getStreamName(space));
         }
         if (event.getWiki() == null) {
             event.setWiki(context.getDatabase());
         }
         if (event.getSpace() == null) {
-            event.setSpace(context.getDoc().getSpace());
+            event.setSpace((doc==null) ? "" : doc.getSpace());
         }
         if (event.getPage() == null) {
-            event.setPage(context.getDoc().getFullName());
+            event.setPage((doc==null) ? "" : doc.getFullName());
         }
         if (event.getUrl() == null) {
-            event.setUrl(context.getDoc().getURL("view", context));
+            event.setUrl((doc==null) ? "" : doc.getURL("view", context));
         }
         if (event.getApplication() == null) {
             event.setApplication("xwiki");
@@ -80,44 +86,78 @@
         }
     }
 
+    public String getStreamName(String space) {
+        return space;
+    }
+
     protected String generateEventId(ActivityEvent event, XWikiContext context)
     {
-        return event.getStream() + "-" + event.getApplication() + "-" + 
event.getWiki() + ":"
-            + event.getPage() + "-" + event.getType() + "-" + 
event.getDate().getTime() + "-"
-            + RandomStringUtils.randomAlphanumeric(4);
+        String key = event.getStream() + "-" + event.getApplication() + "-" + 
event.getWiki() + ":"
+                + event.getPage() + "-" + event.getType();
+        long hash = key.hashCode();
+        if (hash<0)
+         hash = -hash;
+
+        String id =  "" + hash +  "-" + event.getDate().getTime() + "-"
+                + RandomStringUtils.randomAlphanumeric(8);
+        if (context.get("activitystream_requestid")==null) {
+            context.put("activitystream_requestid", id);
+        }
+        return id;
     }
 
     public void addActivityEvent(ActivityEvent event, XWikiContext context)
-        throws ActivityStreamException
+            throws ActivityStreamException
     {
-        prepareEvent(event, context);
+        addActivityEvent(event, null, context);
+    }
 
+    public void addActivityEvent(ActivityEvent event, XWikiDocument doc, 
XWikiContext context)
+            throws ActivityStreamException
+    {
+        prepareEvent(event, doc, context);
+
         // store event using hibernate
         XWikiHibernateStore hibstore = context.getWiki().getHibernateStore();
         try {
             hibstore.beginTransaction(context);
             Session session = hibstore.getSession(context);
-            session.saveOrUpdate(event);
+            session.save(event);
             hibstore.endTransaction(context, true);
         } catch (XWikiException e) {
             hibstore.endTransaction(context, false);
         }
     }
 
-    public void addActivityEvent(String type, String title, XWikiContext 
context)
-        throws ActivityStreamException
+    public void addActivityEvent(String streamName, String type, String title, 
XWikiContext context)
+            throws ActivityStreamException
     {
+        addActivityEvent(streamName, type, title, null, context);
+    }
+
+    public void addActivityEvent(String streamName, String type, String title, 
List params, XWikiContext context)
+            throws ActivityStreamException
+    {
         ActivityEvent event = newActivityEvent();
+        event.setStream(streamName);
         event.setType(type);
         event.setTitle(title);
         event.setBody(title);
+        event.setParams(params);
         addActivityEvent(event, context);
     }
 
-    public void addDocumentActivityEvent(XWikiDocument doc, String type, 
String title,
-        XWikiContext context) throws ActivityStreamException
+    public void addDocumentActivityEvent(String streamName, XWikiDocument doc, 
String type, String title,
+                                         XWikiContext context) throws 
ActivityStreamException
     {
+        addDocumentActivityEvent(streamName, doc, type, title, null, context);
+    }
+
+    public void addDocumentActivityEvent(String streamName, XWikiDocument doc, 
String type, String title, List params,
+                                         XWikiContext context) throws 
ActivityStreamException
+    {
         ActivityEvent event = newActivityEvent();
+        event.setStream(streamName);
         event.setPage(doc.getFullName());
         if (doc.getDatabase() != null) {
             event.setWiki(doc.getDatabase());
@@ -127,15 +167,16 @@
         event.setType(type);
         event.setTitle(title);
         event.setBody(title);
-        addActivityEvent(event, context);
+        event.setParams(params);
+        addActivityEvent(event, doc, context);
     }
 
     public List searchEvents(String hql, boolean filter, int nb, int start, 
XWikiContext context)
-        throws ActivityStreamException
+            throws ActivityStreamException
     {
         String searchHql = "select act.* from ActivityEvent as act " + hql;
         String filterQuery =
-            ", ActivityEvent act2 where act.eventId=act2.eventId and 
act.priority=max(act2.priority)";
+                ", ActivityEvent act2 where act.eventId=act2.eventId and 
act.priority=max(act2.priority)";
         if (filter) {
             searchHql += filterQuery;
         }
@@ -152,41 +193,41 @@
     }
 
     public List getEvents(boolean filter, int nb, int start, XWikiContext 
context)
-        throws ActivityStreamException
+            throws ActivityStreamException
     {
         return searchEvents("", filter, nb, start, context);
     }
 
     public List getEventsForSpace(String space, boolean filter, int nb, int 
start,
-        XWikiContext context) throws ActivityStreamException
+                                  XWikiContext context) throws 
ActivityStreamException
     {
         return searchEvents("where act.space='" + space + "'", filter, nb, 
start, context);
     }
 
     public List getEventsForUser(String user, boolean filter, int nb, int 
start,
-        XWikiContext context) throws ActivityStreamException
+                                 XWikiContext context) throws 
ActivityStreamException
     {
         return searchEvents("where act.user='" + user + "'", filter, nb, 
start, context);
     }
 
     public List getEvents(String stream, boolean filter, int nb, int start, 
XWikiContext context)
-        throws ActivityStreamException
+            throws ActivityStreamException
     {
         return searchEvents("where act.stream='" + stream + "'", filter, nb, 
start, context);
     }
 
     public List getEventsForSpace(String stream, String space, boolean filter, 
int nb, int start,
-        XWikiContext context) throws ActivityStreamException
+                                  XWikiContext context) throws 
ActivityStreamException
     {
         return searchEvents("where act.space='" + space + "' and act.stream='" 
+ stream + "'",
-            filter, nb, start, context);
+                filter, nb, start, context);
     }
 
     public List getEventsForUser(String stream, String user, boolean filter, 
int nb, int start,
-        XWikiContext context) throws ActivityStreamException
+                                 XWikiContext context) throws 
ActivityStreamException
     {
         return searchEvents("where act.user='" + user + "' and act.stream='" + 
stream + "'",
-            filter, nb, start, context);
+                filter, nb, start, context);
     }
 
     protected ActivityEvent newActivityEvent()
@@ -195,31 +236,46 @@
     }
 
     public void notify(XWikiNotificationRule rule, XWikiDocument newdoc, 
XWikiDocument olddoc,
-        int event, XWikiContext context)
+                       int event, XWikiContext context)
     {
+        ArrayList params = new ArrayList();
+        params.set(0, newdoc.getDisplayTitle(context));
+
+        String streamName = getStreamName(newdoc.getSpace());
+
+        if (streamName==null)
+         return;
+
         try {
             switch (event) {
                 case XWikiDocChangeNotificationInterface.EVENT_CHANGE:
-                    addActivityEvent(ActivityEventType.UPDATE, null, context);
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
                     break;
                 case XWikiDocChangeNotificationInterface.EVENT_NEW:
-                    addActivityEvent(ActivityEventType.CREATE, null, context);
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.CREATE, "as_document_has_been_created", params, context);
                     break;
                 case XWikiDocChangeNotificationInterface.EVENT_DELETE:
-                    addActivityEvent(ActivityEventType.DELETE, null, context);
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.DELETE, "as_document_has_been_deleted", params, context);
                     break;
                 case XWikiDocChangeNotificationInterface.EVENT_UPDATE_CONTENT:
-                    addActivityEvent(ActivityEventType.UPDATE, null, context);
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
                     break;
                 case XWikiDocChangeNotificationInterface.EVENT_UPDATE_OBJECT:
-                    // TODO
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
                     break;
                 case XWikiDocChangeNotificationInterface.EVENT_UPDATE_CLASS:
-                    // TODO
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
                     break;
             }
-        } catch (ActivityStreamException e) {
-            // ignore
+        } catch (Throwable e) {
+            // Error in activity stream notify should be ignored but logged in 
the log file
+            e.printStackTrace();
         }
     }
+
+    /*
+    public FeedEntry getFeedEntry(ActivityEvent event, XWikiContext context) {
+        return null;
+    } */
+
 }

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPlugin.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPlugin.java
  2008-02-10 22:32:26 UTC (rev 7475)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPlugin.java
  2008-02-10 22:38:10 UTC (rev 7476)
@@ -37,7 +37,7 @@
     /**
      * We should user inversion of control instead
      */
-    private ActivityStream activityStream = new ActivityStreamImpl();
+    private ActivityStream activityStream;
 
     /**
      * @see 
XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
@@ -45,6 +45,7 @@
     public ActivityStreamPlugin(String name, String className, XWikiContext 
context)
     {
         super(name, className, context);
+        setActivityStream(new ActivityStreamImpl());
     }
 
     /**

Modified: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
       2008-02-10 22:32:26 UTC (rev 7475)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/java/org/xwiki/plugin/activitystream/plugin/ActivityStreamPluginApi.java
       2008-02-10 22:38:10 UTC (rev 7476)
@@ -20,11 +20,17 @@
 package org.xwiki.plugin.activitystream.plugin;
 
 import org.xwiki.plugin.activitystream.api.ActivityStream;
+import org.xwiki.plugin.activitystream.api.ActivityEvent;
+import org.xwiki.plugin.activitystream.api.ActivityStreamException;
 
 import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.api.Document;
+import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.plugin.PluginApi;
 import com.xpn.xwiki.plugin.XWikiPluginInterface;
 
+import java.util.List;
+
 /**
  * API for [EMAIL PROTECTED] ActivityStreamPlugin}
  */
@@ -45,4 +51,91 @@
     {
         return ((ActivityStreamPlugin) getPlugin()).getActivityStream();
     }
+
+    public void addActivityEvent(ActivityEvent event) throws 
ActivityStreamException {
+         if (hasProgrammingRights()) {
+             getActivityStream().addActivityEvent(event, context);
+         }
+    }
+
+    public void addActivityEvent(String streamName, String type, String title) 
throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            getActivityStream().addActivityEvent(streamName, type, title, 
context);
+        }
+    }
+
+    public void addDocumentActivityEvent(String streamName, Document doc, 
String type, String title) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            getActivityStream().addDocumentActivityEvent(streamName, 
doc.getDocument(), type, title, context);
+        }
+    }
+
+    public void addActivityEvent(String streamName, String type, String title, 
List params) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            getActivityStream().addActivityEvent(streamName, type, title, 
params, context);
+        }
+    }
+
+    public void addDocumentActivityEvent(String streamName, Document doc, 
String type, String title, List params) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            getActivityStream().addDocumentActivityEvent(streamName, 
doc.getDocument(), type, title, params, context);
+        }
+    }
+
+    public List searchEvents(String hql, boolean filter, int nb, int start) 
throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            return getActivityStream().searchEvents(hql, filter, nb, start, 
context);
+        } else {
+            return null;
+        }
+    }
+
+    public List getEvents(boolean filter, int nb, int start) throws 
ActivityStreamException {
+        if (hasProgrammingRights()) {
+            return getActivityStream().getEvents(filter, nb, start, context);
+        } else {
+            return null;
+        }
+    }
+
+    public List getEventsForSpace(String space, boolean filter, int nb, int 
start) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            return getActivityStream().getEventsForSpace(space, filter, nb, 
start, context);
+        } else {
+            return null;
+        }
+    }
+
+    public List getEventsForUser(String user, boolean filter, int nb, int 
start) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            return getActivityStream().getEventsForUser(user, filter, nb, 
start, context);
+        } else {
+            return null;
+        }
+    }
+
+    public List getEvents(String streamName, boolean filter, int nb, int 
start) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            return getActivityStream().getEvents(streamName, filter, nb, 
start, context);
+        } else {
+            return null;
+        }
+    }
+
+    public List getEventsForSpace(String streamName, String space, boolean 
filter, int nb, int start) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            return getActivityStream().getEventsForSpace(streamName, space, 
filter, nb, start, context);
+        } else {
+            return null;
+        }
+    }
+
+    public List getEventsForUser(String streamName, String user, boolean 
filter, int nb, int start) throws ActivityStreamException {
+        if (hasProgrammingRights()) {
+            return getActivityStream().getEventsForUser(streamName, user, 
filter, nb, start, context);
+        } else {
+            return null;
+        }
+    }
+    
 }

Added: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/resources/activitystream.hbm.xml
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/resources/activitystream.hbm.xml
                               (rev 0)
+++ 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/resources/activitystream.hbm.xml
       2008-02-10 22:38:10 UTC (rev 7476)
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
+        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd";>
+<hibernate-mapping>
+    <class name="org.xwiki.plugin.activitystream.impl.ActivityEventImpl" 
table="activitystream_events">
+        <id name="eventId" type="string" unsaved-value="any"><column 
name="ase_eventid" length="255" not-null="true" /><generator class="assigned" 
/></id>
+        <property name="requestId" type="string"><column name="ase_requestid" 
length="2000" /></property>
+        <property name="stream" type="string"><column name="ase_stream" 
length="255" /></property>
+        <property name="date" type="timestamp"><column name="ase_date" 
/></property>
+        <property name="priority" type="integer"><column name="ase_priority" 
/></property>
+        <property name="type" type="string"><column name="ase_type" 
length="255" /></property>
+        <property name="application" type="string"><column 
name="ase_application" length="255" /></property>
+        <property name="user" type="string"><column name="ase_user" 
length="255" /></property>
+        <property name="wiki" type="string"><column name="ase_wiki" 
length="255" /></property>
+        <property name="space" type="string"><column name="ase_space" 
length="255" /></property>
+        <property name="page" type="string"><column name="ase_page" 
length="255" /></property>
+        <property name="url" type="string"><column name="ase_url" 
length="2000" /></property>
+        <property name="title" type="string"><column name="ase_title" 
length="2000" /></property>
+        <property name="body" type="string"><column name="ase_body" 
length="2000" /></property>
+        <property name="param1" type="string"><column name="ase_param1" 
length="2000" /></property>
+        <property name="param2" type="string"><column name="ase_param2" 
length="2000" /></property>
+        <property name="param3" type="string"><column name="ase_param3" 
length="2000" /></property>
+        <property name="param4" type="string"><column name="ase_param4" 
length="2000" /></property>
+        <property name="param5" type="string"><column name="ase_param5" 
length="2000" /></property>
+    </class>
+</hibernate-mapping>


Property changes on: 
xwiki-products/curriki/trunk/plugins/activitystream/src/main/resources/activitystream.hbm.xml
___________________________________________________________________
Name: svn:executable
   + *

Added: xwiki-products/curriki/trunk/plugins/currikiactivitystream/pom.xml
===================================================================
--- xwiki-products/curriki/trunk/plugins/currikiactivitystream/pom.xml          
                (rev 0)
+++ xwiki-products/curriki/trunk/plugins/currikiactivitystream/pom.xml  
2008-02-10 22:38:10 UTC (rev 7476)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+
+<!--
+ *
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ *
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.curriki</groupId>
+    <artifactId>curriki-plugins</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>curriki-plugin-activitystream</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>XWiki Products - Curriki - Plugins - Activity Stream</name>
+  <packaging>jar</packaging>
+  <description>XWiki Products - Curriki - Plugins - Activity 
Stream</description>
+  <dependencies>
+    <dependency>
+      <groupId>com.xpn.xwiki.platform</groupId>
+      <artifactId>xwiki-core</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock-cglib</artifactId>
+      <version>1.1.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.xpn.xwiki.platform.plugins</groupId>
+      <artifactId>xwiki-plugin-mailsender</artifactId>
+      <version>1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>com.xpn.xwiki.platform.plugins</groupId>
+      <artifactId>xwiki-plugin-activitystream</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>      

Added: 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/impl/CurrikiActivityStream.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/impl/CurrikiActivityStream.java
                          (rev 0)
+++ 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/impl/CurrikiActivityStream.java
  2008-02-10 22:38:10 UTC (rev 7476)
@@ -0,0 +1,78 @@
+package org.curriki.plugin.activitystream.impl;
+
+import org.xwiki.plugin.activitystream.impl.ActivityStreamImpl;
+import org.xwiki.plugin.activitystream.api.ActivityEventType;
+import com.xpn.xwiki.notify.XWikiNotificationRule;
+import com.xpn.xwiki.notify.XWikiDocChangeNotificationInterface;
+import com.xpn.xwiki.doc.XWikiDocument;
+import com.xpn.xwiki.XWikiContext;
+
+import java.util.ArrayList;
+
+
+public class CurrikiActivityStream extends ActivityStreamImpl {
+    private String CURRIKI_SPACE_TYPE = "currikispace";
+    private String SPACE_CLASS_NAME = "XWiki.SpaceClass";
+
+    public CurrikiActivityStream()
+    {
+        super();
+    }
+
+    public void notify(XWikiNotificationRule rule, XWikiDocument newdoc, 
XWikiDocument olddoc, int event, XWikiContext context) {
+        try {
+        ArrayList params = new ArrayList();
+        params.add(newdoc.getDisplayTitle(context));
+
+        String streamName = getStreamName(newdoc.getSpace(), context);
+        if (streamName==null)
+         return;
+
+            switch (event) {
+                case XWikiDocChangeNotificationInterface.EVENT_CHANGE:
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
+                    break;
+                case XWikiDocChangeNotificationInterface.EVENT_NEW:
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.CREATE, "as_document_has_been_created", params, context);
+                    break;
+                case XWikiDocChangeNotificationInterface.EVENT_DELETE:
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.DELETE, "as_document_has_been_deleted", params, context);
+                    break;
+                case XWikiDocChangeNotificationInterface.EVENT_UPDATE_CONTENT:
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
+                    break;
+                case XWikiDocChangeNotificationInterface.EVENT_UPDATE_OBJECT:
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
+                    break;
+                case XWikiDocChangeNotificationInterface.EVENT_UPDATE_CLASS:
+                    addDocumentActivityEvent(streamName, newdoc, 
ActivityEventType.UPDATE, "as_document_has_been_updated", params, context);
+                    break;
+            }
+        } catch (Throwable e) {
+            // Error in activity stream notify should be ignored but logged in 
the log file
+            e.printStackTrace();
+        }
+    }
+
+    public String getStreamName(String space, XWikiContext context) {
+        XWikiDocument doc;
+        try {
+            doc = context.getWiki().getDocument(space, "WebPreferences", 
context);
+            String type = doc.getStringValue(SPACE_CLASS_NAME, "type");
+
+            if (CURRIKI_SPACE_TYPE.equals(type))
+                return space;
+
+            String parentSpace = space.substring(space.indexOf("_") + 1);
+            doc = context.getWiki().getDocument(parentSpace, "WebPreferences", 
context);
+            type = doc.getStringValue(SPACE_CLASS_NAME, "type");
+            if (CURRIKI_SPACE_TYPE.equals(type))
+                return parentSpace;
+
+            // could not find a curriki space
+            return null;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+}

Added: 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPlugin.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPlugin.java
                          (rev 0)
+++ 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPlugin.java
  2008-02-10 22:38:10 UTC (rev 7476)
@@ -0,0 +1,34 @@
+package org.curriki.plugin.activitystream.plugin;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.plugin.XWikiPluginInterface;
+import org.xwiki.plugin.activitystream.plugin.ActivityStreamPlugin;
+import org.curriki.plugin.activitystream.impl.CurrikiActivityStream;
+
+
+public class CurrikiActivityStreamPlugin extends ActivityStreamPlugin {
+
+    public CurrikiActivityStreamPlugin(String name, String className, 
XWikiContext context)
+    {
+        super(name, className, context);
+        setActivityStream(new CurrikiActivityStream());       
+    }
+
+    public String getName() {
+        return "activitystream";
+    }
+
+
+
+    /**
+     * Gets the activity plugin Api
+     * @param plugin The plugin interface
+     * @param context Xwiki context
+     * @return                              
+     */
+    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) 
{
+        return new 
CurrikiActivityStreamPluginApi((CurrikiActivityStreamPlugin) plugin, context);
+    }
+
+}

Added: 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPluginApi.java
===================================================================
--- 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPluginApi.java
                               (rev 0)
+++ 
xwiki-products/curriki/trunk/plugins/currikiactivitystream/src/main/java/org/curriki/plugin/activitystream/plugin/CurrikiActivityStreamPluginApi.java
       2008-02-10 22:38:10 UTC (rev 7476)
@@ -0,0 +1,19 @@
+package org.curriki.plugin.activitystream.plugin;
+
+
+import org.curriki.plugin.activitystream.impl.CurrikiActivityStream;
+import org.xwiki.plugin.activitystream.plugin.ActivityStreamPluginApi;
+
+import com.xpn.xwiki.XWikiContext;
+
+public class CurrikiActivityStreamPluginApi extends ActivityStreamPluginApi {
+
+    public CurrikiActivityStreamPluginApi(CurrikiActivityStreamPlugin plugin, 
XWikiContext context)
+    {
+        super(plugin, context);
+    }
+
+    protected CurrikiActivityStream getCurrikiActivityStream() {
+        return (CurrikiActivityStream) ((CurrikiActivityStreamPlugin) 
getPlugin()).getActivityStream();
+    }
+}

_______________________________________________
notifications mailing list
notifications@xwiki.org
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to