cancel
Showing results for 
Search instead for 
Did you mean: 

creating association

jeyaa
Champ in-the-making
Champ in-the-making
Hi all,

I have a model like

<type name="custom:customType">
         <title>custom Root Content Type</title>
         <parent>cm:content</parent>
         <associations>
            <child-association name="custom:myAssoc">
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>custom:comments</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </child-association>
         </associations>
         <mandatory-aspects>
            <aspect>cm:generalclassifiable</aspect>
            <aspect>custom:Info</aspect>
         </mandatory-aspects>
      </type>
                ……….
                ………..
               <type name="custom:comments">
         <title>Custom comment Type</title>
         <parent>custom:customType</parent>
         <mandatory-aspects>
            <aspect>custom:commentable</aspect>
         </mandatory-aspects>
      </type>

Here is my aspect…
<aspect name="custom:commentable">
         <title>Custom commentable Aspect</title>
         <properties>
            <property name="custom:timeStamp">
               <type>d:datetime</type>
            </property>
            <property name="custom:commentAuthor">
               <type>d:text</type>
            </property>
            <property name="custom:commentType">
               <type>d:text</type>
               <mandatory>true</mandatory>
               <constraints>
                  <constraint ref="custom:commentTypeList" />
               </constraints>
            </property>
            <property name="custom:commentDescription">
               <type>d:text</type>
            </property>
         </properties>
      </aspect>

Now I have a content called "Comment_Content.txt" of type "custom:comments", and have another content called "CustomType_Content.txt". Now I need to make "Comment_Content.txt" associated to "CustomType_Content.txt". So did like this.

this.nodeService.createAssociation(customTypeNodeRef, commentNodeRef,  new Node(commentNodeRef).getType());

But it is showing exception. Here is the stack trace.

java.lang.IllegalArgumentException: Association {http://www.Custom.com/model/content/1.0}comments has not been defined in the data dictionary
        at org.alfresco.repo.policy.AssociationPolicyDelegate.checkAssocType(AssociationPolicyDelegate.java:80)
        at org.alfresco.repo.policy.AssociationPolicyDelegate.get(AssociationPolicyDelegate.java:166)
        at org.alfresco.repo.node.AbstractNodeServiceImpl.invokeOnCreateAssociation(AbstractNodeServiceImpl.java:667)
        at org.alfresco.repo.node.db.DbNodeServiceImpl.createAssociation(DbNodeServiceImpl.java:1864)
        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:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:104)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy11.createAssociation(Unknown Source)
        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:597)
        at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:215)
        at $Proxy12.createAssociation(Unknown Source)
        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:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:303)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:303)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:269)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:269)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy11.createAssociation(Unknown Source)
        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:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:80)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:43)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:135)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy11.createAssociation(Unknown Source)
        at com.someco.web.bean.comments.CommentBean.init(CommentBean.java:55)
        at com.someco.web.bean.comments.CommentBean.getCommentsList(CommentBean.java:92)
        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:597)
        at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:457)
        at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:85)
        at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:535)
        at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
        at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:386)
        at org.alfresco.web.ui.common.component.data.UIRichList.getValue(UIRichList.java:151)
        at org.alfresco.web.ui.common.component.data.UIRichList.getDataModel(UIRichList.java:512)
        at org.alfresco.web.ui.common.component.data.UIRichList.bind(UIRichList.java:448)
        at org.alfresco.web.ui.common.renderer.data.RichListRenderer.encodeChildren(RichListRenderer.java:77)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:527)
        at javax.faces.webapp.UIComponentTag.encodeChildren(UIComponentTag.java:483)
        at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:364)
        at org.apache.jsp.jsp.extension.document_002ddetails_jsp._jspx_meth_a_005frichList_005f2(document_002ddetails_jsp.java:5708)
        at org.apache.jsp.jsp.extension.document_002ddetails_jsp._jspx_meth_a_005fpanel_005f13(document_002ddetails_jsp.java:5614)
        at org.apache.jsp.jsp.extension.document_002ddetails_jsp._jspService(document_002ddetails_jsp.java:612)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
        at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:968)
        at org.apache.jsp.jsp.dialog.container_jsp._jspService(container_jsp.java:647)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
        at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
        at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
        at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
        at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:104)
        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:597)
        at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:116)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy233.doFilter(Unknown Source)
        at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.repo.web.filter.beans.NullFilter.doFilter(NullFilter.java:68)
        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:597)
        at org.alfresco.repo.management.subsystems.ChainingSubsystemProxyFactory$1.invoke(ChainingSubsystemProxyFactory.java:116)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy233.doFilter(Unknown Source)
        at org.alfresco.repo.web.filter.beans.BeanProxyFilter.doFilter(BeanProxyFilter.java:82)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
        at java.lang.Thread.run(Thread.java:619)

Is this the right way to create association?. Please suggest on this.


Regards,
Jeya
11 REPLIES 11

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi Jeyaa,

This seems to be correct  , the only thing  "new Node(commentNodeRef).getType()" . Please check if this  is returning proper value.

Thanks,

jeyaa
Champ in-the-making
Champ in-the-making
Thanks Amita,

Yeah I have checked it out and the value am getting for 
new Node(commentNodeRef).getType()

The above code is returning
http://www.Custom.com/model/content/1.0}comments

Am wondering on the exception that is occurring

java.lang.IllegalArgumentException: Association {http://www.Custom.com/model/content/1.0}comments has not been defined in the data dictionary

Any idea on this.


Regards,
Jeya

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi Jeyaa,


The method has two parameters correct but the third one you have to  create  QName of association and provide that.
For example : you have to create object like QName.createQName("http://www.Custom.com/model/content/1.0", "custom:myAssoc");

so the  correct method should be  similar to below code:
this.nodeService.createAssociation(customTypeNodeRef, commentNodeRef, QName.createQName("http://www.Custom.com/model/content/1.0", "custom:myAssoc"));

Thanks,

jeyaa
Champ in-the-making
Champ in-the-making
Thanks Amita. This is working. I never checked the association name from my code. This was really helpful. Thanks once again.  And one question. I want the "Comment_Content" has to be deleted if the "Customtype_content"  is deleted. What shall suppose to do for that.


Regards,
Jeyamurugan A

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi Jeyaa,

Since you have  already used child association  , it is going to  delete  associated  nodes  also. So no additional configurations are required.


Thanks,

jeyaa
Champ in-the-making
Champ in-the-making
Amita,

But its not happening like that. If I delete the "CustomType_Content.txt" the associated comment file is not getting deleted. And also if I try to get the number of child associations for the "CustomType_Content.txt" like

Map childAssoc= new Node(customTypeNodeRef).getChildAssociations();

The childAssoc size is 0. But If try to get associations like this,

Map assoc = new Node(nodeRef).getAssociations();

now the assoc size is 1.

I think the following line did not made the "comment_content" child associated. So what may be the problem in here.

this.nodeService.createAssociation(customTypeNodeRef, commentNodeRef, QName.createQName("http://www.Custom.com/model/content/1.0", "custom:myAssoc"));


Regards,
Jeyaa

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi Jeyaa,

Please use the below code:
Collection<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(nodeRef);
          if (childRefs.size() != 0)
            {
               for (ChildAssociationRef ref : childRefs)
               {
                 System.out.println(ref.getChildRef());
                 System.out.println(nodeService.gteProperty(ref.getChildRef(), ContentModel.PROP_NAME));
                }
         }

Thanks,

jeyaa
Champ in-the-making
Champ in-the-making
Thanks,

I tried on the above code and the size of the collection is 0. What may be the problem?

amitabhandari1
Champ in-the-making
Champ in-the-making
Hi Jeyaa,

what   you are passing in the nodeRef.

Thanks,