cancel
Showing results for 
Search instead for 
Did you mean: 

how to fetch folder contents along with other custom types

chaituu
Champ in-the-making
Champ in-the-making
i am newbie to alfresco.This is the custom model.i need to fetch folder contents(cm:folder) also with other custom types(sparepart,metal).below method used to fetch the types but folder contents are not coming.what changes need to be made in custom model xml file and also in java class.

List associationRefs = nodeService.getTargetAssocs(nodeRef, EMPContentModel.EMP_NAMESPACE_URI_QNAME_PATTERN);



if i add another association under emp:fac then also its not working..


  <association name="emp:containsFactoryFolder">
                        <source>
                            <mandatory>false</mandatory>
                            <many>true</many>
                        </source>
                        <target>
                            <class>cm:folder</class>
                            <mandatory>false</mandatory>
                            <many>true</many>
                        </target>
                    </association>


custommodel.xml



<namespaces>
        <namespace uri="http://www.emp.com/model/emp-cms-core/2.0" prefix="emp"/>

    </namespaces>


    <types>
        <type name="emp:container">
            <title>Container</title>
            <parent>cm:folder</parent>
        </type>

        <type name="emp:fac">
            <title>Factory</title>
            <parent>emp:container</parent>

            <associations>
                <association name="emp:containsFactoryAsset">
                    <source>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </source>
                    <target>
                        <class>emp:asset</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
                <association name="emp:containsFactorySparePart">
                    <source>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </source>
                    <target>
                        <class>emp:sparepart</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
                <association name="emp:containsFactoryMetal">
                    <source>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </source>
                    <target>
                        <class>emp:metal</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
            </associations>
         </type>

        <type name="emp:sparepart">
            <title>Spare Part</title>
            <parent>emp:container</parent>
            <properties>
                <property name="emp:sparePartNumber">
                    <title>Spare Part Number</title>
                    <type>d:text</type>
               </property>
           </properties>

            <associations>
                <association name="emp:containsSparePartAsset">
                    <source>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </source>
                    <target>
                        <class>emp:asset</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
                <association name="emp:containsSparePartMetal">
                    <source>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </source>
                    <target>
                        <class>emp:metal</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
                <association name="emp:derivesFromSparePart">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>emp:sparepart</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
            </associations>
         </type>
        <type name="emp:metal">
            <title>Metal</title>
            <parent>emp:container</parent>

            <associations>
                <association name="emp:containsMetalAsset">
                    <source>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </source>
                    <target>
                        <class>emp:asset</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
                <association name="emp:derivesFromMetal">
                    <source>
                        <mandatory>false</mandatory>
                        <many>false</many>
                    </source>
                    <target>
                        <class>emp:metal</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
                <association name="emp:containsMetalMetal">
                    <source>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </source>
                    <target>
                        <class>emp:metal</class>
                        <mandatory>false</mandatory>
                        <many>true</many>
                    </target>
                </association>
            </associations>
        </type>

        <type name="emp:content">
            <title>Content</title>
            <parent>cm:content</parent>
        </type>
        <type name="emp:asset">
            <title>Asset</title>
            <parent>emp:content</parent>
       </type>

    </types>

</model>
1 REPLY 1

steven_okennedy
Star Contributor
Star Contributor
Hi chaituu,

How are you creating the actual data that you are trying to retrieve? I.e. how are you creating your instances of emp:fac, emp:asset etc. and how are you relating them together (associating the instances of the types together)?  There don't seem to be any major issues with the way that your model is constructed (except maybe that it seems strange that you've defined many-to-many relationships across the board).

Because each of your types extends from cm:folder (indirectly), each of these has the capacity to have it's own children - inheriting the cm:contains child-association - but if you want to link out to an arbitrary folder as you've defined in your emp:containsFactoryFolder association and get that folderr's contents, you would first need to traverse your custom association and then traverse the cm:contains child-association of the folder (or just call nodeService.getChildAssocs(folder) ) to get the contents of that folder.

Regards

Steven
Getting started

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.