mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Added new method to Java Person Service public API - getPeopleFilteredByProperty(QName propertyKey, Serializable propertyValue)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10211 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -228,6 +228,9 @@
|
||||
<property name="authorityService">
|
||||
<ref bean="authorityService" />
|
||||
</property>
|
||||
<property name="dictionaryService">
|
||||
<ref bean="dictionaryService" />
|
||||
</property>
|
||||
<property name="namespacePrefixResolver">
|
||||
<ref bean="namespaceService" />
|
||||
</property>
|
||||
|
@@ -819,6 +819,7 @@
|
||||
org.alfresco.service.cmr.security.PersonService.createPerson=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||
org.alfresco.service.cmr.security.PersonService.deletePerson=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||
org.alfresco.service.cmr.security.PersonService.getAllPeople=ACL_ALLOW
|
||||
org.alfresco.service.cmr.security.PersonService.getPeopleFilteredByProperty=ACL_ALLOW
|
||||
org.alfresco.service.cmr.security.PersonService.getPeopleContainer=ACL_ALLOW
|
||||
org.alfresco.service.cmr.security.PersonService.getUserNamesAreCaseSensitive=ACL_ALLOW
|
||||
org.alfresco.service.cmr.security.PersonService.getUserIdentifier=ACL_ALLOW
|
||||
|
@@ -41,6 +41,7 @@ import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.security.permissions.PermissionServiceSPI;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -86,6 +87,8 @@ public class PersonServiceImpl implements PersonService,
|
||||
private SearchService searchService;
|
||||
|
||||
private AuthorityService authorityService;
|
||||
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
private PermissionServiceSPI permissionServiceSPI;
|
||||
|
||||
@@ -700,6 +703,54 @@ public class PersonServiceImpl implements PersonService,
|
||||
return nodes;
|
||||
}
|
||||
|
||||
public Set<NodeRef> getPeopleFilteredByProperty(QName propertyKey, Serializable propertyValue)
|
||||
{
|
||||
// check that given property key is defined for content model type 'cm:person'
|
||||
// and throw exception if it isn't
|
||||
if (this.dictionaryService.getProperty(ContentModel.TYPE_PERSON, propertyKey) == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Property '" + propertyKey + "' is not defined "
|
||||
+ "for content model type cm:person");
|
||||
}
|
||||
|
||||
LinkedHashSet<NodeRef> people = new LinkedHashSet<NodeRef>();
|
||||
|
||||
//
|
||||
// Search for people using the given property
|
||||
//
|
||||
|
||||
SearchParameters sp = new SearchParameters();
|
||||
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
sp.setQuery("@cm\\:" + propertyKey.getLocalName() + ":\"" + propertyValue + "\"");
|
||||
sp.addStore(tenantService.getName(storeRef));
|
||||
sp.excludeDataInTheCurrentTransaction(false);
|
||||
|
||||
ResultSet rs = null;
|
||||
|
||||
try
|
||||
{
|
||||
rs = searchService.query(sp);
|
||||
|
||||
for (ResultSetRow row : rs)
|
||||
{
|
||||
NodeRef nodeRef = row.getNodeRef();
|
||||
if (nodeService.exists(nodeRef))
|
||||
{
|
||||
people.add(nodeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (rs != null)
|
||||
{
|
||||
rs.close();
|
||||
}
|
||||
}
|
||||
|
||||
return people;
|
||||
}
|
||||
|
||||
// Policies
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -737,6 +788,11 @@ public class PersonServiceImpl implements PersonService,
|
||||
{
|
||||
this.authorityService = authorityService;
|
||||
}
|
||||
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
public void setPermissionServiceSPI(PermissionServiceSPI permissionServiceSPI)
|
||||
{
|
||||
|
@@ -268,6 +268,12 @@ public class PersonTest extends BaseSpringTest
|
||||
|
||||
assertEquals(1, personService.getAllPeople().size());
|
||||
assertTrue(personService.getAllPeople().contains(personService.getPerson("derek")));
|
||||
assertEquals(1, personService.getPeopleFilteredByProperty(ContentModel.PROP_USERNAME, "derek").size());
|
||||
assertEquals(1, personService.getPeopleFilteredByProperty(ContentModel.PROP_EMAIL, "dh@dh").size());
|
||||
assertEquals(1, personService.getPeopleFilteredByProperty(ContentModel.PROP_ORGID, "alfresco").size());
|
||||
assertEquals(0, personService.getPeopleFilteredByProperty(ContentModel.PROP_USERNAME, "glen").size());
|
||||
assertEquals(0, personService.getPeopleFilteredByProperty(ContentModel.PROP_EMAIL, "gj@email.com").size());
|
||||
assertEquals(0, personService.getPeopleFilteredByProperty(ContentModel.PROP_ORGID, "microsoft").size());
|
||||
|
||||
personService.deletePerson("derek");
|
||||
assertEquals(0, personService.getAllPeople().size());
|
||||
@@ -301,6 +307,12 @@ public class PersonTest extends BaseSpringTest
|
||||
|
||||
assertEquals(1, personService.getAllPeople().size());
|
||||
assertTrue(personService.getAllPeople().contains(personService.getPerson("Derek")));
|
||||
assertEquals(1, personService.getPeopleFilteredByProperty(ContentModel.PROP_USERNAME, "Derek").size());
|
||||
assertEquals(1, personService.getPeopleFilteredByProperty(ContentModel.PROP_EMAIL, "dh@dh").size());
|
||||
assertEquals(1, personService.getPeopleFilteredByProperty(ContentModel.PROP_ORGID, "alfresco").size());
|
||||
assertEquals(0, personService.getPeopleFilteredByProperty(ContentModel.PROP_USERNAME, "Glen").size());
|
||||
assertEquals(0, personService.getPeopleFilteredByProperty(ContentModel.PROP_EMAIL, "gj@email.com").size());
|
||||
assertEquals(0, personService.getPeopleFilteredByProperty(ContentModel.PROP_ORGID, "microsoft").size());
|
||||
assertEquals(personService.personExists("derek"), EqualsHelper.nullSafeEquals(personService.getUserIdentifier("derek"), "Derek"));
|
||||
assertEquals(personService.personExists("dEREK"), EqualsHelper.nullSafeEquals(personService.getUserIdentifier("dEREK"), "Derek"));
|
||||
assertEquals(personService.personExists("DEREK"), EqualsHelper.nullSafeEquals(personService.getUserIdentifier("DEREK"), "Derek"));
|
||||
|
@@ -154,6 +154,16 @@ public interface PersonService
|
||||
*/
|
||||
@Auditable
|
||||
public Set<NodeRef> getAllPeople();
|
||||
|
||||
/**
|
||||
* Get people filtered by the given property name/value pair
|
||||
*
|
||||
* @param propertyKey property key of property to filter people by
|
||||
* @param propertyValue property value of property to filter people by
|
||||
* @return people filtered by the given property name/value pair
|
||||
*/
|
||||
@Auditable
|
||||
public Set<NodeRef> getPeopleFilteredByProperty(QName propertyKey, Serializable propertyValue);
|
||||
|
||||
/**
|
||||
* Return the container that stores people.
|
||||
|
Reference in New Issue
Block a user