Activity Service - add REST API for User Feed Controls & general cleanup/fixes

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9187 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka 2008-05-20 16:41:10 +00:00
parent cecd138ed6
commit f0883f987f
9 changed files with 113 additions and 7 deletions

View File

@ -65,6 +65,7 @@
<property name="postDaoService" ref="postDaoService"/> <property name="postDaoService" ref="postDaoService"/>
<property name="authenticationService" ref="AuthenticationService"/> <property name="authenticationService" ref="AuthenticationService"/>
<property name="repoEndPoint" value="${repo.remote.endpoint.url}"/> <property name="repoEndPoint" value="${repo.remote.endpoint.url}"/>
<property name="userNamesAreCaseSensitive" value="${user.name.caseSensitive}"/>
<property name="maxItemsPerCycle" value="100"/> <property name="maxItemsPerCycle" value="100"/>
</bean> </bean>

View File

@ -456,7 +456,7 @@ public class ActivityServiceImpl implements ActivityService
} }
catch (SQLException e) catch (SQLException e)
{ {
throw new AlfrescoRuntimeException("Failed to set feed control: " + e, e); throw new AlfrescoRuntimeException("Failed to get feed controls: " + e, e);
} }
} }
@ -479,7 +479,7 @@ public class ActivityServiceImpl implements ActivityService
} }
catch (SQLException e) catch (SQLException e)
{ {
throw new AlfrescoRuntimeException("Failed to set feed control: " + e, e); throw new AlfrescoRuntimeException("Failed to unset feed control: " + e, e);
} }
} }

View File

@ -48,6 +48,8 @@ public abstract class AbstractFeedGenerator implements FeedGenerator
private String repoEndPoint; // http://hostname:port/webapp (eg. http://localhost:8080/alfresco) private String repoEndPoint; // http://hostname:port/webapp (eg. http://localhost:8080/alfresco)
private boolean userNamesAreCaseSensitive = false;
private RepoCtx ctx = null; private RepoCtx ctx = null;
private boolean busy; private boolean busy;
@ -67,6 +69,11 @@ public abstract class AbstractFeedGenerator implements FeedGenerator
this.repoEndPoint = repoEndPoint; this.repoEndPoint = repoEndPoint;
} }
public void setUserNamesAreCaseSensitive(boolean userNamesAreCaseSensitive)
{
this.userNamesAreCaseSensitive = userNamesAreCaseSensitive;
}
public void setMaxItemsPerCycle(int maxItemsPerCycle) public void setMaxItemsPerCycle(int maxItemsPerCycle)
{ {
this.maxItemsPerCycle = maxItemsPerCycle; this.maxItemsPerCycle = maxItemsPerCycle;
@ -95,6 +102,7 @@ public abstract class AbstractFeedGenerator implements FeedGenerator
public void init() throws Exception public void init() throws Exception
{ {
ctx = new RepoCtx(repoEndPoint); ctx = new RepoCtx(repoEndPoint);
ctx.setUserNamesAreCaseSensitive(userNamesAreCaseSensitive);
busy = false; busy = false;
} }

View File

@ -408,6 +408,12 @@ public abstract class FeedTaskProcessor
{ {
JSONObject member = (JSONObject)ja.get(i); JSONObject member = (JSONObject)ja.get(i);
JSONObject person = (JSONObject)member.getJSONObject("person"); JSONObject person = (JSONObject)member.getJSONObject("person");
String userName = person.getString("userName");
if (! ctx.isUserNamesAreCaseSensitive())
{
userName = userName.toLowerCase();
}
members.add(person.getString("userName")); members.add(person.getString("userName"));
} }
} }
@ -523,7 +529,7 @@ public abstract class FeedTaskProcessor
for (FeedControlDAO feedControl : feedControls) for (FeedControlDAO feedControl : feedControls)
{ {
if ((feedControl.getSiteNetwork() == null) && (feedControl.getAppTool() != null)) if (((feedControl.getSiteNetwork() == null) || (feedControl.getSiteNetwork().length() == 0)) && (feedControl.getAppTool() != null))
{ {
if (feedControl.getAppTool().equals(activityPost.getAppTool())) if (feedControl.getAppTool().equals(activityPost.getAppTool()))
{ {
@ -531,7 +537,7 @@ public abstract class FeedTaskProcessor
return false; return false;
} }
} }
else if ((feedControl.getAppTool() == null) && (feedControl.getSiteNetwork() != null)) else if (((feedControl.getAppTool() == null) || (feedControl.getAppTool().length() == 0)) && (feedControl.getSiteNetwork() != null))
{ {
if (feedControl.getSiteNetwork().equals(activityPost.getSiteNetwork())) if (feedControl.getSiteNetwork().equals(activityPost.getSiteNetwork()))
{ {
@ -539,7 +545,8 @@ public abstract class FeedTaskProcessor
return false; return false;
} }
} }
else if ((feedControl.getSiteNetwork() != null) && (feedControl.getAppTool() != null)) else if (((feedControl.getSiteNetwork() != null) && (feedControl.getSiteNetwork().length() > 0)) &&
((feedControl.getAppTool() != null) && (feedControl.getAppTool().length() > 0)))
{ {
if ((feedControl.getSiteNetwork().equals(activityPost.getSiteNetwork())) && if ((feedControl.getSiteNetwork().equals(activityPost.getSiteNetwork())) &&
(feedControl.getAppTool().equals(activityPost.getAppTool()))) (feedControl.getAppTool().equals(activityPost.getAppTool())))

View File

@ -32,6 +32,8 @@ import java.io.Serializable;
public class RepoCtx implements Serializable public class RepoCtx implements Serializable
{ {
private String repoEndPoint; // http://hostname:port/webapp (eg. http://localhost:8080/alfresco) private String repoEndPoint; // http://hostname:port/webapp (eg. http://localhost:8080/alfresco)
private boolean userNamesAreCaseSensitive = false;
private String ticket; private String ticket;
public static final long serialVersionUID = -3896042917378679686L; public static final long serialVersionUID = -3896042917378679686L;
@ -54,4 +56,14 @@ public class RepoCtx implements Serializable
{ {
this.ticket = ticket; this.ticket = ticket;
} }
public boolean isUserNamesAreCaseSensitive()
{
return userNamesAreCaseSensitive;
}
public void setUserNamesAreCaseSensitive(boolean userNamesAreCaseSensitive)
{
this.userNamesAreCaseSensitive = userNamesAreCaseSensitive;
}
} }

View File

@ -24,8 +24,11 @@
*/ */
package org.alfresco.repo.activities.script; package org.alfresco.repo.activities.script;
import java.util.List;
import org.alfresco.repo.jscript.BaseScopableProcessorExtension; import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.service.cmr.activities.ActivityService; import org.alfresco.service.cmr.activities.ActivityService;
import org.alfresco.service.cmr.activities.FeedControl;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
@ -47,6 +50,11 @@ public final class Activity extends BaseScopableProcessorExtension
this.activityService = activityService; this.activityService = activityService;
} }
/*
* Post Activity
*/
/** /**
* Post a custom activity type * Post a custom activity type
* *
@ -108,4 +116,42 @@ public final class Activity extends BaseScopableProcessorExtension
{ {
activityService.postActivity(activityType, siteId, appTool, nodeRef, name, typeQName, parentNodeRef); activityService.postActivity(activityType, siteId, appTool, nodeRef, name, typeQName, parentNodeRef);
} }
/*
* Manage User Feed Controls
*/
/**
* For current user, get feed controls
*
* @return array of user feed controls
*/
public FeedControl[] getFeedControls()
{
List<FeedControl> feedControls = activityService.getFeedControls();
return (FeedControl[])feedControls.toArray(new FeedControl[feedControls.size()]);
}
/**
* For current user, set feed control (opt-out) for a site or an appTool or a site/appTool combination
*
* @param siteId - required (optional, if appToolId is supplied)
* @param appToolId - required (optional, if siteId is supplied)
*/
public void setFeedControl(String siteId, String appToolId)
{
activityService.setFeedControl(new FeedControl(siteId, appToolId));
}
/**
* For current user, unset feed control
*
* @param siteId - required (optional, if appToolId is supplied)
* @param appToolId - required (optional, if siteId is supplied)
*/
public void unsetFeedControl(String siteId, String appToolId)
{
activityService.unsetFeedControl(new FeedControl(siteId, appToolId));
}
} }

View File

@ -12,6 +12,33 @@ activities.postActivity("test activity type 5", "my site", null, '{ "item2" : 45
activities.postActivity("test activity type 6", "my site", "my app tool", '{ "item3" : 789 }'); activities.postActivity("test activity type 6", "my site", "my app tool", '{ "item3" : 789 }');
activities.postActivity("test activity type 7", "my site", "my app tool", '{ invalidJSON }'); activities.postActivity("test activity type 7", "my site", "my app tool", '{ invalidJSON }');
// user feed controls
var feedControls = activities.getFeedControls();
test.assertEquals(0, feedControls.length);
activities.setFeedControl("my site", "my app tool");
feedControls = activities.getFeedControls();
test.assertEquals(1, feedControls.length);
activities.setFeedControl("my site", null);
feedControls = activities.getFeedControls();
test.assertEquals(2, feedControls.length);
activities.setFeedControl("", "my app tool");
feedControls = activities.getFeedControls();
test.assertEquals(3, feedControls.length);
activities.unsetFeedControl("my site", "my app tool");
activities.unsetFeedControl("my site", "");
activities.unsetFeedControl(null, "my app tool");
feedControls = activities.getFeedControls();
test.assertEquals(0, feedControls.length);
failure = ""; failure = "";

View File

@ -116,7 +116,7 @@ public interface ActivityService
*/ */
/** /**
* For current user, set feed control (opt-out) for a site or an appTool or a site/appTool * For current user, set feed control (opt-out) for a site or an appTool or a site/appTool combination
* *
* @param feedControl - required * @param feedControl - required
*/ */

View File

@ -24,11 +24,16 @@
*/ */
package org.alfresco.service.cmr.activities; package org.alfresco.service.cmr.activities;
public class FeedControl import java.io.Serializable;
public class FeedControl implements Serializable
{ {
private static final long serialVersionUID = -1934566916718472843L;
private String siteId; private String siteId;
private String appToolId; private String appToolId;
public FeedControl(String siteId, String appToolId) public FeedControl(String siteId, String appToolId)
{ {
if (siteId == null) siteId = ""; if (siteId == null) siteId = "";