Java Code Examples for org.alfresco.service.cmr.dictionary.ClassDefinition#isContainer()

The following examples show how to use org.alfresco.service.cmr.dictionary.ClassDefinition#isContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VersionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void defaultOnCreateVersion(
        QName classRef,
        NodeRef nodeRef, 
        Map<String, Serializable> versionProperties, 
        PolicyScope nodeDetails)
{
    ClassDefinition classDefinition = this.dictionaryService.getClass(classRef);    
    if (classDefinition != null)
    {           
        boolean wasMLAware = MLPropertyInterceptor.setMLAware(true);
        try
        {
            // Copy the properties (along with their aspect)
            Map<QName,PropertyDefinition> propertyDefinitions = classDefinition.getProperties();
            for (QName propertyName : propertyDefinitions.keySet()) 
            {
                Serializable propValue = this.nodeService.getProperty(nodeRef, propertyName);
                nodeDetails.addProperty(classRef, propertyName, propValue);
            }
            // Also copy the aspect with no properties in its definition
            if (classDefinition.isAspect() && !nodeDetails.getAspects().contains(classRef))
            {
                nodeDetails.addAspect(classRef);
            }
        }
        finally
        {
            MLPropertyInterceptor.setMLAware(wasMLAware);
        }
        
        // Version the associations (child and target)
        Map<QName, AssociationDefinition> assocDefs = classDefinition.getAssociations();

        // TODO: Need way of getting child assocs of a given type
        if (classDefinition.isContainer())
        {
            List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(nodeRef);
            for (ChildAssociationRef childAssocRef : childAssocRefs) 
            {
                if (assocDefs.containsKey(childAssocRef.getTypeQName()))
                {
                    nodeDetails.addChildAssociation(classDefinition.getName(), childAssocRef);
                }
            }
        }
        
        // TODO: Need way of getting assocs of a given type
        List<AssociationRef> nodeAssocRefs = this.nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
        for (AssociationRef nodeAssocRef : nodeAssocRefs) 
        {
            if (assocDefs.containsKey(nodeAssocRef.getTypeQName()))
            {
                nodeDetails.addAssociation(classDefinition.getName(), nodeAssocRef);
            }
        }
    }
}