mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
124236 amorarasu: Merged 5.0.N (5.0.4) to 5.1.N (5.1.2) (PARTIAL MERGE) 124190 amorarasu: Merged V4.2-BUG-FIX (4.2.7) to 5.0.N (5.0.4) 124132 arebegea: MNT-15573 : Site finder slow for a user who's member of many sites - added a new method to InvitationService to make use of the limit in the searchInvitation - sent and used the 200 limit from the site-finder.get.js in the script/ScriptInvitationService.java and passed the new parameter - for searchModeratedInvitations and searchNominatedInvitations methods of InvitationServiceImpl.java I added the use of the limit parameter - added some comments on ActivitiWorkflowEngine.java and TaskComponent.java to inform developers about the performance issues and possible improvement - added junit tests git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@124277 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -828,16 +828,22 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the general search invitation method returning {@link Invitation}s
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* @param criteria InvitationSearchCriteria
|
* @deprecated
|
||||||
* @return the list of start tasks for invitations
|
|
||||||
*/
|
*/
|
||||||
public List<Invitation> searchInvitation(final InvitationSearchCriteria criteria)
|
public List<Invitation> searchInvitation(final InvitationSearchCriteria criteria)
|
||||||
{
|
{
|
||||||
int limit = 200;
|
return searchInvitation(criteria, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public List<Invitation> searchInvitation(InvitationSearchCriteria criteria, int limit)
|
||||||
|
{
|
||||||
List<String> invitationIds = searchInvitationsForIds(criteria, limit);
|
List<String> invitationIds = searchInvitationsForIds(criteria, limit);
|
||||||
return invitationIds.isEmpty() ? Collections.<Invitation>emptyList() : searchInvitation(criteria, invitationIds);
|
return invitationIds.isEmpty() ? Collections.<Invitation> emptyList() : searchInvitation(criteria, invitationIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Invitation> searchInvitation(final InvitationSearchCriteria criteria, List<String> invitationIds)
|
private List<Invitation> searchInvitation(final InvitationSearchCriteria criteria, List<String> invitationIds)
|
||||||
@@ -872,7 +878,7 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
if (toSearch == InvitationSearchCriteria.InvitationType.ALL
|
if (toSearch == InvitationSearchCriteria.InvitationType.ALL
|
||||||
|| toSearch == InvitationSearchCriteria.InvitationType.NOMINATED)
|
|| toSearch == InvitationSearchCriteria.InvitationType.NOMINATED)
|
||||||
{
|
{
|
||||||
for (WorkflowTask task : searchNominatedInvitations(criteria))
|
for (WorkflowTask task : searchNominatedInvitations(criteria, limit))
|
||||||
{
|
{
|
||||||
String invitationId = task.getPath().getInstance().getId();
|
String invitationId = task.getPath().getInstance().getId();
|
||||||
invitationIds.add(invitationId);
|
invitationIds.add(invitationId);
|
||||||
@@ -886,7 +892,7 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
(toSearch == InvitationSearchCriteria.InvitationType.ALL
|
(toSearch == InvitationSearchCriteria.InvitationType.ALL
|
||||||
|| toSearch == InvitationSearchCriteria.InvitationType.MODERATED))
|
|| toSearch == InvitationSearchCriteria.InvitationType.MODERATED))
|
||||||
{
|
{
|
||||||
for (WorkflowTask task: searchModeratedInvitations(criteria))
|
for (WorkflowTask task: searchModeratedInvitations(criteria, limit))
|
||||||
{
|
{
|
||||||
String invitationId = task.getPath().getInstance().getId();
|
String invitationId = task.getPath().getInstance().getId();
|
||||||
invitationIds.add(invitationId);
|
invitationIds.add(invitationId);
|
||||||
@@ -937,14 +943,23 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<WorkflowTask> searchModeratedInvitations(InvitationSearchCriteria criteria)
|
/**
|
||||||
|
*
|
||||||
|
* @param criteria criteria to search by
|
||||||
|
* @param limit maximum number of IDs to return. If less than 1, there is no limit.
|
||||||
|
* @return list of WorkflowTask representing moderated invitations
|
||||||
|
*/
|
||||||
|
private List<WorkflowTask> searchModeratedInvitations(InvitationSearchCriteria criteria, int limit)
|
||||||
{
|
{
|
||||||
long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
|
long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
|
||||||
|
|
||||||
WorkflowTaskQuery query = new WorkflowTaskQuery();
|
WorkflowTaskQuery query = new WorkflowTaskQuery();
|
||||||
query.setTaskState(WorkflowTaskState.IN_PROGRESS);
|
query.setTaskState(WorkflowTaskState.IN_PROGRESS);
|
||||||
|
if (limit > 0)
|
||||||
|
{
|
||||||
|
query.setLimit(limit);
|
||||||
|
}
|
||||||
Map<QName, Object> properties = new HashMap<QName, Object>();
|
Map<QName, Object> properties = new HashMap<QName, Object>();
|
||||||
String invitee = criteria.getInvitee();
|
String invitee = criteria.getInvitee();
|
||||||
if (invitee != null)
|
if (invitee != null)
|
||||||
@@ -998,13 +1013,22 @@ public class InvitationServiceImpl implements InvitationService, NodeServicePoli
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<WorkflowTask> searchNominatedInvitations(InvitationSearchCriteria criteria)
|
/**
|
||||||
|
*
|
||||||
|
* @param criteria
|
||||||
|
* @param limit maximum number of IDs to return. If less than 1, there is no limit.
|
||||||
|
* @return list of WorkflowTask representing nominated invitations
|
||||||
|
*/
|
||||||
|
private List<WorkflowTask> searchNominatedInvitations(InvitationSearchCriteria criteria, int limit)
|
||||||
{
|
{
|
||||||
long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
|
long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
|
||||||
|
|
||||||
WorkflowTaskQuery query = new WorkflowTaskQuery();
|
WorkflowTaskQuery query = new WorkflowTaskQuery();
|
||||||
query.setTaskState(WorkflowTaskState.IN_PROGRESS);
|
query.setTaskState(WorkflowTaskState.IN_PROGRESS);
|
||||||
|
if (limit > 0)
|
||||||
|
{
|
||||||
|
query.setLimit(limit);
|
||||||
|
}
|
||||||
String invitee = criteria.getInvitee();
|
String invitee = criteria.getInvitee();
|
||||||
if(invitee != null)
|
if(invitee != null)
|
||||||
{
|
{
|
||||||
|
@@ -48,6 +48,8 @@ public class ScriptInvitationService extends BaseScopableProcessorExtension
|
|||||||
implements InitializingBean
|
implements InitializingBean
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static final int DEFAULT_MAX_LIST_INVITATIONS_RETURN_SIZE = 200;
|
||||||
|
|
||||||
/** The invitation service */
|
/** The invitation service */
|
||||||
private InvitationService invitationService;
|
private InvitationService invitationService;
|
||||||
|
|
||||||
@@ -101,7 +103,13 @@ public class ScriptInvitationService extends BaseScopableProcessorExtension
|
|||||||
* List the open invitations.
|
* List the open invitations.
|
||||||
* props specifies optional properties to constrain the search.
|
* props specifies optional properties to constrain the search.
|
||||||
*
|
*
|
||||||
* @param props props
|
* By default, if no "resultsLimit" property is specified in the props argument,
|
||||||
|
* this method will return a maximum of DEFAULT_MAX_LIST_INVITATIONS_RETURN_SIZE (200) results
|
||||||
|
*
|
||||||
|
* @param props inviteeUserName
|
||||||
|
* @param props resourceName
|
||||||
|
* @param props resourceType
|
||||||
|
* @param props invitationType
|
||||||
*
|
*
|
||||||
* @return the invitations
|
* @return the invitations
|
||||||
*/
|
*/
|
||||||
@@ -109,7 +117,9 @@ public class ScriptInvitationService extends BaseScopableProcessorExtension
|
|||||||
public ScriptInvitation<?>[] listInvitations(Scriptable props)
|
public ScriptInvitation<?>[] listInvitations(Scriptable props)
|
||||||
{
|
{
|
||||||
InvitationSearchCriteriaImpl crit = new InvitationSearchCriteriaImpl();
|
InvitationSearchCriteriaImpl crit = new InvitationSearchCriteriaImpl();
|
||||||
|
|
||||||
|
int resultsLimit = DEFAULT_MAX_LIST_INVITATIONS_RETURN_SIZE;
|
||||||
|
|
||||||
if (props.has("resourceName", props))
|
if (props.has("resourceName", props))
|
||||||
{
|
{
|
||||||
crit.setResourceName((String)props.get("resourceName", props));
|
crit.setResourceName((String)props.get("resourceName", props));
|
||||||
@@ -127,6 +137,21 @@ public class ScriptInvitationService extends BaseScopableProcessorExtension
|
|||||||
String invitationType = (String)props.get("invitationType", props);
|
String invitationType = (String)props.get("invitationType", props);
|
||||||
crit.setInvitationType(InvitationType.valueOf(invitationType));
|
crit.setInvitationType(InvitationType.valueOf(invitationType));
|
||||||
}
|
}
|
||||||
|
if (props.has("resultsLimit", props))
|
||||||
|
{
|
||||||
|
String resultsLimitStr = (String) props.get("resultsLimit", props);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (resultsLimitStr != null && !resultsLimitStr.isEmpty())
|
||||||
|
{
|
||||||
|
resultsLimit = Integer.parseInt(resultsLimitStr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// ignore any parse exceptions; no need to log them
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//MNT-9905 Pending Invites created by one site manager aren't visible to other site managers
|
//MNT-9905 Pending Invites created by one site manager aren't visible to other site managers
|
||||||
String currentUser = AuthenticationUtil.getRunAsUser();
|
String currentUser = AuthenticationUtil.getRunAsUser();
|
||||||
@@ -136,12 +161,12 @@ public class ScriptInvitationService extends BaseScopableProcessorExtension
|
|||||||
if (siteShortName != null && (SiteModel.SITE_MANAGER).equals(siteService.getMembersRole(siteShortName, currentUser)))
|
if (siteShortName != null && (SiteModel.SITE_MANAGER).equals(siteService.getMembersRole(siteShortName, currentUser)))
|
||||||
{
|
{
|
||||||
final InvitationSearchCriteriaImpl criteria = crit;
|
final InvitationSearchCriteriaImpl criteria = crit;
|
||||||
|
final int resultsLimitFinal = resultsLimit;
|
||||||
RunAsWork<List<Invitation>> runAsSystem = new RunAsWork<List<Invitation>>()
|
RunAsWork<List<Invitation>> runAsSystem = new RunAsWork<List<Invitation>>()
|
||||||
{
|
{
|
||||||
public List<Invitation> doWork() throws Exception
|
public List<Invitation> doWork() throws Exception
|
||||||
{
|
{
|
||||||
return invitationService.searchInvitation(criteria);
|
return invitationService.searchInvitation(criteria, resultsLimitFinal);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,7 +174,7 @@ public class ScriptInvitationService extends BaseScopableProcessorExtension
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
invitations = invitationService.searchInvitation(crit);
|
invitations = invitationService.searchInvitation(crit, resultsLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptInvitation<?>[] ret = new ScriptInvitation[invitations.size()];
|
ScriptInvitation<?>[] ret = new ScriptInvitation[invitations.size()];
|
||||||
|
@@ -73,11 +73,16 @@ public interface TaskComponent
|
|||||||
/**
|
/**
|
||||||
* Query for tasks
|
* Query for tasks
|
||||||
*
|
*
|
||||||
* @param query the filter by which tasks are queried
|
* Hint: use {@link WorkflowTaskQuery} setLimit() method to limit the number
|
||||||
* @param sameSession indicates that the returned {@link WorkflowTask} elements will be used in
|
* of processed items if you don't really need to go through all of them
|
||||||
* the same session. If {@code true}, the returned List will be a lazy loaded list
|
*
|
||||||
* providing greater performance.
|
* @param query
|
||||||
* @return the list of tasks matching the specified query
|
* the filter by which tasks are queried
|
||||||
|
* @param sameSession
|
||||||
|
* indicates that the returned {@link WorkflowTask} elements will
|
||||||
|
* be used in the same session. If {@code true}, the returned
|
||||||
|
* List will be a lazy loaded list providing greater performance.
|
||||||
|
* @return the list of tasks matching the specified query
|
||||||
*/
|
*/
|
||||||
public List<WorkflowTask> queryTasks(final WorkflowTaskQuery query, boolean sameSession);
|
public List<WorkflowTask> queryTasks(final WorkflowTaskQuery query, boolean sameSession);
|
||||||
|
|
||||||
|
@@ -1238,8 +1238,15 @@ public class ActivitiWorkflowEngine extends BPMEngine implements WorkflowEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given list of {@link Task}s to a list of {@link WorkflowTask}s
|
* Converts the given list of {@link Task}s to a list of
|
||||||
* that have a valid domain.
|
* {@link WorkflowTask}s that have a valid domain.
|
||||||
|
*
|
||||||
|
* Note that this method is not very performant. It will do many DB queries
|
||||||
|
* for each of the Task item in the list of tasks as parameter. Make sure
|
||||||
|
* that you limit the size of the tasks list depending on your needs. Hint:
|
||||||
|
* use the WorkflowTaskQuery query parameter setLimit() method to limit the
|
||||||
|
* number of Tasks to process
|
||||||
|
*
|
||||||
* @param tasks List<Task>
|
* @param tasks List<Task>
|
||||||
*/
|
*/
|
||||||
private List<WorkflowTask> getValidWorkflowTasks(List<Task> tasks)
|
private List<WorkflowTask> getValidWorkflowTasks(List<Task> tasks)
|
||||||
|
@@ -283,14 +283,36 @@ public interface InvitationService
|
|||||||
public List<Invitation> listPendingInvitationsForResource(Invitation.ResourceType resourceType, String resourceName);
|
public List<Invitation> listPendingInvitationsForResource(Invitation.ResourceType resourceType, String resourceName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* search invitation
|
* This is the general search invitation method returning {@link Invitation}
|
||||||
|
* This method has a hardcoded limit of 200 invitations to return. It has
|
||||||
|
* been deprecated and it is recommended to use the overloaded version for
|
||||||
|
* which you can specify an appropriate limit depending on the needs
|
||||||
*
|
*
|
||||||
* @param criteria InvitationSearchCriteria
|
* @param criteria InvitationSearchCriteria
|
||||||
|
* search criteria
|
||||||
* @return the list of invitations
|
* @return the list of invitations
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@NotAuditable
|
@NotAuditable
|
||||||
public List<Invitation> searchInvitation(InvitationSearchCriteria criteria);
|
public List<Invitation> searchInvitation(InvitationSearchCriteria criteria);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the general search invitation method returning {@link Invitation}
|
||||||
|
* This is the recommended method to use for searching invitations; Consider
|
||||||
|
* that the performance of the method will be greatly influenced by the
|
||||||
|
* limit specified
|
||||||
|
*
|
||||||
|
* @param criteria
|
||||||
|
* search criteria
|
||||||
|
* @param limit
|
||||||
|
* maximum number of IDs to return. If less than 1, there is no
|
||||||
|
* limit.
|
||||||
|
* @return the list of invitations
|
||||||
|
*/
|
||||||
|
@NotAuditable
|
||||||
|
public List<Invitation> searchInvitation(InvitationSearchCriteria criteria, int limit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if emails are sent on invite.
|
* @return true if emails are sent on invite.
|
||||||
*/
|
*/
|
||||||
|
@@ -1142,6 +1142,10 @@ public abstract class AbstractInvitationServiceImplTest extends BaseAlfrescoSpri
|
|||||||
List<Invitation> resFive = invitationService.searchInvitation(crit1);
|
List<Invitation> resFive = invitationService.searchInvitation(crit1);
|
||||||
assertEquals("user one does not have 2 nominated", 2, resFive.size());
|
assertEquals("user one does not have 2 nominated", 2, resFive.size());
|
||||||
|
|
||||||
|
// now limit the search to 1 returned value
|
||||||
|
List<Invitation> limitRes = invitationService.searchInvitation(crit1, 1);
|
||||||
|
assertEquals("user one does not have 1 nominated", 1, limitRes.size());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search with an empty criteria - should find all open invitations
|
* Search with an empty criteria - should find all open invitations
|
||||||
*/
|
*/
|
||||||
@@ -1149,6 +1153,10 @@ public abstract class AbstractInvitationServiceImplTest extends BaseAlfrescoSpri
|
|||||||
invitationService.searchInvitation(crit2);
|
invitationService.searchInvitation(crit2);
|
||||||
assertTrue("search everything returned 0 elements", resFive.size() > 0);
|
assertTrue("search everything returned 0 elements", resFive.size() > 0);
|
||||||
|
|
||||||
|
// now search everything but limit the results to 3
|
||||||
|
invitationService.searchInvitation(crit2, 3);
|
||||||
|
assertTrue("search everything returned 0 or more than 3 elements", resFive.size() > 0 && resFive.size() <=3);
|
||||||
|
|
||||||
InvitationSearchCriteriaImpl crit3 = new InvitationSearchCriteriaImpl();
|
InvitationSearchCriteriaImpl crit3 = new InvitationSearchCriteriaImpl();
|
||||||
crit3.setInviter(USER_MANAGER);
|
crit3.setInviter(USER_MANAGER);
|
||||||
crit3.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
|
crit3.setInvitationType(InvitationSearchCriteria.InvitationType.NOMINATED);
|
||||||
@@ -1156,6 +1164,51 @@ public abstract class AbstractInvitationServiceImplTest extends BaseAlfrescoSpri
|
|||||||
List<Invitation> res3 = invitationService.searchInvitation(crit3);
|
List<Invitation> res3 = invitationService.searchInvitation(crit3);
|
||||||
assertEquals("user one does not have 2 nominated", 2, res3.size());
|
assertEquals("user one does not have 2 nominated", 2, res3.size());
|
||||||
|
|
||||||
|
//now limit the search to 1 result
|
||||||
|
res3 = invitationService.searchInvitation(crit3, 1);
|
||||||
|
assertEquals("user one does not have 1 nominated", 1, res3.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that the search limiter works
|
||||||
|
*/
|
||||||
|
public void testSearchInvitationWithLimit() throws Exception
|
||||||
|
{
|
||||||
|
Invitation.ResourceType resourceType = Invitation.ResourceType.WEB_SITE;
|
||||||
|
String resourceName = SITE_SHORT_NAME_INVITE;
|
||||||
|
String inviteeRole = SiteModel.SITE_COLLABORATOR;
|
||||||
|
String serverPath = "wibble";
|
||||||
|
String acceptUrl = "froob";
|
||||||
|
String rejectUrl = "marshmallow";
|
||||||
|
|
||||||
|
authenticationComponent.setCurrentUser(USER_MANAGER);
|
||||||
|
|
||||||
|
// Create 10 invites
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
invitationService
|
||||||
|
.inviteNominated(USER_ONE, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invite USER_TWO
|
||||||
|
NominatedInvitation inviteForUserTwo = invitationService.inviteNominated(USER_TWO, resourceType, resourceName,
|
||||||
|
inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
|
|
||||||
|
InvitationSearchCriteriaImpl query = new InvitationSearchCriteriaImpl();
|
||||||
|
query.setInvitee(USER_TWO);
|
||||||
|
|
||||||
|
// search all of them
|
||||||
|
List<Invitation> results = invitationService.searchInvitation(query, 0);
|
||||||
|
assertEquals(1, results.size());
|
||||||
|
assertEquals(inviteForUserTwo.getInviteId(), results.get(0).getInviteId());
|
||||||
|
|
||||||
|
query = new InvitationSearchCriteriaImpl();
|
||||||
|
query.setInvitee(USER_ONE);
|
||||||
|
|
||||||
|
final int MAX_SEARCH = 3;
|
||||||
|
// only search for the first MAX_SEARCH
|
||||||
|
results = invitationService.searchInvitation(query, MAX_SEARCH);
|
||||||
|
assertEquals(MAX_SEARCH, results.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disabled_test100Invites() throws Exception
|
public void disabled_test100Invites() throws Exception
|
||||||
@@ -1175,7 +1228,7 @@ public abstract class AbstractInvitationServiceImplTest extends BaseAlfrescoSpri
|
|||||||
invitationService.inviteNominated(USER_ONE, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
invitationService.inviteNominated(USER_ONE, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invite USER_TWO
|
// Invite USER_TWO
|
||||||
NominatedInvitation invite = invitationService.inviteNominated(USER_TWO, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
NominatedInvitation invite = invitationService.inviteNominated(USER_TWO, resourceType, resourceName, inviteeRole, serverPath, acceptUrl, rejectUrl);
|
||||||
|
|
||||||
InvitationSearchCriteriaImpl query = new InvitationSearchCriteriaImpl();
|
InvitationSearchCriteriaImpl query = new InvitationSearchCriteriaImpl();
|
||||||
|
Reference in New Issue
Block a user