cancel
Showing results for 
Search instead for 
Did you mean: 

CMIS: Custom behaviour not triggered when creating content

oskarelisson
Champ in-the-making
Champ in-the-making
Hi!
I have a custom behaviour that is bind to  onCreateNode. This works perfectly when I add content manually via Alfresco Explorer.
But when I use a Java OpenCMIS REST/ATOM client to create content the custom behaviour isn't triggered.

The code in the cmis client looks like this:

   Document sammanstallning = inbox.createDocument(
            properties, contentStream, VersioningState.NONE);

The actual content is created as it should in the inbox folder, it's just that the custom behaviour isn't triggered.
The custom behaviour code looks like this:

this.onCreateNode = new JavaBehaviour(this, "onCreateNode",
            NotificationFrequency.TRANSACTION_COMMIT);


this.policyComponent.bindClassBehaviour(QName.createQName(
            NamespaceService.ALFRESCO_URI, "onCreateNode"), QName
            .createQName(UUModelConstants.NAMESPACE_UU_CONTENT_MODEL,
                  UUModelConstants.TYPE_XML_STRUCT), this.onCreateNode);

public void onCreateNode(ChildAssociationRef childAssRef) {

Here goes the code….
   }

Has anyone experienced this problem?

Regards
/Oskar
2 REPLIES 2

oskarelisson
Champ in-the-making
Champ in-the-making
Problem solved.
I tried to bind my behaviour to a custom type xml_struct, when I changed that to cm:content the behaviour got trigged
this.policyComponent.bindClassBehaviour(QName.createQName(
            NamespaceService.ALFRESCO_URI, "onCreateNode"), ContentModel.TYPE_CONTENT, this.onCreateNode);
Then in the method onCreateNode I can check what type the content is:

if (nodeService.getType(newNodeRef).isMatch(
         QName.createQName(UUModelConstants.NAMESPACE_UU_CONTENT_MODEL, UUModelConstants.TYPE_XML_STRUCT)      
         )) {
GOOD!
}

I'm not sure I understand why i Can't bind directly to a customized type though.
With this solution the behaviour will be triggered for every added document which isn't good from a prestanda point of view.

jgiffin
Champ in-the-making
Champ in-the-making
Thanks very much for posting this workaround.  It saved me a lot of trouble trying to track down the problem.

I have submitted a JIRA ticket for this issue: https://issues.alfresco.com/jira/browse/ALF-7994?page=com.atlassian.jira.plugin.system.issuetabpanel...

Also, problems can occur in the call to NodeService.getType() unless you first check to see if the node is deleted.  I have written about this on our blog:  http://www.ziaconsulting.com/technology/alfresco-technology/issue-with-alfresco-cmis-and-behaviors/