Problem com BDM with complex data

Description

I think there are problems in version 7.8.x community with BDM with complex data,
I imported the ExpenseReport 3.0 sample and it worked correctly,
when I try to replicate it doing zero, it gives error in the operation to write the information complex data (lines)

old function OK
import org.bonitasoft.engine.bpm.process.ProcessInstance;
import com.company.model.ExpenseReport;
import com.company.model.ExpenseReportLine;

ProcessInstance processInstance = apiAccessor.getProcessAPI (). GetProcessInstance (processInstanceId);

ExpenseReport newReport = new ExpenseReport ();
newReport.setIsApproved (false);
newReport.setSummary (reportContract.get ("summary"));
newReport.setCreationDate (new Date ());
newReport.setCreatedBy (processInstance.getStartedBy ());

List <Map <String, Object >> contractLines = reportContract.get ("lines");
List <ExpenseReportLine> lines = new ArrayList <ExpenseReportLine> ();
for (Map <String, Object> contractLine: contractLines)
{
ExpenseReportLine line = new ExpenseReportLine ();
line.setLabel (contractLine.get ("label"));
line.setCost (contractLine.get ("cost"));
lines.add (line);
}
newReport.setLines (lines);

return newReport;

new function with ERROR

expenseReportVar.summary = reportInput.summary
expenseReportVar.lines = {
def expenseReportLineList = []
// For each item collected in multiple input
reportInput.lines.each {
// Add aggregated ExpenseReportLine instance
expenseReportLineList.add ({currentExpenseReportLineInput ->
def expenseReportLineVar = expenseReportLineDAO.findByPersistenceId (currentExpenseReportLineInput.persistenceId.toLong ())
expenseReportLineVar.label = currentExpenseReportLineInput.label
expenseReportLineVar.cost = currentExpenseReportLineInput.cost
return expenseReportLineVar
} (it)
}
return expenseReportLineList} ()

Environment

windows 10

External Link

None

Workaround

None

Activity

Show:
Antoine Mottier
March 12, 2019, 10:02 AM

I think that the issue you report is actually related with your code.

To start the process you asked (in the contract) the user to provide an expense report summary and a set of lines for the details of the expense report. For each line you asked for the label and cost (that is expected) but you also asked for the persistence id (you probably should not).

Persistence id is generate by Bonita BDM service when storing a new entry in the database. In your use case you are creating a new expense report with a set of new lines. So you should only provide label and cost for each line. When you set your business variable default value BDM service will save it in the database and generate for you the persistence id. Currently in your business variable default value you are searching for existing expense report line based on the persistence id provided by the user: expenseReportLineDAO.findByPersistenceId(currentExpenseReportLineInput.persistenceId.toLong()) As you don't have any existing data this will fail. It will return a null value and then try to update it with the label and cost and lead to the NullPointerException you can see in Bonita Engine log file (available from Bonita Studio help menu).

Paulo Azevedo
March 15, 2019, 12:07 AM

thanks for the feedback. My question is that this code is not mine, it was generated automatically by the beautiful studio. When I do the same process in other versions the automatic generated code works correctly, in 7.8.xx it does not work and I have to change it manually. My question, is why the bonita is generating this wrong code, because this is a very simple process ...
thanks

Paulo Azevedo
March 15, 2019, 12:08 AM

sory "beautiful studio" = bonita studio

Paulo Azevedo
March 15, 2019, 12:24 AM

I solved this problem with change bdm.lines Relationship to Composition and Always load related objects

Antoine Mottier
March 18, 2019, 10:35 AM

I can confirm that the issue was related to the usage of an aggregation. Aggregation would mean that ExpenseReportLine have a life cycle independent of ExpenseReport. That is actually not the attended design. If you delete an expense report there is no situation where associated lines should not be deleted.
With an aggregation, the default value generated script expect the ExpenseReportLine to already exists. The script will failed because they don't exist.

Using the appropriate relationship between the two objects fix the issue as you find out. I think no update is required in the product. Please add a comment if you have some suggestion to improve this behavior.

Thanks a lot for taking the time to report this issue and share your solution. I'll update the example with the latest version of Bonita and include some comments based on your feedback.

Assignee

Antoine Mottier

Reporter

Paulo Azevedo

Affects versions

Reference

None

Fix versions

Configure