MySQL connector data to BDM variable

1
0
-1

I am struggling with getting data from a MySQL connector into a BDM variable in Bonita 7.4.3

When i create the connector if i use the Graphical mode and run "test" I can see the data i want.
But it only writes the first record tot he BDM.

When I choose script and try to write some code (totally not a coder btw) It seems to change the data and i cant get anything into the bdm.

I would like a simple example on how to get data, transform it and get it into the BDM.

Thanks!

4 answers

1
+1
-1

What you need to do - incomplete and not tested code is as follows in the script:

while(rs.next()){
     myBDM newBDM = new myBDM;
     newBDM.setfField(1) = rs.field(0);
     newBDM.setfField(2) = rs.field(1);
     etc.
}

That should do it...

regards
Seán

PS: As this reply offers an answer your question, and if you like it, please Mark UP and/or as Resolved.

1
0
-1

Hello,
I'm trying to follow your example. It's interesting because that's I want to do. But I wonder understand where is traited the code of your script? In connector definition or in business variable? I use Bonita v.5.1 and my connector is MS-SQL and essentially it's the same object I'm looking for.

1
0
-1

ah I see.
So heres the connector
8Rw3pOPhv.jpg

And heres the Pool Variable def
https://pasteboard.co/8RxdtChpN.png

Comments

Submitted by Sean McP on Sun, 05/21/2017 - 09:54

First things first, can you make to to add a new comment and not a new Answer - gets confusing...

As I can't see the whole process it makes it a little difficult but when doing a Postgresql to BDM migration, there is no need to define a Pool Data variable for the BDM.

You do that in code only...

The init_code is also wrong as there are no operations to set the data so it doesn't look right.

From what I can tell - please correct me if wrong - the only thing you're doing is:

Read database
load into BDM - no forms or anything else for now.

This is a one off exercise and would never be executed again...

regards

Submitted by jason.hastain on Sun, 05/21/2017 - 09:56

Sean,
Yes you are correct. Reading data from a db to a BDM variable.

Submitted by Sean McP on Sun, 05/21/2017 - 10:08

OK so all you need is the right version of my code as previously shown.

Delete all process variables that reference the BDM - not needed.

In your script reading the Postgresql results:

while(rs.next()){
     def newBDM = new com.company.model.myBDM()
     newBDM.setfField() = rs.field(0);
     newBDM.setfField() = rs.field(1);
     etc.
}

In the last page of the database widget thingie, delete the output operation it's not needed...

regards

Submitted by jason.hastain on Sun, 05/21/2017 - 10:32

Sean
thanks I rewrote that code:
`List<List

> resultTable = new ArrayList<List>();

while(resultset.next()) { def newGLPI = com.company.model.GLPItest

newGLPI.name = resultset.field(0)
newGLPI.serial = resultset.field(1)

} return resultTable`

and removed the return reference and it did write to the BDM and no errors in the log.

Thanks for the help! I appreciate that you took the time to help a n00b ;) thanks again jason

Submitted by jason.hastain on Sun, 05/21/2017 - 10:32

Sean
thanks I rewrote that code:
`List<List

> resultTable = new ArrayList<List>();

while(resultset.next()) { def newGLPI = com.company.model.GLPItest

newGLPI.name = resultset.field(0)
newGLPI.serial = resultset.field(1)

} return resultTable`

and removed the return reference and it did write to the BDM and no errors in the log.

Thanks for the help! I appreciate that you took the time to help a n00b ;) thanks again jason

1
0
-1

Sean thanks for that answer.

So at one point I had it working. Then inexplicably it stopped working again without any code changes :(

here is the code im using:

List<List

> resultTable = new ArrayList<List>(); int maxColumn = resultset.getMetaData().getColumnCount()+1;

while(resultset.next()) { final List row = new ArrayList(); for(int colIndex =1; colIndex < maxColumn ; colIndex++){ row.add(resultset.getObject(colIndex)); } resultTable.add(row);

} return resultTable

Whats weird is is gets the data into the H2 Database. But im getting this error in the logs:

2017-05-21 02:03:53.081 -0400 SEVERE: org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork THREAD_ID=111 | HOSTNAME=NJEXT023 | TENANT_ID=1 | The work [ExecuteConnectorOfActivity: flowNodeInstanceId = 20036, connectorDefinitionName = svrGLPIlookup] failed. The failure will be handled. 2017-05-21 02:03:53.081 -0400 SEVERE: org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork THREAD_ID=111 | HOSTNAME=NJEXT023 | TENANT_ID=1 | java.lang.ClassCastException : "java.util.ArrayList cannot be cast to org.bonitasoft.engine.bdm.Entity" java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.bonitasoft.engine.bdm.Entity at org.bonitasoft.engine.operation.MergeEntityAction.execute(MergeEntityAction.java:50) at org.bonitasoft.engine.operation.EntitiesActionsExecutor.executeAction(EntitiesActionsExecutor.java:45) at org.bonitasoft.engine.operation.BusinessDataAssignmentStrategy.computeNewValueForLeftOperand(BusinessDataAssignmentStrategy.java:45) at org.bonitasoft.engine.core.operation.impl.OperationServiceImpl.calculateRightOperandValue(OperationServiceImpl.java:122) at org.bonitasoft.engine.core.operation.impl.OperationServiceImpl.executeOperators(OperationServiceImpl.java:105) at org.bonitasoft.engine.core.operation.impl.OperationServiceImpl.execute(OperationServiceImpl.java:94) at org.bonitasoft.engine.core.connector.impl.ConnectorServiceImpl.executeOutputOperation(ConnectorServiceImpl.java:178) at org.bonitasoft.engine.connector.ConnectorServiceDecorator.executeOutputOperation(ConnectorServiceDecorator.java:108) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.evaluateOutput(ExecuteConnectorWork.java:115) at org.bonitasoft.engine.execution.work.ExecuteConnectorOfActivity.evaluateOutput(ExecuteConnectorOfActivity.java:73) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateConnectorOutputsTxContent.call(ExecuteConnectorWork.java:310) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateConnectorOutputsTxContent.call(ExecuteConnectorWork.java:293) at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:274) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.work(ExecuteConnectorWork.java:143) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork.work(FailureHandlingBonitaWork.java:66) at org.bonitasoft.engine.work.BonitaWork.run(BonitaWork.java:56) at org.bonitasoft.engine.work.SequenceRunnableExecutor.innerRun(SequenceRunnableExecutor.java:47) at org.bonitasoft.engine.work.BonitaRunnable.run(BonitaRunnable.java:35) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

any ideas?

Comments

Submitted by Sean McP on Sun, 05/21/2017 - 09:28

A Tip on displaying CODE/LOGS correctly in Posts:

You can use the Supplied Buttons above, <> and '<>', for diplaying code and logs or use:

< code >
your code/log
< /code >

removing the spaces to allow the showing of code/logs correctly as here:

your code/log

You should still be able to edit your post to ensure the correct formatting of the code to help us understand it easier.

Thanks and regards
Seán

Submitted by Sean McP on Sun, 05/21/2017 - 09:29

Your problem is:

"java.util.ArrayList cannot be cast to org.bonitasoft.engine.bdm.Entity" java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.bonitasoft.engine.bdm.Entity

Does Entity have a List defined in it?

Submitted by jason.hastain on Sun, 05/21/2017 - 09:34

Whats interesting is there is no BDM object or Pool variable or really anything referencing "Entity"

So im unclear on what the issue is. Sorry Im new to Bonita and groovy.

Submitted by Sean McP on Sun, 05/21/2017 - 09:40

No, it's not in that code.

It is elsewhere, for example the return resultTable how is that being used? resultTable is an ArrayList.

Notifications