mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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:
@@ -0,0 +1,9 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Activity User Feed Controls</shortname>
|
||||||
|
<description>Unset activity feed control (opt-out) for currently logged in user.</description>
|
||||||
|
<url>/api/activities/feed/user/control?s={siteId}&a={appToolId}</url>
|
||||||
|
<url>/api/activities/feed/user/control??s={siteId}&a={appToolId}&format=json</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -0,0 +1,20 @@
|
|||||||
|
function main()
|
||||||
|
{
|
||||||
|
// Get the details of the site id (site shortname) and/or appTool id
|
||||||
|
var siteId = args["s"];
|
||||||
|
var appToolId = args["a"];
|
||||||
|
|
||||||
|
if ((siteId == null || siteId.length == 0) &&
|
||||||
|
(appToolId == null || appToolId.length == 0))
|
||||||
|
{
|
||||||
|
status.code = 400;
|
||||||
|
status.message = "siteId and appToolId are both missing - must supply one or both.";
|
||||||
|
status.redirect = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unset feed control for current user
|
||||||
|
activities.unsetFeedControl(siteId, appToolId);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -0,0 +1,9 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Activity User Feed Controls</shortname>
|
||||||
|
<description>Set activity feed control (opt-out) for currently logged in user.</description>
|
||||||
|
<url>/api/activities/feed/user/control</url>
|
||||||
|
<url>/api/activities/feed/user/control?format=json</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -0,0 +1,30 @@
|
|||||||
|
function main()
|
||||||
|
{
|
||||||
|
// Get the details of the site id (site shortname) and/or appTool id
|
||||||
|
var siteId = null;
|
||||||
|
var appToolId = null;
|
||||||
|
|
||||||
|
if (! json.isNull("siteId"))
|
||||||
|
{
|
||||||
|
siteId = json.get("siteId");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! json.isNull("appToolId"))
|
||||||
|
{
|
||||||
|
appToolId = json.get("appToolId");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((siteId == null || siteId.length == 0) &&
|
||||||
|
(appToolId == null || appToolId.length == 0))
|
||||||
|
{
|
||||||
|
status.code = 400;
|
||||||
|
status.message = "siteId and appToolId are both missing - must supply one or both.";
|
||||||
|
status.redirect = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set feed control for current user
|
||||||
|
activities.setFeedControl(siteId, appToolId);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
@@ -0,0 +1,9 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Activity User Feed Controls</shortname>
|
||||||
|
<description>Get the activity feed controls (opt-outs) for currently logged in user.</description>
|
||||||
|
<url>/api/activities/feed/user/controls</url>
|
||||||
|
<url>/api/activities/feed/user/controls?format=json</url>
|
||||||
|
<format default="json"/>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -0,0 +1,5 @@
|
|||||||
|
// Get the list of feed controls for current user
|
||||||
|
var feedControls = activities.getFeedControls();
|
||||||
|
|
||||||
|
// Pass the queried feed controls to the template
|
||||||
|
model.feedControls = feedControls;
|
@@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
<#if feedControls??>
|
||||||
|
<#list feedControls as feedControl>
|
||||||
|
${feedControl}<#if feedControl_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
</#if>
|
||||||
|
]
|
@@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
<#if feedEntries??>
|
||||||
|
<#list feedEntries as feedEntry>
|
||||||
|
${feedEntry}<#if feedEntry_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
</#if>
|
||||||
|
]
|
@@ -227,17 +227,17 @@
|
|||||||
<!-- -->
|
<!-- -->
|
||||||
|
|
||||||
<!-- Activity User Feed - to get activities feed for logged in user -->
|
<!-- Activity User Feed - to get activities feed for logged in user -->
|
||||||
<bean id="webscript.org.alfresco.repository.activities.userfeed.get" class="org.alfresco.repo.web.scripts.activities.UserFeedRetrieverWebScript" parent="webscript">
|
<bean id="webscript.org.alfresco.repository.activities.feed.userfeed.get" class="org.alfresco.repo.web.scripts.activities.feed.UserFeedRetrieverWebScript" parent="webscript">
|
||||||
<property name="activityService" ref="activityService"/>
|
<property name="activityService" ref="activityService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Activity Admin Feed - to get activities feed for specified user -->
|
<!-- Activity Admin Feed - to get activities feed for specified user -->
|
||||||
<bean id="webscript.org.alfresco.repository.activities.userfeed-admin.get" class="org.alfresco.repo.web.scripts.activities.UserFeedRetrieverWebScript" parent="webscript">
|
<bean id="webscript.org.alfresco.repository.activities.feed.userfeed-admin.get" class="org.alfresco.repo.web.scripts.activities.feed.UserFeedRetrieverWebScript" parent="webscript">
|
||||||
<property name="activityService" ref="activityService"/>
|
<property name="activityService" ref="activityService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- Activity Site Feed - to get activities feed for given site, if private site then need to be a member or admin -->
|
<!-- Activity Site Feed - to get activities feed for given site, if private site then need to be a member or admin -->
|
||||||
<bean id="webscript.org.alfresco.repository.activities.sitefeed.get" class="org.alfresco.repo.web.scripts.activities.SiteFeedRetrieverWebScript" parent="webscript">
|
<bean id="webscript.org.alfresco.repository.activities.feed.sitefeed.get" class="org.alfresco.repo.web.scripts.activities.feed.SiteFeedRetrieverWebScript" parent="webscript">
|
||||||
<property name="activityService" ref="activityService"/>
|
<property name="activityService" ref="activityService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
@@ -75,15 +75,27 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
private static final String URL_ACTIVITIES = "/api/activities";
|
private static final String URL_ACTIVITIES = "/api/activities";
|
||||||
private static final String URL_SITE_FEED = "/feed/site";
|
private static final String URL_SITE_FEED = "/feed/site";
|
||||||
private static final String URL_USER_FEED = "/feed/user";
|
private static final String URL_USER_FEED = "/feed/user";
|
||||||
|
private static final String URL_USER_FEED_CTRL = "/feed/user/control";
|
||||||
|
|
||||||
|
// Users & Passwords
|
||||||
|
private static final String ADMIN_USER = "admin";
|
||||||
|
private static final String ADMIN_PW = "admin";
|
||||||
|
|
||||||
private static boolean setup = false;
|
|
||||||
|
|
||||||
private static String shortName = null;
|
|
||||||
private static String user1 = null;
|
private static String user1 = null;
|
||||||
private static String user2 = null;
|
private static String user2 = null;
|
||||||
private static String user3 = null;
|
private static String user3 = null;
|
||||||
|
|
||||||
|
private static final String USER_PW = "password";
|
||||||
|
|
||||||
|
// Test siteId
|
||||||
|
private static String shortName = null;
|
||||||
|
|
||||||
|
// Site Service appToolId
|
||||||
|
private static String appToolId = "siteService"; // refer to SiteService
|
||||||
|
|
||||||
|
private static boolean setup = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public SiteActivitySystemTest()
|
public SiteActivitySystemTest()
|
||||||
{
|
{
|
||||||
@@ -105,9 +117,9 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
|
|
||||||
// pre-create users
|
// pre-create users
|
||||||
|
|
||||||
createUser(user1, "password");
|
createUser(user1, USER_PW);
|
||||||
createUser(user2, "password");
|
createUser(user2, USER_PW);
|
||||||
createUser(user3, "password");
|
createUser(user3, USER_PW);
|
||||||
|
|
||||||
setup = true;
|
setup = true;
|
||||||
}
|
}
|
||||||
@@ -122,7 +134,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
|
|
||||||
public void testCreateSite() throws Exception
|
public void testCreateSite() throws Exception
|
||||||
{
|
{
|
||||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, "admin", "admin");
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||||
|
|
||||||
JSONObject site = new JSONObject();
|
JSONObject site = new JSONObject();
|
||||||
site.put("sitePreset", "myPreset");
|
site.put("sitePreset", "myPreset");
|
||||||
@@ -147,7 +159,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
{
|
{
|
||||||
// relies on testCreateSite
|
// relies on testCreateSite
|
||||||
|
|
||||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, "admin", "admin");
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||||
|
|
||||||
String url = WEBSCRIPT_ENDPOINT + URL_SITES + "/" + shortName;
|
String url = WEBSCRIPT_ENDPOINT + URL_SITES + "/" + shortName;
|
||||||
String response = callGetWebScript(url, ticket);
|
String response = callGetWebScript(url, ticket);
|
||||||
@@ -165,7 +177,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
{
|
{
|
||||||
// relies on testCreateSite
|
// relies on testCreateSite
|
||||||
|
|
||||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, "admin", "admin");
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||||
|
|
||||||
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_SITE_FEED + "/" + shortName + "?format=json";
|
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_SITE_FEED + "/" + shortName + "?format=json";
|
||||||
String jsonArrayResult = callGetWebScript(url, ticket);
|
String jsonArrayResult = callGetWebScript(url, ticket);
|
||||||
@@ -185,7 +197,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
{
|
{
|
||||||
// relies on testCreateSite
|
// relies on testCreateSite
|
||||||
|
|
||||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, "admin", "admin");
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||||
|
|
||||||
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_USER_FEED + "/" + user1 + "?format=json";
|
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_USER_FEED + "/" + user1 + "?format=json";
|
||||||
String jsonArrayResult = callGetWebScript(url, ticket);
|
String jsonArrayResult = callGetWebScript(url, ticket);
|
||||||
@@ -227,29 +239,43 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUserFeedControls() throws Exception
|
||||||
|
{
|
||||||
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, user1, USER_PW);
|
||||||
|
addFeedControl(user1, shortName, null, ticket);
|
||||||
|
|
||||||
|
ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, user2, USER_PW);
|
||||||
|
addFeedControl(user2, null, appToolId, ticket);
|
||||||
|
|
||||||
|
//ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, user2, USER_PW);
|
||||||
|
//addFeedControl(user3, shortName, appToolId, ticket);
|
||||||
|
|
||||||
|
// TODO add more here, once we have more appToolIds
|
||||||
|
}
|
||||||
|
|
||||||
public void testMemberships() throws Exception
|
public void testMemberships() throws Exception
|
||||||
{
|
{
|
||||||
// relies on testCreateSite
|
// relies on testCreateSite
|
||||||
|
|
||||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, "admin", "admin");
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||||
|
|
||||||
// add member -> join site
|
// add member -> join site
|
||||||
testAddMembership(user1, ticket, SiteModel.SITE_CONSUMER);
|
addMembership(user1, ticket, SiteModel.SITE_CONSUMER);
|
||||||
testAddMembership(user2, ticket, SiteModel.SITE_MANAGER);
|
addMembership(user2, ticket, SiteModel.SITE_MANAGER);
|
||||||
testAddMembership(user3, ticket, SiteModel.SITE_COLLABORATOR);
|
addMembership(user3, ticket, SiteModel.SITE_COLLABORATOR);
|
||||||
|
|
||||||
// update member -> change role
|
// update member -> change role
|
||||||
testUpdateMembership(user1, ticket, SiteModel.SITE_MANAGER);
|
updateMembership(user1, ticket, SiteModel.SITE_MANAGER);
|
||||||
testUpdateMembership(user2, ticket, SiteModel.SITE_COLLABORATOR);
|
updateMembership(user2, ticket, SiteModel.SITE_COLLABORATOR);
|
||||||
testUpdateMembership(user3, ticket, SiteModel.SITE_CONSUMER);
|
updateMembership(user3, ticket, SiteModel.SITE_CONSUMER);
|
||||||
|
|
||||||
// add pause - otherwise, activity service will not generate feed entries (since they will have already left the site)
|
// add pause - otherwise, activity service will not generate feed entries (since they will have already left the site)
|
||||||
Thread.sleep(90000); // 1 min
|
Thread.sleep(90000); // 1 min
|
||||||
|
|
||||||
// remove member -> leave site
|
// remove member -> leave site
|
||||||
testRemoveMembership(user1, ticket);
|
removeMembership(user1, ticket);
|
||||||
testRemoveMembership(user2, ticket);
|
removeMembership(user2, ticket);
|
||||||
testRemoveMembership(user3, ticket);
|
removeMembership(user3, ticket);
|
||||||
|
|
||||||
// add pause
|
// add pause
|
||||||
Thread.sleep(60000); // 1 min
|
Thread.sleep(60000); // 1 min
|
||||||
@@ -259,7 +285,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
{
|
{
|
||||||
// relies on testCreateSite, testMemberships
|
// relies on testCreateSite, testMemberships
|
||||||
|
|
||||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, "admin", "admin");
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||||
|
|
||||||
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_SITE_FEED + "/" + shortName + "?format=json";
|
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_SITE_FEED + "/" + shortName + "?format=json";
|
||||||
String jsonArrayResult = callGetWebScript(url, ticket);
|
String jsonArrayResult = callGetWebScript(url, ticket);
|
||||||
@@ -287,7 +313,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
{
|
{
|
||||||
// relies on testCreateSite, testMemberships
|
// relies on testCreateSite, testMemberships
|
||||||
|
|
||||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, "admin", "admin");
|
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||||
|
|
||||||
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_USER_FEED + "/" + user1 + "?format=json";
|
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_USER_FEED + "/" + user1 + "?format=json";
|
||||||
String jsonArrayResult = callGetWebScript(url, ticket);
|
String jsonArrayResult = callGetWebScript(url, ticket);
|
||||||
@@ -303,7 +329,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
if (jsonArrayResult != null)
|
if (jsonArrayResult != null)
|
||||||
{
|
{
|
||||||
JSONArray ja = new JSONArray(jsonArrayResult);
|
JSONArray ja = new JSONArray(jsonArrayResult);
|
||||||
assertEquals(6, ja.length());
|
assertEquals(0, ja.length()); // 0 due to feed control
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -324,7 +350,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
if (jsonArrayResult != null)
|
if (jsonArrayResult != null)
|
||||||
{
|
{
|
||||||
JSONArray ja = new JSONArray(jsonArrayResult);
|
JSONArray ja = new JSONArray(jsonArrayResult);
|
||||||
assertEquals(6, ja.length());
|
assertEquals(0, ja.length()); // 0 due to feed control
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -353,7 +379,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testAddMembership(String userName, String ticket, String role) throws Exception
|
private void addMembership(String userName, String ticket, String role) throws Exception
|
||||||
{
|
{
|
||||||
// Build the JSON membership object
|
// Build the JSON membership object
|
||||||
JSONObject membership = new JSONObject();
|
JSONObject membership = new JSONObject();
|
||||||
@@ -367,14 +393,14 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("testAddMembership: " + userName);
|
logger.debug("addMembership: " + userName);
|
||||||
logger.debug("------------------");
|
logger.debug("--------------");
|
||||||
logger.debug(url);
|
logger.debug(url);
|
||||||
logger.debug(response);
|
logger.debug(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testUpdateMembership(String userName, String ticket, String role) throws Exception
|
private void updateMembership(String userName, String ticket, String role) throws Exception
|
||||||
{
|
{
|
||||||
// Build the JSON membership object
|
// Build the JSON membership object
|
||||||
JSONObject membership = new JSONObject();
|
JSONObject membership = new JSONObject();
|
||||||
@@ -388,22 +414,41 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("testUpdateMembership: " + userName);
|
logger.debug("updateMembership: " + userName);
|
||||||
logger.debug("------------------");
|
logger.debug("-----------------");
|
||||||
logger.debug(url);
|
logger.debug(url);
|
||||||
logger.debug(response);
|
logger.debug(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testRemoveMembership(String userName, String ticket) throws Exception
|
private void removeMembership(String userName, String ticket) throws Exception
|
||||||
{
|
{
|
||||||
String url = WEBSCRIPT_ENDPOINT + URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + userName;
|
String url = WEBSCRIPT_ENDPOINT + URL_SITES + "/" + shortName + URL_MEMBERSHIPS + "/" + userName;
|
||||||
String response = callDeleteWebScript(url, ticket);
|
String response = callDeleteWebScript(url, ticket);
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("testRemoveMembership: " + userName);
|
logger.debug("removeMembership: " + userName);
|
||||||
logger.debug("---------------------");
|
logger.debug("-----------------");
|
||||||
|
logger.debug(url);
|
||||||
|
logger.debug(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addFeedControl(String userName, String siteId, String appToolId, String ticket) throws Exception
|
||||||
|
{
|
||||||
|
// Build the JSON feedControl object
|
||||||
|
JSONObject feedControl = new JSONObject();
|
||||||
|
feedControl.put("siteId", siteId);
|
||||||
|
feedControl.put("appToolId", appToolId);
|
||||||
|
|
||||||
|
String url = WEBSCRIPT_ENDPOINT + URL_ACTIVITIES + URL_USER_FEED_CTRL;
|
||||||
|
String response = callPostWebScript(url, ticket, feedControl.toString());
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("addFeedControl: " + userName);
|
||||||
|
logger.debug("--------------");
|
||||||
logger.debug(url);
|
logger.debug(url);
|
||||||
logger.debug(response);
|
logger.debug(response);
|
||||||
}
|
}
|
||||||
@@ -563,7 +608,7 @@ public class SiteActivitySystemTest extends TestCase
|
|||||||
|
|
||||||
protected void createUser(String username, String password) throws MalformedURLException, URISyntaxException, IOException
|
protected void createUser(String username, String password) throws MalformedURLException, URISyntaxException, IOException
|
||||||
{
|
{
|
||||||
String ticket = webServiceStartSession("admin", "admin");
|
String ticket = webServiceStartSession(ADMIN_USER, ADMIN_PW);
|
||||||
webServiceCreateUser(username, password, ticket);
|
webServiceCreateUser(username, password, ticket);
|
||||||
webServiceEndSession(ticket);
|
webServiceEndSession(ticket);
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@
|
|||||||
* the FLOSS exception, and it is also available here:
|
* the FLOSS exception, and it is also available here:
|
||||||
* http://www.alfresco.com/legal/licensing
|
* http://www.alfresco.com/legal/licensing
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.web.scripts.activities;
|
package org.alfresco.repo.web.scripts.activities.feed;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
@@ -22,7 +22,7 @@
|
|||||||
* the FLOSS exception, and it is also available here:
|
* the FLOSS exception, and it is also available here:
|
||||||
* http://www.alfresco.com/legal/licensing
|
* http://www.alfresco.com/legal/licensing
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.web.scripts.activities;
|
package org.alfresco.repo.web.scripts.activities.feed;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
@@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2008 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
* This program 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 General Public License for more details.
|
||||||
|
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
* As a special exception to the terms and conditions of version 2.0 of
|
||||||
|
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||||
|
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||||
|
* FLOSS exception. You should have recieved a copy of the text describing
|
||||||
|
* the FLOSS exception, and it is also available here:
|
||||||
|
* http://www.alfresco.com/legal/licensing"
|
||||||
|
*/
|
||||||
|
package org.alfresco.repo.web.scripts.activities.feed.control;
|
||||||
|
|
||||||
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
|
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||||
|
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||||
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.util.PropertyMap;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.springframework.mock.web.MockHttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test the Activity Service's User Feed Control Web Script API
|
||||||
|
*
|
||||||
|
* @author janv
|
||||||
|
*/
|
||||||
|
public class FeedControlTest extends BaseWebScriptTest
|
||||||
|
{
|
||||||
|
private static Log logger = LogFactory.getLog(FeedControlTest.class);
|
||||||
|
|
||||||
|
private AuthenticationService authenticationService;
|
||||||
|
private AuthenticationComponent authenticationComponent;
|
||||||
|
private PersonService personService;
|
||||||
|
|
||||||
|
private static final String TEST_USER = "my user";
|
||||||
|
|
||||||
|
private static final String TEST_SITE_ID = "my site";
|
||||||
|
private static final String TEST_APP_TOOL_ID = "my app tool";
|
||||||
|
|
||||||
|
private static final String URL_CONTROLS = "/api/activities/feed/user/controls";
|
||||||
|
private static final String URL_CONTROL = "/api/activities/feed/user/control";
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
||||||
|
this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
|
||||||
|
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
||||||
|
|
||||||
|
this.authenticationComponent.setCurrentUser("admin");
|
||||||
|
|
||||||
|
// Create users
|
||||||
|
createUser(TEST_USER);
|
||||||
|
|
||||||
|
// Do tests as user one
|
||||||
|
this.authenticationComponent.setCurrentUser(TEST_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createUser(String userName)
|
||||||
|
{
|
||||||
|
if (this.authenticationService.authenticationExists(userName) == false)
|
||||||
|
{
|
||||||
|
this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
|
||||||
|
|
||||||
|
PropertyMap ppOne = new PropertyMap(4);
|
||||||
|
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
||||||
|
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
|
||||||
|
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
|
||||||
|
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
|
||||||
|
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
|
||||||
|
|
||||||
|
this.personService.createPerson(ppOne);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void tearDown() throws Exception
|
||||||
|
{
|
||||||
|
super.tearDown();
|
||||||
|
|
||||||
|
this.authenticationComponent.clearCurrentSecurityContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreateFeedControls() throws Exception
|
||||||
|
{
|
||||||
|
createFeedControl(TEST_SITE_ID, null);
|
||||||
|
createFeedControl(null, TEST_APP_TOOL_ID);
|
||||||
|
createFeedControl(TEST_SITE_ID, TEST_APP_TOOL_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createFeedControl(String siteId, String appToolId) throws Exception
|
||||||
|
{
|
||||||
|
// Set (create) feed control
|
||||||
|
JSONObject feedControl = new JSONObject();
|
||||||
|
feedControl.put("siteId", siteId);
|
||||||
|
feedControl.put("appToolId", appToolId);
|
||||||
|
|
||||||
|
int expectedStatus = 200;
|
||||||
|
MockHttpServletResponse response = postRequest(URL_CONTROL, expectedStatus, feedControl.toString(), "application/json");
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRetrieveFeedControls() throws Exception
|
||||||
|
{
|
||||||
|
// Get (retrieve) feed controls
|
||||||
|
int expectedStatus = 200;
|
||||||
|
MockHttpServletResponse response = getRequest(URL_CONTROLS, expectedStatus);
|
||||||
|
JSONArray result = new JSONArray(response.getContentAsString());
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNotNull(result);
|
||||||
|
assertEquals(3, result.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteFeedControls() throws Exception
|
||||||
|
{
|
||||||
|
deleteFeedControl(TEST_SITE_ID, null);
|
||||||
|
deleteFeedControl(null, TEST_APP_TOOL_ID);
|
||||||
|
deleteFeedControl(TEST_SITE_ID, TEST_APP_TOOL_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deleteFeedControl(String siteId, String appToolId) throws Exception
|
||||||
|
{
|
||||||
|
// Unset (delete) feed control
|
||||||
|
int expectedStatus = 200;
|
||||||
|
MockHttpServletResponse response = deleteRequest(URL_CONTROL + "?s=" + TEST_SITE_ID + "&a=" + TEST_APP_TOOL_ID, expectedStatus);
|
||||||
|
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user