mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
MOB-822 - Activity feed generator - optimise to use embedded calls (as alternative to existing remote repo callbacks)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14163 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -97,12 +97,14 @@ public class SiteActivitySystemTest extends TestCase
|
||||
// AppToolId for site membership activities
|
||||
private static String appToolId = "siteService"; // refer to SiteService
|
||||
|
||||
private static int DELAY_MSECS = 120000; // 2 mins
|
||||
|
||||
private static boolean setup = false;
|
||||
private static boolean sitesCreated = false;
|
||||
private static boolean membersAddedUpdated = false;
|
||||
private static boolean membersRemoved = false;
|
||||
private static boolean controlsCreated = false;
|
||||
|
||||
|
||||
|
||||
public SiteActivitySystemTest()
|
||||
{
|
||||
@@ -144,6 +146,12 @@ public class SiteActivitySystemTest extends TestCase
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testLogin() throws Exception
|
||||
{
|
||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||
assertNotNull(ticket);
|
||||
}
|
||||
|
||||
public void testCreateSites() throws Exception
|
||||
{
|
||||
if (! sitesCreated)
|
||||
@@ -334,7 +342,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
append(excludeThisUser ? UserFeedRetrieverWebScript.PARAM_EXCLUDE_THIS_USER + "=true&" : ""). // optional
|
||||
append(excludeOtherUsers ? UserFeedRetrieverWebScript.PARAM_EXCLUDE_OTHER_USERS + "=true&" : ""). // optional
|
||||
append("format=json");
|
||||
|
||||
|
||||
String url = sb.toString();
|
||||
String jsonArrayResult = callGetWebScript(url, ticket);
|
||||
|
||||
@@ -372,7 +380,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
// user 3 opts out of site membership activities for site 1 only
|
||||
ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, user3, USER_PW);
|
||||
addFeedControl(user3, site1, appToolId, ticket);
|
||||
|
||||
|
||||
// TODO add more here, once we have more appToolIds
|
||||
|
||||
controlsCreated = true;
|
||||
@@ -392,7 +400,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
addAndUpdateMemberships(site3, ticket, false); // private site, do not include user 4
|
||||
|
||||
// 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(DELAY_MSECS);
|
||||
|
||||
membersAddedUpdated = true;
|
||||
}
|
||||
@@ -433,13 +441,13 @@ public class SiteActivitySystemTest extends TestCase
|
||||
testAddAndUpdateMembershipsWithPause();
|
||||
|
||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||
|
||||
|
||||
removeMemberships(site1, ticket, true);
|
||||
removeMemberships(site2, ticket, true);
|
||||
removeMemberships(site3, ticket, false);
|
||||
|
||||
// add pause
|
||||
Thread.sleep(60000); // 1 min
|
||||
Thread.sleep(DELAY_MSECS);
|
||||
|
||||
membersRemoved = true;
|
||||
}
|
||||
@@ -522,12 +530,18 @@ public class SiteActivitySystemTest extends TestCase
|
||||
|
||||
String ticket = callLoginWebScript(WEBSCRIPT_ENDPOINT, ADMIN_USER, ADMIN_PW);
|
||||
|
||||
// 2 sites, with 4 users, each with 1 join and 1 role change = 8x2
|
||||
// 1 site, with 3 users, each with 1 join and 1 role change = 6x1
|
||||
// site 1, with 4 users, each with 1 join, 1 role change = 4x2 = 8
|
||||
// site 2, with 4 users, each with 1 join, 1 role change = 4x2 = 8
|
||||
// site 3, with 3 users, each with 1 join, 1 role change = 3x2 = 6
|
||||
|
||||
getUserFeed(user1, ticket, true, 14); // 8 = due to feed control - exclude site 1
|
||||
// user 1 belongs to 3 sites = (2x8)+(1x6) = 22
|
||||
// user 2 belongs to 3 sites = (2x8)+(1x6) = 22
|
||||
// user 3 belongs to 3 sites = (2x8)+(1x6) = 22
|
||||
// user 4 belongs to 2 sites = (2x8) = 16
|
||||
|
||||
getUserFeed(user1, ticket, true, 14); // 14 = (22 - 8) due to feed control - exclude site 1
|
||||
getUserFeed(user2, ticket, true, 0); // 0 = due to feed control - exclude site membership activities (across all sites)
|
||||
getUserFeed(user3, ticket, true, 14); // 8 = due to feed control - exclude site membership activities for site 1
|
||||
getUserFeed(user3, ticket, true, 14); // 14 = (22 - 8) due to feed control - exclude site membership activities for site 1
|
||||
getUserFeed(user4, ticket, true, 16); // 16 = no feed control
|
||||
|
||||
// as user1
|
||||
@@ -563,7 +577,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
getUserFeed(null, null, ticket, false, true, false, 14); // exclude any from user1
|
||||
getUserFeed(null, null, ticket, false, false, true, 0); // exclude all except user1
|
||||
getUserFeed(null, null, ticket, false, true, true, 0); // exclude all (NOOP)
|
||||
|
||||
|
||||
// TODO - add more (eg. other non-admin user activities)
|
||||
}
|
||||
|
||||
@@ -641,7 +655,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
logger.debug(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected String callGetWebScript(String urlString, String ticket) throws MalformedURLException, URISyntaxException, IOException
|
||||
{
|
||||
return callOutWebScript(urlString, "GET", ticket);
|
||||
@@ -668,7 +682,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
|
||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||
conn.setRequestMethod(method);
|
||||
|
||||
|
||||
if (ticket != null)
|
||||
{
|
||||
// add Base64 encoded authorization header
|
||||
@@ -684,7 +698,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
{
|
||||
is = conn.getInputStream();
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
|
||||
String line = null;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while(((line = br.readLine()) !=null)) {
|
||||
@@ -698,7 +712,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
if (br != null) { br.close(); };
|
||||
if (is != null) { is.close(); };
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -724,7 +738,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
{
|
||||
conn.setRequestProperty("SOAPAction", soapAction);
|
||||
}
|
||||
|
||||
|
||||
if (ticket != null)
|
||||
{
|
||||
// add Base64 encoded authorization header
|
||||
@@ -755,7 +769,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
{
|
||||
is = conn.getInputStream();
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
|
||||
String line = null;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while(((line = br.readLine()) !=null))
|
||||
|
@@ -33,8 +33,6 @@ import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.util.JSONtoFmModel;
|
||||
import org.alfresco.web.scripts.DeclarativeWebScript;
|
||||
import org.alfresco.web.scripts.Status;
|
||||
@@ -51,19 +49,12 @@ public class SiteFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
private static final Log logger = LogFactory.getLog(SiteFeedRetrieverWebScript.class);
|
||||
|
||||
private ActivityService activityService;
|
||||
private SiteService siteService;
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
|
||||
*/
|
||||
@@ -100,31 +91,11 @@ public class SiteFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
// if site is null then either does not exist or is private (and current user is not admin or a member) - hence return 401 (unauthorised)
|
||||
|
||||
SiteInfo siteInfo = null;
|
||||
try
|
||||
{
|
||||
siteInfo = siteService.getSite(siteId);
|
||||
}
|
||||
catch (AccessDeniedException ade)
|
||||
{
|
||||
// ignore - fall through
|
||||
}
|
||||
|
||||
if (siteInfo == null)
|
||||
{
|
||||
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
status.setCode(Status.STATUS_UNAUTHORIZED);
|
||||
logger.warn("Unable to get site feed entries for '" + siteId + "' (site does not exist or is private) - currently logged in as '" + currentUser +"'");
|
||||
|
||||
model.put("feedEntries", null);
|
||||
model.put("siteId", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
List<String> feedEntries = activityService.getSiteFeedEntries(siteId, format);
|
||||
|
||||
|
||||
if (format.equals("json"))
|
||||
{
|
||||
model.put("feedEntries", feedEntries);
|
||||
@@ -149,6 +120,16 @@ public class SiteFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
model.put("siteId", siteId);
|
||||
}
|
||||
}
|
||||
catch (AccessDeniedException ade)
|
||||
{
|
||||
// implies that site either does not exist or is private (and current user is not admin or a member) - hence return 401 (unauthorised)
|
||||
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
status.setCode(Status.STATUS_UNAUTHORIZED);
|
||||
logger.warn("Unable to get site feed entries for '" + siteId + "' (site does not exist or is private) - currently logged in as '" + currentUser +"'");
|
||||
|
||||
model.put("feedEntries", null);
|
||||
model.put("siteId", "");
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
@@ -31,6 +31,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.util.JSONtoFmModel;
|
||||
@@ -110,23 +111,12 @@ public class UserFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
{
|
||||
exclOtherUsers = true;
|
||||
}
|
||||
|
||||
|
||||
if ((feedUserId == null) || (feedUserId.length() == 0))
|
||||
{
|
||||
feedUserId = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
}
|
||||
|
||||
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
|
||||
if (! ((currentUser == null) ||
|
||||
(currentUser.equals(AuthenticationUtil.getSystemUserName())) ||
|
||||
(authorityService.isAdminAuthority(currentUser)) ||
|
||||
(currentUser.equals(feedUserId))))
|
||||
{
|
||||
status.setCode(Status.STATUS_UNAUTHORIZED);
|
||||
logger.warn("Unable to get user feed entries for '" + feedUserId + "' - currently logged in as '" + currentUser +"'");
|
||||
return null;
|
||||
}
|
||||
|
||||
// map feed collection format to feed entry format (if not the same), eg.
|
||||
// atomfeed -> atomentry
|
||||
// atom -> atomentry
|
||||
@@ -136,32 +126,41 @@ public class UserFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
}
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
List<String> feedEntries = activityService.getUserFeedEntries(feedUserId, format, siteId, exclThisUser, exclOtherUsers);
|
||||
|
||||
if (format.equals("json"))
|
||||
{
|
||||
model.put("feedEntries", feedEntries);
|
||||
model.put("siteId", siteId);
|
||||
}
|
||||
else
|
||||
try
|
||||
{
|
||||
List<Map<String, Object>> activityFeedModels = new ArrayList<Map<String, Object>>();
|
||||
try
|
||||
{
|
||||
for (String feedEntry : feedEntries)
|
||||
{
|
||||
activityFeedModels.add(JSONtoFmModel.convertJSONObjectToMap(feedEntry));
|
||||
}
|
||||
}
|
||||
catch (JSONException je)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to get user feed entries: " + je.getMessage());
|
||||
}
|
||||
List<String> feedEntries = activityService.getUserFeedEntries(feedUserId, format, siteId, exclThisUser, exclOtherUsers);
|
||||
|
||||
model.put("feedEntries", activityFeedModels);
|
||||
model.put("feedUserId", feedUserId);
|
||||
}
|
||||
if (format.equals("json"))
|
||||
{
|
||||
model.put("feedEntries", feedEntries);
|
||||
model.put("siteId", siteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<Map<String, Object>> activityFeedModels = new ArrayList<Map<String, Object>>();
|
||||
try
|
||||
{
|
||||
for (String feedEntry : feedEntries)
|
||||
{
|
||||
activityFeedModels.add(JSONtoFmModel.convertJSONObjectToMap(feedEntry));
|
||||
}
|
||||
}
|
||||
catch (JSONException je)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to get user feed entries: " + je.getMessage());
|
||||
}
|
||||
|
||||
model.put("feedEntries", activityFeedModels);
|
||||
model.put("feedUserId", feedUserId);
|
||||
}
|
||||
}
|
||||
catch (AccessDeniedException ade)
|
||||
{
|
||||
status.setCode(Status.STATUS_UNAUTHORIZED);
|
||||
logger.warn("Unable to get user feed entries for '" + feedUserId + "' - currently logged in as '" + AuthenticationUtil.getFullyAuthenticatedUser() +"'");
|
||||
return null;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
Reference in New Issue
Block a user