Skip to content

Commit

Permalink
XWIKI-6839 Support for named parameters in eventstream events
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Velociter committed Aug 12, 2011
1 parent cf2d2a6 commit 835d75f
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 1 deletion.
3 changes: 3 additions & 0 deletions xwiki-platform-core/pom.xml
Expand Up @@ -357,6 +357,9 @@
<excludes>compatibility/com/xpn/xwiki/api/ApiCompatibilityAspect</excludes>
<excludes>compatibility/com/xpn/xwiki/api/ContextCompatibilityAspect</excludes>
<excludes>compatibility/com/xpn/xwiki/api/DocumentCompatibilityAspect</excludes>
<exclude>org/xwiki/eventstream/Event</exclude>
<exclude>com/xpn/xwiki/plugin/activitystream/api/ActivityEvent</exclude>
<exclude>com/xpn/xwiki/plugin/activitystream/plugin/ActivityEvent</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
Expand Up @@ -21,6 +21,7 @@

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.xpn.xwiki.XWikiContext;

Expand Down Expand Up @@ -341,4 +342,16 @@ public interface ActivityEvent
*/
void setParams(List<String> params);

/**
* Associates name-value pair parameters with this event.
*
* @param parameters the parameters to associate
*/
void setParameters(Map<String, String> parameters);

/**
* @return name-value pair parameters associated with this event.
*/
Map<String, String> getParameters();

}
Expand Up @@ -215,6 +215,8 @@ private ActivityEvent convertEventToActivity(Event e)
result.setVersion(e.getDocumentVersion());
result.setWiki(this.serializer.serialize(e.getWiki()));

result.setParameters(e.getParameters());

return result;
}

Expand Down Expand Up @@ -280,6 +282,7 @@ private Event convertActivityToEvent(ActivityEvent e)
result.setUser(new DocumentReference(this.resolver.resolve(e.getUser(), EntityType.DOCUMENT)));
result.setDocumentVersion(e.getVersion());

result.setParameters(e.getParameters());
return result;
}
}
Expand Up @@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.plugin.activitystream.api.ActivityEvent;
Expand Down Expand Up @@ -131,6 +132,11 @@ public class ActivityEventImpl implements ActivityEvent
*/
private String param5 = "";

/**
* Named parameters.
*/
private Map<String, String> parameters;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -522,4 +528,20 @@ public void setApplication(String application)
{
this.application = application;
}

/**
* {@inheritDoc}
*/
public void setParameters(Map<String, String> parameters)
{
this.parameters = parameters;
}

/**
* {@inheritDoc}
*/
public Map<String, String> getParameters()
{
return this.parameters;
}
}
Expand Up @@ -23,6 +23,7 @@
import com.xpn.xwiki.XWikiContext;

import java.util.Date;
import java.util.Map;

/**
* Api wrapper for a {@link com.xpn.xwiki.plugin.activitystream.api.ActivityEvent} to be exposed from velocity.
Expand Down Expand Up @@ -264,6 +265,14 @@ public String getDisplayUser()
return event.getDisplayUser(context);
}

/**
* @return the parameters associated with the event
*/
public Map<String, String> getParameters()
{
return event.getParameters();
}

/**
* @return the wrapped event
*/
Expand Down
Expand Up @@ -27,5 +27,10 @@
<property name="param3" type="string" column="ase_param3" length="2000" />
<property name="param4" type="string" column="ase_param4" length="2000" />
<property name="param5" type="string" column="ase_param5" length="2000" />
<map name="parameters" table="activitystream_events_parameters" lazy="false">
<key column="eventId"/>
<index column="name" type="string"/>
<element column="value" type="string"/>
</map>
</class>
</hibernate-mapping>
Expand Up @@ -22,6 +22,7 @@

import java.net.URL;
import java.util.Date;
import java.util.Map;

import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.EntityReference;
Expand All @@ -45,7 +46,8 @@
* Events contain:
* <ul>
* <li>a {@link #getTitle() title}</li>
* <li>and a {@link #getBody() body}</li>
* <li>a {@link #getBody() body}</li>
* <li>and a map of {@link #getParameters()} parameters</li>

This comment has been minimized.

Copy link
@sdumitriu

sdumitriu Aug 12, 2011

Member

The closing } should be right before /li

* </ul>
* </p>
* <p>
Expand Down Expand Up @@ -333,4 +335,15 @@ enum Importance
* @see #getDocumentTitle()
*/
void setDocumentTitle(String title);

/**
* @return the named parameters associated with this event as key/value pairs.
*/
Map<String, String> getParameters();

/**
* @param parameters the parameters to associate to the event.
* @see #getParameters()
*/
void setParameters(Map<String, String> parameters);
}
Expand Up @@ -22,7 +22,9 @@

import java.net.URL;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Map;

import org.xwiki.eventstream.Event;
import org.xwiki.model.reference.DocumentReference;
Expand Down Expand Up @@ -92,6 +94,9 @@ public class DefaultEvent implements Event
/** @see #getBody() */
private String body;

/** @see #getParameters() */
private Map<String, String> parameters;

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -467,6 +472,27 @@ public void setDocumentTitle(String title)
this.documentTitle = title;
}

/**
* {@inheritDoc}
*
* @see Event#getParameters()
*/
public Map<String, String> getParameters()

This comment has been minimized.

Copy link
@sdumitriu

sdumitriu Aug 12, 2011

Member

I wonder if the returned map should be read-only? Collections.emptyMap does return an immutable map, so we should not allow the caller to try to modify it.

{
return this.parameters == null ? Collections.<String, String> emptyMap() : this.parameters;
}

/**
* {@inheritDoc}
*
* @see Event#setParameters(Map)
* @see #getParameters()
*/
public void setParameters(Map<String, String> parameters)

This comment has been minimized.

Copy link
@sdumitriu

sdumitriu Aug 12, 2011

Member

Should clone the map, so that it's free of side effects if the caller code modifies the map afterwards.

{
this.parameters = parameters;
}

/**
* {@inheritDoc}
*/
Expand Down

1 comment on commit 835d75f

@jvelo
Copy link
Contributor

@jvelo jvelo commented on 835d75f Aug 12, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, pushed fixes following your remarks

Please sign in to comment.