Bonita Studio 6.3 - How do I get the ProcessDefinitionId and processInstanceId variables in java (not groovy) code?

1
0
-1

I am trying to write some informational data to a log so we can easily track a workflows progress without having to log into Bonita. Since we share the connector that we write with many workflows I need to know what process name, version, and instance (case) id is writing to the log file.

I can easily do this using a Groovy script connector with code like this:

*import org.bonitasoft.engine.bpm.process.ProcessDefinition; import org.bonitasoft.engine.api.ProcessAPI; import org.slf4j.Logger; import org.slf4j.LoggerFactory;

ProcessAPI processApi = apiAccessor.getProcessAPI(); ProcessDefinition process = processApi.getProcessDefinition(processDefinitionId);

Logger logger = LoggerFactory.getLogger("org.bonitasoft.groovy.script.logNoMetadataNothingToDo"); logger.error("processName=" + process.name + " processVersion=" + process.version + " processInstanceId=" + processInstanceId.toString() + " has no metadata so there is nothing for it to do.");*

I am trying to do the same thing in a java connector implementation (not groovy) but I do not see how I can get the processDefinitionId and processInstanceId variables that are provided to a groovy script. Can someone share an example of how to get this data in a java connector?

1 answer

1
0
-1
This one is the BEST answer!

I've answered my own question: Here is how you do it if anyone is interested:

package org.bonitasoft.connector;

import org.bonitasoft.engine.connector.ConnectorException; import org.bonitasoft.engine.bpm.process.ProcessDefinition; import org.bonitasoft.engine.api.ProcessAPI; import org.slf4j.Logger; import org.slf4j.LoggerFactory;

public class SomethingImpl extends AbstractSomethingImpl {

private static final Logger logger = LoggerFactory.getLogger(SomethingImpl.class); 

@Override
protected void executeBusinessLogic() throws ConnectorException{        
    ProcessAPI processApi = apiAccessor.getProcessAPI();

    try {
        ProcessDefinition process = processApi.getProcessDefinition(getExecutionContext().getProcessDefinitionId());
        logger.info("processName=" + process.getName() + " processVersion=" + process.getVersion() + 
                " processInstanceId=" + getExecutionContext().getProcessInstanceId());
    } catch (Exception e) {
                    //Handle errors here
        throw new ConnectorException(e);
    }
 }

}

Comments

Submitted by Sean McP on Thu, 08/28/2014 - 08:38

Many thanks Ryan, I'll be using it at some time...

best regards Seán

Notifications