cancel
Showing results for 
Search instead for 
Did you mean: 

Custom folder, can only contain a specific type

frankb
Champ in-the-making
Champ in-the-making
Hi,

Is there possible to, by configuration, restricting a new custom folder type to only contain certain types?

Given my type:
 <type name="dwdb:DB">
         <title>DB</title>
         <parent>cm:folder</parent>
      </type>

Is there any configuration option to specify which types this new folder can contain?

Frank
5 REPLIES 5

frankb
Champ in-the-making
Champ in-the-making
or any other way of solving it would be greatly appreciated.

afaust
Legendary Innovator
Legendary Innovator
Hello Frank,

I am sorry, there is no way to configure an override for the target class of a child association. We achieved something similar to what you are trying to do by defining our special child association(s) and then implementing a behavior / policy, which automatically moves matching objects from cm:contains to our child association and throws an exception when someone tries to create a non-compliant child. In custom forms / UI controls, we expose our child association instead of the cm:contains, so that elements like the Alfresco object-finder can use the correct type information to only allow selection / addition of correctly typed objects.

Regards
Axel Faust

acurs
Champ in-the-making
Champ in-the-making
Hello Alex,
      very good solution. Although yo were very clear in your response I wonder how your child_association redefinition looks, and how you implement the behaviour for the target. Did you have any trouble when changing the custom UI to show the target with the alfresco object finder?

I have space template, to instantiate every time i create a certaint site type, it's look like this:

-> Project (space)
          ->   initiation folder (space) -> i want to force this folder to ave initiation_docs content types only
                          ->    authorization (pdf)
                          ->    charter (pdf)
          ->    planification folder (space)
……

Danke,
    Alberto

afaust
Legendary Innovator
Legendary Innovator
Hello,

we did not encounter any problems with the UI of either object-finder or the documentlibrary in Share - both components retrieve any child independent of the type of child association. There are some components though which are rather hard-coded to the FileFolderService and its reliance on cm:contains - e.g. all file server protocols and Sharepoint do not work correctly without cm:contains. In cases where we require these features, we alter our approach a little - we move the new child to the correct child association, but create a secondary child association with cm:contains as a kind of "shadow" to let the FileFolderService-reliant components handle the content their way.

Actually, we did not re-define a child association - we rather added our own:

<type name="opapp:company">
   <title>Company</title>
   <description></description>
   <parent>cm:folder</parent>
   <associations>
      <child-association name="opapp:businessUnit">
         <source>
            <mandatory>false</mandatory>
            <many>false</many>
         </source>
         <target>
            <class>opapp:businessUnit</class>
            <mandatory>false</mandatory>
            <many>true</many>
         </target>
      </child-association>
   </associations>
</type>

A behaviour written in Java could look something like this:

public void onCreateNode(final ChildAssociationRef childAssocRef) {
   final NodeRef element = childAssocRef.getChildRef();
   final QName assocType = childAssocRef.getTypeQName();
   if (assocType.equals(ContentModel.ASSOC_CONTAINS)) {
      this.nodeService.moveNode(element, childAssocRef.getParent(), OurModel.ASSOC_BUSINESS_UNIT, childAssocRef.getQName());

      // create a secondary cm:contains assoc for FileFolder-based features
      this.nodeService.addChild(childAssocRef.getParent(), element, ContentModel.ASSOC_CONTAINS, childAssocRef.getQName());
   }
}

The behavior above would need to be registered on the event OnCreateNode and the type opapp:businessUnit to be called at the correct point in time - also it would of course need to include checks wether the parent is indeed a opapp:company which actually has a child association opapp:businessUnit.

In more recent customizations of Share we have also used a different approach:
* the upload.post.js web script has been altered to allow passing in a target child association by an uploader
* the upload action and uploader component in the documentlibrary have been customized to already set the correct document type and pass the appropriate target child association dynamically, depending on the current location in the UI

Alfresco and Share are very flexible on how you can achieve something like this depending on the specific requirements. Instead of using a behavior we could have also chosen to rely on rules and actions for this. For what you are trying to achieve, rules and actions may actually be the way to go - instead of hardwiring this all into Java, you could provide a small script which does the trick and configure a rule to trigger the script. Now when you copy spaces from a space template, the rules you have configured are automatically copied as well and ensure that your newly created spaces behave appropriately.

Regards
Axel

acurs
Champ in-the-making
Champ in-the-making
Thanks Alex, I think I will try like you say the rules and actions way. But still was a great help to understand a little bit better how you could do this through the foundation services. Regards