05-24-2006 04:38 AM
package ec.ep.dit.isp.sp.alfrescoeval;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.transaction.TransactionService;
import javax.transaction.UserTransaction;
import javax.transaction.Status;
import org.alfresco.util.ApplicationContextHelper;
import org.springframework.context.ApplicationContext;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.lock.LockType;
public class TestGetLocks {
public static void main(String[] args) throws Exception
{
// initialise app content
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
// get registry of services
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
TransactionService transactionService = serviceRegistry.getTransactionService();
UserTransaction trx = transactionService.getUserTransaction();
// authenticate
AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
authenticationService.authenticate("admin", "admin".toCharArray());
try{
trx.begin();
testGetLocks(serviceRegistry);
trx.commit();
}
catch(Exception exc){
exc.printStackTrace();
if (trx.getStatus() == Status.STATUS_ACTIVE)
{
try
{
trx.rollback();
}
catch(Throwable ee)
{
ee.printStackTrace();
}
}
}
}
/**
* We list the files locked by admin
* Prerequisites :
* With the webClient, logon as admin and checkout some files
* Expected results :
* You should obtain information about files locked by admin
* @param serviceRegistry
* @throws Exception
*
*/
public static void testGetLocks(ServiceRegistry serviceRegistry) throws Exception
{
LockService lockService = serviceRegistry.getLockService();
NodeService nodeService = serviceRegistry.getNodeService();
// get the store
StoreRef storeRef = new StoreRef(
StoreRef.PROTOCOL_WORKSPACE,
"SpacesStore"
);
if (!nodeService.exists(storeRef))
{
return;
}
List<NodeRef> nodes = lockService.getLocks(storeRef); // Give locks for current user
System.out.println("You have " + nodes.size() + " locked nodes");
String nodeTitle;
LockType lockType;
LockStatus lockStatus;
for(NodeRef nodeRef : nodes){
if (nodeRef!=null){
nodeTitle = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE);
lockType = lockService.getLockType(nodeRef);
lockStatus = lockService.getLockStatus(nodeRef);
System.out.println("the node titled \"" + nodeTitle + "\" is locked, the type if this lock is " + lockType + ", it's status is "+ lockStatus);
}
}
}
}
10:31:00,834 INFO [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 1.2.0 schema 6 - Installed version 1.2.0 schema 6
You have 2 locked nodes
net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
at net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(DaoAuthenticationProvider.java:290)
at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:159)
at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:372)
at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:37)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
at $Proxy15.getProperty(Unknown Source)
at ec.ep.dit.isp.sp.alfrescoeval.TestGetLocks.testGetLocks(TestGetLocks.java:89)
at ec.ep.dit.isp.sp.alfrescoeval.TestGetLocks.main(TestGetLocks.java:36)
05-24-2006 05:11 AM
<bean id="LockService_security" class="net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor">
org.alfresco.service.cmr.lock.LockService.getLocks=ACL_NODE.0.sys:base.Read
05-24-2006 05:21 AM
05-24-2006 10:41 AM
Thanks Kevin. It's very nice. I will test it. Please, could you also check if there is the same problem with the method "CheckOutCheckInService.getWorkingCopy()"
05-29-2006 09:12 AM
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.