mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
ALF-8805 (RINF 40) - PersonService getPeople
- return PagingResults<PersonInfo> (follow CQ results pattern) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28627 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -46,6 +46,7 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.service.cmr.usage.ContentUsageService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -520,7 +521,12 @@ public final class People extends BaseScopableProcessorExtension implements Init
|
||||
if (filter == null || filter.length() == 0)
|
||||
{
|
||||
PagingRequest pagingRequest = new PagingRequest(maxResults, null);
|
||||
people = personService.getPeople(null, true, null, pagingRequest).getPage().toArray();
|
||||
List<PersonInfo> persons = personService.getPeople(null, true, null, pagingRequest).getPage();
|
||||
people = new Object[persons.size()];
|
||||
for (int i=0; i<people.length; i++)
|
||||
{
|
||||
people[i] = persons.get(i).getNodeRef();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -543,7 +549,12 @@ public final class People extends BaseScopableProcessorExtension implements Init
|
||||
filterProps.add(new Pair<QName, String>(ContentModel.PROP_USERNAME, propVal));
|
||||
|
||||
PagingRequest pagingRequest = new PagingRequest(maxResults, null);
|
||||
people = personService.getPeople(filterProps, true, null, pagingRequest).getPage().toArray();
|
||||
List<PersonInfo> persons = personService.getPeople(filterProps, true, null, pagingRequest).getPage();
|
||||
people = new Object[persons.size()];
|
||||
for (int i=0; i<people.length; i++)
|
||||
{
|
||||
people[i] = persons.get(i).getNodeRef();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -57,8 +57,8 @@ import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||
import org.alfresco.service.cmr.security.PagingPersonResults;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -394,14 +394,14 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
||||
sort.add(new Pair<QName, Boolean>(ContentModel.PROP_USERNAME, sortAscending));
|
||||
}
|
||||
|
||||
final PagingPersonResults ppr = personService.getPeople(filter, true, sort, pagingRequest);
|
||||
final PagingResults<PersonInfo> ppr = personService.getPeople(filter, true, sort, pagingRequest);
|
||||
|
||||
List<NodeRef> result = ppr.getPage();
|
||||
List<PersonInfo> result = ppr.getPage();
|
||||
final List<String> auths = new ArrayList<String>(result.size());
|
||||
|
||||
for (NodeRef personRef : result)
|
||||
for (PersonInfo person : result)
|
||||
{
|
||||
auths.add((String)nodeService.getProperty(personRef, ContentModel.PROP_USERNAME));
|
||||
auths.add(person.getUserName());
|
||||
}
|
||||
|
||||
return new PagingResults<String>()
|
||||
|
@@ -24,18 +24,16 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationContext;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
@@ -47,8 +45,6 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
|
||||
{
|
||||
private PersonService personService;
|
||||
|
||||
private NodeService nodeService;
|
||||
|
||||
private Set<String> adminSet = Collections.singleton(PermissionService.ADMINISTRATOR_AUTHORITY);
|
||||
|
||||
private Set<String> guestSet = Collections.singleton(PermissionService.GUEST_AUTHORITY);
|
||||
@@ -69,11 +65,6 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
|
||||
super();
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setPersonService(PersonService personService)
|
||||
{
|
||||
this.personService = personService;
|
||||
@@ -180,10 +171,9 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
|
||||
case ROLE:
|
||||
break;
|
||||
case USER:
|
||||
for (NodeRef personRef : personService.getPeople(null, true, null, new PagingRequest(0, Integer.MAX_VALUE, null)).getPage())
|
||||
for (PersonInfo person : personService.getPeople(null, true, null, new PagingRequest(0, Integer.MAX_VALUE, null)).getPage())
|
||||
{
|
||||
authorities.add(DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(personRef,
|
||||
ContentModel.PROP_USERNAME)));
|
||||
authorities.add(person.getUserName());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -26,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
|
||||
import org.alfresco.repo.security.authority.UnknownAuthorityException;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
@@ -33,8 +34,8 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||
import org.alfresco.service.cmr.security.PagingPersonResults;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.ScriptPagingDetails;
|
||||
@@ -411,20 +412,17 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
|
||||
}
|
||||
|
||||
// Do the search
|
||||
PagingPersonResults results = personService.getPeople(filter, true, sort, paging);
|
||||
List<PersonInfo> people = personService.getPeople(filter, true, sort, paging).getPage();
|
||||
|
||||
// Record the size of the results
|
||||
paging.setTotalItems(results);
|
||||
paging.setTotalItems(people.size());
|
||||
|
||||
// Now wrap up the users
|
||||
List<NodeRef> nodes = results.getPage();
|
||||
ScriptUser[] users = new ScriptUser[nodes.size()];
|
||||
ScriptUser[] users = new ScriptUser[people.size()];
|
||||
for (int i=0; i<users.length; i++)
|
||||
{
|
||||
NodeRef node = nodes.get(i);
|
||||
String username = (String)serviceRegistry.getNodeService().getProperty(
|
||||
node, ContentModel.PROP_USERNAME);
|
||||
users[i] = new ScriptUser(username, node, serviceRegistry, this.getScope());
|
||||
PersonInfo person = people.get(i);
|
||||
users[i] = new ScriptUser(person.getUserName(), person.getNodeRef(), serviceRegistry, this.getScope());
|
||||
}
|
||||
|
||||
return users;
|
||||
|
@@ -57,6 +57,7 @@ import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
@@ -957,6 +958,10 @@ public class ACLEntryAfterInvocationProvider implements AfterInvocationProvider,
|
||||
{
|
||||
testNodeRef = ((BlogPostInfo) nextObject).getNodeRef();
|
||||
}
|
||||
else if (PersonInfo.class.isAssignableFrom(nextObject.getClass()))
|
||||
{
|
||||
testNodeRef = ((PersonInfo) nextObject).getNodeRef();
|
||||
}
|
||||
else if (Pair.class.isAssignableFrom(nextObject.getClass()))
|
||||
{
|
||||
testNodeRef = (NodeRef) ((Pair)nextObject).getSecond();
|
||||
|
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.security.person;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.query.PermissionedResults;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.PagingPersonResults;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Page of Person results
|
||||
*
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
/* package */ class PagingPersonResultsImpl implements PagingPersonResults, PermissionedResults
|
||||
{
|
||||
private List<NodeRef> nodeRefs;
|
||||
|
||||
private boolean hasMoreItems;
|
||||
private Pair<Integer, Integer> totalResultCount;
|
||||
private String queryExecutionId;
|
||||
private boolean permissionsApplied;
|
||||
|
||||
public PagingPersonResultsImpl(List<NodeRef> nodeRefs, boolean hasMoreItems, Pair<Integer, Integer> totalResultCount, String queryExecutionId, boolean permissionsApplied)
|
||||
{
|
||||
this.nodeRefs = nodeRefs;
|
||||
this.hasMoreItems = hasMoreItems;
|
||||
this.totalResultCount = totalResultCount;
|
||||
this.queryExecutionId = queryExecutionId;
|
||||
this.permissionsApplied = permissionsApplied;
|
||||
}
|
||||
|
||||
public List<NodeRef> getPage()
|
||||
{
|
||||
return nodeRefs;
|
||||
}
|
||||
|
||||
public boolean hasMoreItems()
|
||||
{
|
||||
return hasMoreItems;
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> getTotalResultCount()
|
||||
{
|
||||
return totalResultCount;
|
||||
}
|
||||
|
||||
public String getQueryExecutionId()
|
||||
{
|
||||
return queryExecutionId;
|
||||
}
|
||||
|
||||
public boolean permissionsApplied()
|
||||
{
|
||||
return permissionsApplied;
|
||||
}
|
||||
}
|
@@ -35,6 +35,7 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.CannedQueryFactory;
|
||||
import org.alfresco.query.CannedQueryResults;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.domain.permissions.AclDAO;
|
||||
@@ -45,9 +46,9 @@ import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
|
||||
import org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy;
|
||||
import org.alfresco.repo.node.getchildren.FilterProp;
|
||||
import org.alfresco.repo.node.getchildren.FilterPropString;
|
||||
import org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString;
|
||||
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
|
||||
import org.alfresco.repo.node.getchildren.GetChildrenCannedQueryFactory;
|
||||
import org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
@@ -59,16 +60,16 @@ import org.alfresco.repo.security.permissions.PermissionServiceSPI;
|
||||
import org.alfresco.repo.tenant.TenantDomainMismatchException;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.repo.transaction.TransactionListenerAdapter;
|
||||
import org.alfresco.repo.transaction.TransactionalResourceHelper;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.admin.RepoAdminService;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage.UsageType;
|
||||
import org.alfresco.service.cmr.admin.RepoUsageStatus;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage.UsageType;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.invitation.InvitationException;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
@@ -83,7 +84,6 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||
import org.alfresco.service.cmr.security.PagingPersonResults;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.NamespacePrefixResolver;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
@@ -1159,17 +1159,19 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
||||
*/
|
||||
public Set<NodeRef> getAllPeople()
|
||||
{
|
||||
PagingPersonResults pagingResults = getPeople(null, true, null, new PagingRequest(Integer.MAX_VALUE, null));
|
||||
List<NodeRef> nodeRefs = pagingResults.getPage();
|
||||
Set<NodeRef> refs = new HashSet<NodeRef>(nodeRefs.size());
|
||||
refs.addAll(nodeRefs);
|
||||
List<PersonInfo> personInfos = getPeople(null, true, null, new PagingRequest(Integer.MAX_VALUE, null)).getPage();
|
||||
Set<NodeRef> refs = new HashSet<NodeRef>(personInfos.size());
|
||||
for (PersonInfo personInfo : personInfos)
|
||||
{
|
||||
refs.add(personInfo.getNodeRef());
|
||||
}
|
||||
return refs;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public PagingPersonResults getPeople(List<Pair<QName, String>> stringPropFilters, boolean filterIgnoreCase, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
public PagingResults<PersonInfo> getPeople(List<Pair<QName, String>> stringPropFilters, boolean filterIgnoreCase, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest)
|
||||
{
|
||||
ParameterCheck.mandatory("pagingRequest", pagingRequest);
|
||||
|
||||
@@ -1190,12 +1192,12 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
||||
for (Pair<QName, String> filterProp : stringPropFilters)
|
||||
{
|
||||
String filterStr = filterProp.getSecond();
|
||||
if("*".equals(filterStr))
|
||||
if ((filterStr == null) || (filterStr.equals("")) || (filterStr.equals("*")))
|
||||
{
|
||||
// The wildcard means no filtering is needed on this property
|
||||
continue;
|
||||
}
|
||||
else if(filterStr.endsWith("*"))
|
||||
else if (filterStr.endsWith("*"))
|
||||
{
|
||||
// The trailing * is implicit
|
||||
filterStr = filterStr.substring(0, filterStr.length()-1);
|
||||
@@ -1209,9 +1211,9 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
||||
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, childTypeQNames, filterProps, sortProps, pagingRequest);
|
||||
|
||||
// execute canned query
|
||||
CannedQueryResults<NodeRef> results = cq.execute();
|
||||
final CannedQueryResults<NodeRef> results = cq.execute();
|
||||
|
||||
List<NodeRef> nodeRefs = null;
|
||||
final List<NodeRef> nodeRefs;
|
||||
if (results.getPageCount() > 0)
|
||||
{
|
||||
nodeRefs = results.getPages().get(0);
|
||||
@@ -1222,11 +1224,15 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
||||
}
|
||||
|
||||
// set total count
|
||||
Pair<Integer, Integer> totalCount = null;
|
||||
final Pair<Integer, Integer> totalCount;
|
||||
if (pagingRequest.getRequestTotalCountMax() > 0)
|
||||
{
|
||||
totalCount = results.getTotalResultCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
totalCount = null;
|
||||
}
|
||||
|
||||
if (start != null)
|
||||
{
|
||||
@@ -1246,7 +1252,44 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
||||
}
|
||||
}
|
||||
|
||||
return new PagingPersonResultsImpl(nodeRefs, results.hasMoreItems(), totalCount, results.getQueryExecutionId(), true);
|
||||
final List<PersonInfo> personInfos = new ArrayList<PersonInfo>(nodeRefs.size());
|
||||
for (NodeRef nodeRef : nodeRefs)
|
||||
{
|
||||
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
|
||||
personInfos.add(new PersonInfo(nodeRef,
|
||||
(String)props.get(ContentModel.PROP_USERNAME),
|
||||
(String)props.get(ContentModel.PROP_FIRSTNAME),
|
||||
(String)props.get(ContentModel.PROP_LASTNAME)));
|
||||
}
|
||||
|
||||
return new PagingResults<PersonInfo>()
|
||||
{
|
||||
@Override
|
||||
public String getQueryExecutionId()
|
||||
{
|
||||
return results.getQueryExecutionId();
|
||||
}
|
||||
@Override
|
||||
public List<PersonInfo> getPage()
|
||||
{
|
||||
return personInfos;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMoreItems()
|
||||
{
|
||||
return results.hasMoreItems();
|
||||
}
|
||||
@Override
|
||||
public Pair<Integer, Integer> getTotalResultCount()
|
||||
{
|
||||
return totalCount;
|
||||
}
|
||||
@Override
|
||||
public boolean permissionsApplied()
|
||||
{
|
||||
return results.permissionsApplied();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1267,12 +1310,15 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
||||
filterProps.add(new Pair<QName, String>(propertyKey, (String)propertyValue));
|
||||
|
||||
PagingRequest pagingRequest = new PagingRequest(Integer.MAX_VALUE, null);
|
||||
List<NodeRef> people = getPeople(filterProps, true, null, pagingRequest).getPage();
|
||||
List<PersonInfo> personInfos = getPeople(filterProps, true, null, pagingRequest).getPage();
|
||||
|
||||
Set<NodeRef> result = new HashSet<NodeRef>(people.size());
|
||||
result.addAll(people);
|
||||
Set<NodeRef> refs = new HashSet<NodeRef>(personInfos.size());
|
||||
for (PersonInfo personInfo : personInfos)
|
||||
{
|
||||
refs.add(personInfo.getNodeRef());
|
||||
}
|
||||
|
||||
return result;
|
||||
return refs;
|
||||
}
|
||||
|
||||
// Policies
|
||||
|
@@ -38,8 +38,8 @@ import junit.framework.TestCase;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||
@@ -53,9 +53,9 @@ import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||
import org.alfresco.service.cmr.security.PagingPersonResults;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
@@ -150,7 +150,7 @@ public class PersonTest extends TestCase
|
||||
pagingRequest = new PagingRequest(0, 1, null);
|
||||
pagingRequest.setRequestTotalCountMax(20000); // note: request total people count (up to max of 20000)
|
||||
|
||||
PagingPersonResults ppr = personService.getPeople(null, true, null, pagingRequest);
|
||||
PagingResults<PersonInfo> ppr = personService.getPeople(null, true, null, pagingRequest);
|
||||
|
||||
Pair<Integer, Integer> totalResultCount = ppr.getTotalResultCount();
|
||||
assertNotNull(totalResultCount);
|
||||
@@ -165,9 +165,18 @@ public class PersonTest extends TestCase
|
||||
private void checkPeopleContain(String userName)
|
||||
{
|
||||
PagingRequest pagingRequest = new PagingRequest(0, 20000, null);
|
||||
PagingPersonResults ppr = personService.getPeople(null, true, null, pagingRequest);
|
||||
PagingResults<PersonInfo> ppr = personService.getPeople(null, true, null, pagingRequest);
|
||||
|
||||
assertTrue(ppr.getPage().contains(personService.getPerson(userName)));
|
||||
boolean found = false;
|
||||
for (PersonInfo person : ppr.getPage())
|
||||
{
|
||||
if (person.getUserName().equals(userName))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
}
|
||||
|
||||
public void xtestLazyHomeFolderCreation() throws Exception
|
||||
@@ -555,8 +564,6 @@ public class PersonTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
//TODO add getPeople tests here with filtering and (possibly) sorting ... !!
|
||||
|
||||
public void testPeopleFiltering()
|
||||
{
|
||||
personService.setCreateMissingPeople(false);
|
||||
@@ -636,34 +643,34 @@ public class PersonTest extends TestCase
|
||||
|
||||
// page 1
|
||||
PagingRequest pr = new PagingRequest(0, 2, null);
|
||||
PagingPersonResults ppr = personService.getPeople(null, true, sort, pr);
|
||||
List<NodeRef> results = ppr.getPage();
|
||||
PagingResults<PersonInfo> ppr = personService.getPeople(null, true, sort, pr);
|
||||
List<PersonInfo> results = ppr.getPage();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals(p3, results.get(0));
|
||||
assertEquals(p1, results.get(1));
|
||||
assertEquals(p3, results.get(0).getNodeRef());
|
||||
assertEquals(p1, results.get(1).getNodeRef());
|
||||
|
||||
// page 2
|
||||
pr = new PagingRequest(2, 2, null);
|
||||
ppr = personService.getPeople(null, true, sort, pr);
|
||||
results = ppr.getPage();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals(p6, results.get(0));
|
||||
assertEquals(p4, results.get(1));
|
||||
assertEquals(p6, results.get(0).getNodeRef());
|
||||
assertEquals(p4, results.get(1).getNodeRef());
|
||||
|
||||
// page 3
|
||||
pr = new PagingRequest(4, 2, null);
|
||||
ppr = personService.getPeople(null, true, sort, pr);
|
||||
results = ppr.getPage();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals(p7, results.get(0));
|
||||
assertEquals(p2, results.get(1));
|
||||
assertEquals(p7, results.get(0).getNodeRef());
|
||||
assertEquals(p2, results.get(1).getNodeRef());
|
||||
|
||||
// page 4
|
||||
pr = new PagingRequest(6, 2, null);
|
||||
ppr = personService.getPeople(null, true, sort, pr);
|
||||
results = ppr.getPage();
|
||||
assertEquals(1, results.size());
|
||||
assertEquals(p5, results.get(0));
|
||||
assertEquals(p5, results.get(0).getNodeRef());
|
||||
}
|
||||
|
||||
private void testProperties(NodeRef nodeRef, String userName, String firstName, String lastName, String email, String orgId)
|
||||
|
@@ -34,6 +34,7 @@ import junit.framework.TestCase;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.model.Repository;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
@@ -63,6 +64,7 @@ import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.OwnableService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.security.PersonService.PersonInfo;
|
||||
import org.alfresco.service.cmr.usage.UsageService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -186,11 +188,11 @@ public class MultiTDemoTest extends TestCase
|
||||
|
||||
logger.info("Create tenants");
|
||||
|
||||
Set<NodeRef> personRefs = personService.getAllPeople();
|
||||
List<PersonInfo> persons = personService.getPeople(null, true, null, new PagingRequest(0, Integer.MAX_VALUE, null)).getPage();
|
||||
//assertEquals(2, personRefs.size()); // super-tenant: admin, guest (note: checking for 2 assumes that this test is run in a fresh bootstrap env)
|
||||
for (NodeRef personRef : personRefs)
|
||||
for (PersonInfo person : persons)
|
||||
{
|
||||
String userName = (String)nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
|
||||
String userName = person.getUserName();
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
assertFalse("Unexpected (tenant) user: "+userName, userName.endsWith(tenantDomain));
|
||||
@@ -518,11 +520,11 @@ public class MultiTDemoTest extends TestCase
|
||||
{
|
||||
logger.info("Create demo users");
|
||||
|
||||
Set<NodeRef> personRefs = personService.getAllPeople();
|
||||
List<PersonInfo> persons = personService.getPeople(null, true, null, new PagingRequest(0, Integer.MAX_VALUE, null)).getPage();
|
||||
//assertEquals(2, personRefs.size()); // super-tenant: admin, guest (note: checking for 2 assumes that this test is run in a fresh bootstrap env)
|
||||
for (NodeRef personRef : personRefs)
|
||||
for (PersonInfo person : persons)
|
||||
{
|
||||
String userName = (String)nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
|
||||
String userName = person.getUserName();
|
||||
for (final String tenantDomain : tenants)
|
||||
{
|
||||
assertFalse("Unexpected (tenant) user: "+userName, userName.endsWith(tenantDomain));
|
||||
|
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.service.cmr.security;
|
||||
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Response for page of Person results
|
||||
*
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
public interface PagingPersonResults extends PagingResults<NodeRef>
|
||||
{
|
||||
}
|
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.Auditable;
|
||||
import org.alfresco.service.NotAuditable;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -219,6 +220,48 @@ public interface PersonService
|
||||
@Auditable
|
||||
public Set<NodeRef> getAllPeople();
|
||||
|
||||
/**
|
||||
* Data pojo to carry common person information
|
||||
*
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
public class PersonInfo
|
||||
{
|
||||
private final NodeRef nodeRef;
|
||||
private final String userName;
|
||||
private final String firstName;
|
||||
private final String lastName;
|
||||
|
||||
public PersonInfo(NodeRef nodeRef, String userName, String firstName, String lastName)
|
||||
{
|
||||
this.nodeRef = nodeRef;
|
||||
this.userName = userName;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public NodeRef getNodeRef()
|
||||
{
|
||||
return nodeRef;
|
||||
}
|
||||
|
||||
public String getUserName()
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
|
||||
public String getFirstName()
|
||||
{
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public String getLastName()
|
||||
{
|
||||
return lastName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paged list of people optionally filtered and/or sorted
|
||||
|
||||
@@ -226,10 +269,12 @@ public interface PersonService
|
||||
* @param filterIgnoreCase true to ignore case when filtering, false to be case-sensitive when filtering
|
||||
* @param sortProps sort property, eg. cm:username ascending
|
||||
* @param pagingRequest skip, max + optional query execution id
|
||||
*
|
||||
* @author janv
|
||||
* @since 4.0
|
||||
*/
|
||||
@Auditable(parameters = {"stringPropFilters", "filterIgnoreCase", "sortProps", "pagingRequest"})
|
||||
public PagingPersonResults getPeople(List<Pair<QName,String>> stringPropFilters, boolean filterIgnoreCase, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
public PagingResults<PersonInfo> getPeople(List<Pair<QName,String>> stringPropFilters, boolean filterIgnoreCase, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest);
|
||||
|
||||
/**
|
||||
* Get people filtered by the given property name/value pair
|
||||
|
Reference in New Issue
Block a user