03-05-2008 11:17 AM
03-07-2008 12:18 PM
package mil.navy.scr;
import java.util.Date;
import java.util.List;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ApplicationContextHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
public class Test {
private static Log s_logger = LogFactory.getLog(Test.class);
private PersonService personService;
private NodeService nodeService;
public void setPersonService(PersonService personService)
{
this.personService = personService;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void startTest() throws Exception {
ApplicationContext context = ApplicationContextHelper.getApplicationContext();
UserTransaction tx = null;
AuthenticationComponent authComponent = (AuthenticationComponent) context.getBean("AuthenticationComponent");
authComponent.setSystemUserAsCurrentUser();
Date start = new Date();
System.out.println("Looking up users: " + Long.toString(start.getTime()));
try
{
TransactionService txs = (TransactionService) context.getBean("transactionComponent");
tx = txs.getUserTransaction();
tx.begin();
// build xpath to match available User/Person objects
ServiceRegistry services = (ServiceRegistry) context.getBean(ServiceRegistry.SERVICE_REGISTRY);
NodeRef peopleRef = personService.getPeopleContainer();
String xpath = "*[like(@" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + "firstName, '%Doe%', false)" +
" or " + "like(@" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + "lastName, '%Doe%', false)]";
List<NodeRef> nodes = services.getSearchService().selectNodes(
peopleRef,
xpath,
null,
services.getNamespaceService(),
false);
for (NodeRef personRef : nodes)
{
String username = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);
if (PermissionService.GUEST_AUTHORITY.equals(username) == false)
{
String firstName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
String lastName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
System.out.println(lastName + ", " + firstName);
}
}
// commit the transaction
tx.commit();
}
catch (Exception err)
{
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
throw err;
}
finally {
Date stop = new Date();
System.out.println("Done: " + Long.toString(stop.getTime()));
System.out.println(Long.toString(stop.getTime() - start.getTime()) + " ms\r\n");
authComponent.clearCurrentSecurityContext();
}
}
/**
* @param args
*/
public static void main(String[] args) throws Exception {
ApplicationContext context = ApplicationContextHelper.getApplicationContext();
Test test = (Test) context.getBean("scrTest");
test.startTest();
test.startTest();
test.startTest();
test.startTest();
test.startTest();
test.startTest();
test.startTest();
}
}
11:53:54,842 INFO [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 2.1.0 (482) schema 64 - Installed version 2.1.0 (482) schema 64
Looking up users: 1204908835323
Doe, John
Done: 1204908918947
83624 ms
Looking up users: 1204908918952
Doe, John
Done: 1204908989867
70915 ms
Looking up users: 1204908989872
Doe, John
Done: 1204909059687
69815 ms
Looking up users: 1204909059692
Doe, John
Done: 1204909129566
69874 ms
Looking up users: 1204909129571
Doe, John
Done: 1204909199414
69843 ms
Looking up users: 1204909199420
Doe, John
Done: 1204909268074
68654 ms
Looking up users: 1204909268079
Doe, John
Done: 1204909337184
69105 ms
03-07-2008 01:21 PM
03-10-2008 02:04 PM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.