cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieve content type hierarchy using Java API

webroro
Champ in-the-making
Champ in-the-making
Hi Alfresco’s gurus,

Using the Java API, I’m trying to retrieve a tree of subtypes inherited from the cm:content type. I’d like to display a tree of document type hierarchy. I used the dictionaryService bean and tried to use the following code but getting an error (see below):
TypeDefinition rootContentType = dictionaryService.getType(QName.createQName("{" + NamespaceService.CONTENT_MODEL_1_0_URI + "}content"));
       
for (QName name : 
dictionaryService.getSubTypes(rootContentType.getName()), false)){
   System.out.println(" +– QName : " + name.toString());
}       

The error I’m facing:

08:29:39,546 User:admin ERROR [ui.common.Utils] A system error happened during the operation: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.n
ode.NodeServicePolicies$OnUpdateNodePolicy.onUpdateNode(org.alfresco.service.cmr.repository.NodeRef) in transaction 6bbe0925-73b3-41e7-8540-beabac5c04d2
org.alfresco.error.AlfrescoRuntimeException: Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.node.NodeServicePolicies$OnUpdateNodePolicy.onUpda
teNode(org.alfresco.service.cmr.repository.NodeRef) in transaction 6bbe0925-73b3-41e7-8540-beabac5c04d2
        at org.alfresco.repo.policy.TransactionBehaviourQueue.execute(TransactionBehaviourQueue.java:201)
        at org.alfresco.repo.policy.TransactionBehaviourQueue.beforeCommit(TransactionBehaviourQueue.java:133)
        at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.doBeforeCommit(AlfrescoTransactionSupport.java:671)
        at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.doBeforeCommit(AlfrescoTransactionSupport.java:651)
        at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:611)
        at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:48)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:821)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:637)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:624)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:307)
        at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:431)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:256)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:172)
        at org.alfresco.web.bean.dialog.BaseDialogBean.finish(BaseDialogBean.java:127)
        at org.alfresco.web.bean.content.CreateContentWizard.finish(CreateContentWizard.java:118)
        at org.alfresco.web.bean.wizard.WizardManager.finish(WizardManager.java:580)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
        at javax.faces.component.UICommand.broadcast(UICommand.java:109)
        at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
        at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.alfresco.module.vti.VtiContextFilter.doFilter(VtiContextFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
        at java.lang.Thread.run(Thread.java:595)
[b]Caused by: java.lang.NullPointerException
        at org.alfresco.repo.dictionary.DictionaryDAOImpl.getSubTypes(DictionaryDAOImpl.java:543)[/b]
        at org.alfresco.repo.dictionary.DictionaryComponent.getSubTypes(DictionaryComponent.java:133)
        at com.myapplication.alfresco.event.AlfrescoEventHandler.processDocument(AlfrescoEventHandler.java:141)
        at com.myapplication.alfresco.event.AlfrescoEventHandler.onUpdateNode(AlfrescoEventHandler.java:83)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.alfresco.repo.policy.JavaBehaviour$JavaMethodInvocationHandler.invoke(JavaBehaviour.java:179)
        at $Proxy51.onUpdateNode(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor282.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.alfresco.repo.policy.TransactionBehaviourQueue.execute(TransactionBehaviourQueue.java:189)
        … 48 more


Could anyone help-me? Does anyone exprience this in the past?

Kind regards
1 REPLY 1

brian_robinson
Champ in-the-making
Champ in-the-making
Hi there,

I tried out your code, and it worked for me.  I did change one thing though - your for loop had an extra ')' in there after rootContentType.getName() .  I'm sure that wasn't your problem though, since you were able to run and generate that exception which would only be possible if you were able to compile.


        DictionaryService dictionaryService = _serviceRegistry.getDictionaryService();
        TypeDefinition rootContentType = dictionaryService.getType(QName.createQName("{" + NamespaceService.CONTENT_MODEL_1_0_URI + "}content"));
        for (QName name : dictionaryService.getSubTypes(rootContentType.getName(), false)) {
            System.out.println(" +– QName : " + name.toString());
        }

Anyway, in looking closer at the exception, you have a NullPointerException in there.  In looking at the source code, it appears that the only way you could get a NullPointer there is if something was wrong with the content model.  Therefore, I suggest checking your log file upon server startup (at $TOMCAT_HOME/logs/catalina.out).  If there are any exceptions output there as a result of a content model not being parsed, I would think that would cause a the NullPointer you're seeing.  If that is the case, be sure to fix your content model problem before trying again.  If that is not the case, then all I can suggest is that you download the Alfresco source code, connect a remote debugger, and step through the code until you can see exactly what is going on.

Thanks,
-Brian