Ji !
The question is : how to get in java the value of a variable set during the process ? (for an external use of course)
Which API ? I don’t find any clue in the javadoc !
Thanks for helping !
Ji !
The question is : how to get in java the value of a variable set during the process ? (for an external use of course)
Which API ? I don’t find any clue in the javadoc !
Thanks for helping !
Answer edited:
First, a simple recommendation: instead of using the getRootProcessInstanceId()
method, you should use the getSourceObjectId()
method. In fact, getArchivedProcessDataInstance
expected to receive the process instance id as it was when the instance was “live” (i.e. not yet archived). Using getRootProcessInstanceId()
should not be an issue as searchArchivedProcessInstances()
will not return any sub-processes (and so root process instance should be the same as source object id).
I didn’t did any important modification and it seems “to work just fine for me”.
You can find below my version of the code and the associated Maven pom.xml file to build the project. Maybe you can try to run it and share with me log output (or your existing log output / stack trace).
package org.bonitasoft.democlientv6;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bonitasoft.engine.api.ApiAccessType;
import org.bonitasoft.engine.api.LoginAPI;
import org.bonitasoft.engine.api.ProcessAPI;
import org.bonitasoft.engine.api.TenantAPIAccessor;
import org.bonitasoft.engine.bpm.data.ArchivedDataInstance;
import org.bonitasoft.engine.bpm.process.ArchivedProcessInstance;
import org.bonitasoft.engine.bpm.process.ArchivedProcessInstancesSearchDescriptor;
import org.bonitasoft.engine.search.SearchOptions;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.SearchResult;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.engine.util.APITypeManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
private static final String BONITA_SERVER_HOSTNAME = "localhost";
private static final String BONITA_SERVER_PORT = "8080";
private static final String BONITA_WEBAPP_NAME = "bonita";
private static final String PROCESS_NAME = "process_name";
public static void main(String[] args) throws Exception {
Map<String, String> apiTypeManagerParams = new HashMap<>();
apiTypeManagerParams.put("server.url", "http://"
+ BONITA_SERVER_HOSTNAME + ":" + BONITA_SERVER_PORT);
apiTypeManagerParams.put("application.name", BONITA_WEBAPP_NAME);
APITypeManager.setAPITypeAndParams(ApiAccessType.HTTP,
apiTypeManagerParams);
LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
APISession session = loginAPI.login("walter.bates", "bpm");
ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(session);
SearchOptions searchOptions = new SearchOptionsBuilder(0, 250).filter(
ArchivedProcessInstancesSearchDescriptor.NAME, PROCESS_NAME)
.done();
SearchResult<ArchivedProcessInstance> archivedProcessInstanceResults = processAPI
.searchArchivedProcessInstances(searchOptions);
List<ArchivedProcessInstance> archives = archivedProcessInstanceResults
.getResult();
LOGGER.info("Found {} archived process instances for process {}",
archives.size(), PROCESS_NAME);
for (ArchivedProcessInstance archivedProcessInstance : archives) {
long sourceObjectId = archivedProcessInstance.getSourceObjectId();
long rootProcessInstanceId = archivedProcessInstance
.getRootProcessInstanceId();
LOGGER.info("Root process instance: {}", rootProcessInstanceId);
LOGGER.info("Source object id: {}", sourceObjectId);
LOGGER.info("Process name: {}", archivedProcessInstance.getName());
ArchivedDataInstance di = processAPI
.getArchivedProcessDataInstance("data_name",
sourceObjectId);
String valueToRetrieve = di.getValue().toString();
LOGGER.info("value: {}", valueToRetrieve);
}
}
}
4.0.0
org.bonitasoft
demo-client-v6
0.0.1-SNAPSHOT
A standalone Java application that call Bonita BPM Execution Engine API using Bonita Client library.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[2.1,)
</versionRange>
<goals>
<goal>
copy-dependencies
</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.bonitasoft.engine</groupId>
<artifactId>bonita-client</artifactId>
<version>6.3.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.7</version>
</dependency>
</dependencies>
I had to ask in order maybe to find the solution :
Using this from ProcessRuntimeAPI
DataInstance getProcessDataInstance(String dataName,
long processInstanceId)
throws DataNotFoundException
Get the value of named data item from a specified process instance. The value is returned in a DataInstance object.
http://documentation.bonitasoft.com/javadoc/api/6.3/org/bonitasoft/engine/api/ProcessRuntimeAPI.html#getProcessDataInstance(java.lang.String, long)
When calling the getProcessDataInstance, are you sure that you set the “dataName” with exactly the same name as process data defined in the Studio?
Also can you share your code that you write in order to get the “processInstanceId” that you use?
Thanks.
I answer instead of Romain
Here is what we use :
LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
APISession apiSession = loginAPI.login(bonitaLogin, bonitaPassword);
ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(apiSession);
SearchOptions searchOptions = new SearchOptionsBuilder(0, 250).filter(ArchivedProcessInstancesSearchDescriptor.NAME,“process_name”).done();
SearchResult archivedProcessInstanceResults = processAPI.searchArchivedProcessInstances(searchOptions);
List archives = archivedProcessInstanceResults.getResult();
for (int i=0;i<archives.size();i++)
{
ArchivedProcessInstance api = (ArchivedProcessInstance) archives.get(i);
ArchivedDataInstance di = processAPI.getArchivedProcessDataInstance(“data_name”,api.getRootProcessInstanceId());
String value_to_retrieve = di.getValue().toString();
}
Currently, there is no sub process but if I call getId instead of getRoot…() it didn’t work !
I edit my answer: your code seems to work as it is. So I would be interested to know if you get any stack trace / log message in order for me to find the root cause of the issue?
Well, here are the logs : (don’t think it is very useful)
11:02:46.791 [main] INFO - Found 129 archived process instances for process XXX
11:02:46.795 [main] INFO - Root process instance: 41008
11:02:46.795 [main] INFO - Source object id: 41008
11:02:46.795 [main] INFO - Process name: XXX
11:02:46.811 [main] INFO - value: yyyyy
11:02:46.811 [main] INFO - Root process instance: 42002
11:02:46.811 [main] INFO - Source object id: 42002
11:02:46.811 [main] INFO - Process name: XXX
11:02:46.822 [main] INFO - value: eeeee
…
Ok so from the log file it seems to successfully retrieve archived process instance data value.
So I don’t understand what goes wrong for you here?
Maybe you want to get the data of currently running instance.
In such case, source code should be pretty much the same but without the “Archived” keyword in API methods and Java classes.