mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +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:
@@ -312,7 +312,6 @@
|
||||
<!-- 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.feed.sitefeed.get" class="org.alfresco.repo.web.scripts.activities.feed.SiteFeedRetrieverWebScript" parent="webscript">
|
||||
<property name="activityService" ref="activityService"/>
|
||||
<property name="siteService" ref="siteService"/>
|
||||
</bean>
|
||||
|
||||
<!-- -->
|
||||
|
@@ -97,6 +97,8 @@ 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;
|
||||
@@ -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)
|
||||
@@ -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;
|
||||
}
|
||||
@@ -439,7 +447,7 @@ public class SiteActivitySystemTest extends TestCase
|
||||
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
|
||||
|
@@ -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;
|
||||
@@ -116,17 +117,6 @@ public class UserFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
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
|
||||
@@ -137,6 +127,8 @@ public class UserFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
try
|
||||
{
|
||||
List<String> feedEntries = activityService.getUserFeedEntries(feedUserId, format, siteId, exclThisUser, exclOtherUsers);
|
||||
|
||||
if (format.equals("json"))
|
||||
@@ -162,6 +154,13 @@ public class UserFeedRetrieverWebScript extends DeclarativeWebScript
|
||||
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