How to distinguish open case from archived case.

1
+2
-1

Hi,

I am using Bonita Community 6.3. I would like to create an overview pageflow. Specifically i would like to have a form on case level containing some data about process instance (starteBy, startedDate etc.). So in widget's initial value script I am getting ProcessInstance to get this data. The problem emerges when the case finishes and is moved to archive. I know that I can get ArchiveProcessInstance by

apiAccessor.processAPI.getFinalArchivedProcessInstance(processInstanceId)

but I have no info if the case is open or archived. The best I can do is do something like:

try {
  ProcessInstance pi = apiAccessor.processAPI.getProcessInstance(processInstanceId)
  // return data
}
catch (Exception e) {
  ArchivedProcessInstance pi = apiAccessor.processAPI.getFinalArchivedProcessInstance(processInstanceId)
  // return data
}

But it has at least three drawbacks: 1. There are two database calls instead of one 2. The excepction is logged anyway and unnecessary stacktraces obfuscate the logs 3. The code accessing the data must be rewriten, because ArchiveProcessInstance is not a subclass of ProcessInstance as I expected

The question is: Is there a way to distinguish if given processInstanceId identifies open or archived process instance?

BTW, in an overview pageflow scripts the activityInstanceId variable is provided. I believe it has no sense in this scope.

2 answers

1
+1
-1

Isolation between open and archived cases is a design choice that help to speed up operations on open cases by limiting number of entries in open cases database table.

But it had some consequences on API as you find out.

In order to avoid creation of the log when trying to get an open case that might no longer exist you can use searchProcessInstances(SearchOptions searchOptions) or searchOpenProcessInstances(SearchOptions searchOptions) (if you want to only focus on "root" process instance in case you are using sub-processes)

You can refer to:

  • The javadoc: http://documentation.bonitasoft.com/javadoc/api/6.3/org/bonitasoft/engine/api/ProcessRuntimeAPI.html#searchProcessInstances(org.bonitasoft.engine.search.SearchOptions)
  • This documentation page (adapt it to your use case)

If search returns an empty list you can then perform the call to getFinalArchivedProcessInstance as you did.

1
+1
-1

I think you've hit one of the internal issues that reside in Bonita.

There is no Single Record (in Bonita) that states what state the Process is in. A process is simply either/or and the only way to access a process is to search as you have written. Search Active, search Archived.

You could create a data record in an external database to mimic the single record requirement you are asking for but then you would have to save all pertinent data and then update it via connectors at process start and process end....

so the answers to your statements/questions are unfortunately:

1) no way round it, 2) change the trace settings in Log Config, and 3) yep...no way round it.

I think you could ask for a feature request. A central recording of process states and a clean up of the API's such that ProcessInstance validly works for both archived and live processes.

regards Seán

Comments

Submitted by mmichalak on Tue, 12/09/2014 - 18:51

Thank you for your answer.

Notifications