If someone want to get all context over EngineAPI:
Business entity
public class BusinessEntity implements Serializable {
/**
* <Column name>/<Column value>
*/
Map<String, Object> data = new HashMap<>();
public Map<String, Object> getData() {
return this.data;
}
public void setData(Map<String, Object> data) {
this.data = data;
}
}
Function in my generic Repository:
default List<BusinessEntity> find(@NotNull JdbcTemplate jdbcTemplate, @NotNull String tableName, Map<String, Object> parameters) {
List<BusinessEntity> result = new ArrayList<>();
jdbcTemplate
.query("SELECT * FROM public." + tableName + " t " + createWhereClause(parameters),
(rs, rowNum) -> result.addAll(getObject(rs, rowNum)));
logger.debug("Number of entities that have been find : "+result.size());
return result;
}
And my code to get my context:
public Map<String, Object> getBonitaContext(long processInstanceId) throws LoginException {
Map<String, Object> evaluatedContex = new HashMap<String, Object>();
APISession session = bonitaAuthenticationService.loginWithDefaultUser();
ProcessAPI processApi;
try {
processApi = TenantAPIAccessor.getProcessAPI(session);
Map<String, Serializable> context;
//get context depends of type ( archive or starting)
try {
context = processApi.getProcessInstanceExecutionContext(processInstanceId);
} catch (ProcessInstanceNotFoundException ex) {
context = processApi.getArchivedProcessInstanceExecutionContext(processInstanceId);
}
for (Map.Entry<String, Serializable> entry : context.entrySet()) {
try {
String entryName = entry.getKey();
//remove "_ref" if is present for the entry key ( if "ref", it's a DAO object)
if (entry.getKey().endsWith("_ref")) {
entryName = entry.getKey().replace("_ref", "");
}
//Transform simple object
if (entry.getValue() instanceof SimpleBusinessDataReference) {
SimpleBusinessDataReference contextElement = (SimpleBusinessDataReference) entry.getValue();
int lastDot = contextElement.getType().lastIndexOf(".") + 1;
String clazz = contextElement.getType().substring(lastDot, contextElement.getType().length());
//Search the value in BDD if storage_id is not null
if (contextElement.getStorageId() != null) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("persistenceid", contextElement.getStorageId());
List<BusinessEntity> result = cProcessBusinessDataRepository.findBy(clazz, parameters);
evaluatedContex.put(entry.getKey(), result.get(0));
} else {
evaluatedContex.put(clazz, null);
}
logger.debug("SimpleBusinessDataReference Name = " + entry.getKey() + " Type = " + contextElement.getType());
}//Transform (DAO)object list
else if (entry.getValue() instanceof MultipleBusinessDataReference) {
MultipleBusinessDataReference contextElement = (MultipleBusinessDataReference) entry.getValue();
logger.debug("MultipleBusinessDataReference Name = " + entry.getKey() + " Type = " + contextElement.getType());
//Search the value in BDD if storage_id is not null
if (!contextElement.getStorageIds().isEmpty()) {
int lastDot = contextElement.getType().lastIndexOf(".") + 1;
String clazz = contextElement.getType().substring(lastDot, contextElement.getType().length());
Map<String, Object> parameters = new HashMap<>();
parameters.put("persistenceid", contextElement.getStorageIdsAsString());
//Récupération des objets dans la bdd
List<BusinessEntity> result = cProcessBusinessDataRepository.findBy(clazz, parameters);
evaluatedContex.put(entry.getKey(), result);
}
}//Transform Document object
else if (entry.getValue() instanceof Document) {
Document contextElement = (Document) entry.getValue();
logger.debug("Document Name = " + entry.getKey() + " Type = " + Document.class.getTypeName());
evaluatedContex.put(entry.getKey(), contextElement);
} else if (entry.getValue() instanceof ArrayList) {
ArrayList contextElement = (ArrayList) entry.getValue();
evaluatedContex.put(entry.getKey(), contextElement);
logger.debug("Default Name = " + entry.getKey() + " Type = " + ArrayList.class.getTypeName());
} else {
if (entry.getValue() != null) {
BusinessDataReference contextElement = (BusinessDataReference) entry.getValue();
evaluatedContex.put(entry.getKey(), contextElement);
logger.debug("Default Name = " + entry.getKey() + " Type = " + contextElement.getType());
}
}
break;
} catch (Exception ex) {
logger.error("Impossible de cast l'élément", ex);
}
}
} catch (BonitaHomeNotSetException | ServerAPIException | UnknownAPITypeException | ProcessInstanceNotFoundException | ExpressionEvaluationException ex) {
logger.error(ex);
}
return evaluatedContex;
}