Modify a Alfresco's node from Activiti context

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

Modify a Alfresco's node from Activiti context

Hi,

I have a problem with JavaDelegate class than not modify node on Alfresco Contexte.

Details :

With BPMN workflow (Task service) I call a JAVA CLASS which must modify aspect properties of a (Alfresco) document's Node.

This Class running with success but Node's properties is'nt modify on Alfresco context.

Environnement :

- Alfresco 5.2

- JDK8

- H2 et MYSQL

- WIN10 et Centos7

My delegateClass :

@Component("DocValidationGiveMetadata")
  24 public class DocValidationGiveMetadata extends AbstractDelegateWorkflowImpl {
  25
  38     @Override
  39     public void executeImpl(DelegateExecution execution) {
  40       
  48         // get Alfresco's NodeRef from activiti context
  49         NodeRef nodeRef = getDocumentNodeRef(BPM_PACKAGE);
  50         // validation state
  51         nodeService.setProperty(nodeRef, EnsaModel.PROP_VALIDATE_STATE, EnsaModel.CONSTR_VALIDATE_STATE_VALIDATED);
  52        
  63         // end of task
  64         endOfTask(true);
  65     }

Class AbstractDelegateWorkflowImpl :

32     public abstract class AbstractDelegateWorkflowImpl extends BaseJavaDelegate implements AbstractDelegateWorkflow {
  33
  48     protected ServiceRegistry     serviceRegistry;
  50     protected NodeService         nodeService;
  52     protected DelegateExecution   delegateExecution;
  53
  65     @Override
  66     public void execute(DelegateExecution execution) throws Exception {
  68         this.delegateExecution = execution;
  70         setAlfrescoServices();
  72         executeImpl(execution);
  73     }
  74
  98     public void setAlfrescoServices() {
  99         Map<Object, Object> registeredBeans = Context.getProcessEngineConfiguration().getBeans();
 100         ServiceRegistry registry = (ServiceRegistry) registeredBeans.get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
 101         serviceRegistry = registry;
 102         nodeService = registry.getNodeService();
 103     }

Can you help me please?

3 Replies
mkappel
Active Member II

Re: Modify a Alfresco's node from Activiti context

Hi gavel being,

why so complicated by writing Java class. You can set a document property from within the process with one line of JS:

bpm_package.children[0].properties["cdm:InvoiceStatus"] = "Approved";

So in BPMN it looks like following:

<activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
    <activiti:field name="script">
       <activiti:string>
          <![CDATA[bpm_package.children[0].properties["cdm:InvoiceStatus"]="Approved";
          bpm_package.children[0].save();]]>
       </activiti:string>
    </activiti:field>
</activiti:taskListener>

Does this make sense?

Cheers,

Martin

gawel
Active Member II

Re: Modify a Alfresco's node from Activiti context

Thinks for your repply.

For my exemple, you right, it's make sense.

But I have simplify my exemple, so, I need to do some code a lot of complex and it's will be more easier with java.

More information about Java context :

I tried to do this on remote debug :

nodeService.setProperty(nodeRef, Model.PROP_VALIDATE_STATE, Model.CONSTR_VALIDATE_STATE_VALIDATED);

 String test = (String) nodeService.getProperty(nodeRef, Model.PROP_VALIDATE_STATE);

In this case test = "Approve" (super!)

But when you check this node from admin-nodebrowser : this property doesn't exist.

gawel
Active Member II

Re: Modify a Alfresco's node from Activiti context

Complementary informations :

1) In my case :

public abstract class AbstractDelegateWorkflowImpl extends BaseJavaDelegate(){

   public void test(){

      ServiceRegistry testservice = getServiceRegistry();

   }

}

testservice= null !!!!

It's an Alfresco bug?!