Get behaviourFilter instance in JavaDelegate class

cancel
Showing results for 
Search instead for 
Did you mean: 
Skyor
Active Member

Get behaviourFilter instance in JavaDelegate class

Jump to solution

Hello. I need to change owner property of document, for this i use next code

behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
nodeService.setProperty(nodeRef, ContentModel.PROP_CREATOR, NEW_DOCUMENT_OWNER);
nodeService.setProperty(nodeRef, ContentModel.PROP_MODIFIER, NEW_DOCUMENT_OWNER);
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);

in service task of workflow in class ChangeDocumentsOwner implements JavaDelegate.

I call this file in file.bpmn20.xml 

<serviceTask id="servicetask1" name="Service Task" activiti:async="true" activiti:class="org.alfresco.repo.workflow.activiti.script.ChangeDocumentsOwner"></serviceTask>

But i can't get behaviourFilter instance. nodeService instance i got from the next code

Map<Object, Object> registeredBeans = Context.getProcessEngineConfiguration().getBeans();
ServiceRegistry registry = (ServiceRegistry)registeredBeans.get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
NodeService nodeService = registry.getNodeService();

I tried to register bean ChangeDocumentsOwner 

<bean id="ChangeDocumentsOwner" class="org.alfresco.repo.workflow.activiti.script.ChangeDocumentsOwner" parent="webscript">
        <property name="nodeService" ref="NodeService" />
        <property name="behaviourFilter" ref="policyBehaviourFilter" />
</bean>

but properties was null. Can i get behaviourFilter instance? Or, maybe there are other solutions to my problem?

1 Solution

Accepted Solutions
Skyor
Active Member

Re: Get behaviourFilter instance in JavaDelegate class

Jump to solution

Problem was in bean and call inside service task. 
Correct code

    <serviceTask id="servicetask1" name="Service Task" activiti:async="true" activiti:delegateExpression="${ChangeDocumentsOwner}"></serviceTask>
and
<bean id="AbstractChangeDocumentsOwner" parent="baseJavaDelegate" abstract="true" depends-on="activitiBeanRegistry" />
<bean id="ChangeDocumentsOwner" parent="AbstractChangeDocumentsOwner" class="org.alfresco.repo.workflow.activiti.script.ChangeDocumentsOwner">
    <property name="nodeService" ref="NodeService" />
    <property name="behaviourFilter" ref="policyBhaviourFilter" />
</bean>

View solution in original post

1 Reply
Skyor
Active Member

Re: Get behaviourFilter instance in JavaDelegate class

Jump to solution

Problem was in bean and call inside service task. 
Correct code

    <serviceTask id="servicetask1" name="Service Task" activiti:async="true" activiti:delegateExpression="${ChangeDocumentsOwner}"></serviceTask>
and
<bean id="AbstractChangeDocumentsOwner" parent="baseJavaDelegate" abstract="true" depends-on="activitiBeanRegistry" />
<bean id="ChangeDocumentsOwner" parent="AbstractChangeDocumentsOwner" class="org.alfresco.repo.workflow.activiti.script.ChangeDocumentsOwner">
    <property name="nodeService" ref="NodeService" />
    <property name="behaviourFilter" ref="policyBhaviourFilter" />
</bean>