create an Api accessible from scripts

1
0
-1

The groovy scripting mode in Bonitasoft is a nice feature but has some limitations, including the inability to debug. This is annoying, especially considering the very high quality debugging features of the Java platform.

I tried to develop connectors in Bonitasoft, which is a bit more productive as I have a correct syntax validation and compile but still miss a debugging mode.

Someone told me there is a possibility to develop your own api in bonitasoft, but I can't find how. Has someone some experience with that kind of problematic ?

Regards

Comments

Submitted by yannick.lombardi on Thu, 04/23/2015 - 10:49

When you develop a connector for Bonita BPM, first do it in your IDE (Eclipse, Intellij, NetBean, ...). Like this you can debbug your code. And when all work, you just need to copy/paste in bonita.

Also you can debbug your groovy script by adding this line in your code :

import java.util.logging.Logger;
Logger logger= Logger.getLogger("org.bonitasoft");
logger.severe("This text will appear in bonita logs");

For example you can add a StackTrace in your log.

Submitted by Sean McP on Thu, 04/23/2015 - 12:14

Not strictly correct,

In Eclipse etc., you can write your code, format it and code correct it (Intellisense) etc. but you cannot debug it.

Debugging is when executing the real logic of the program with completed variables etc.

You can add dummy data to the code, but in real life it's very different, for loops, bad return codes from databases...etc.

these are execution debugging requirements which are not available in Bonita, and should be (in my opinion).

If Bonita based the editor on Eclipse JAVA EE with integrated Tomcat rather than the standard Tomcat Eclipse editor, this would allow us to do execution debugging inside the Eclipse environment (I think), so powerful.

Examples of this can be found at, yes theya re talking about Servlets etc but surely there must be a way round this?

http://www.wikijava.org/wiki/Debugging_a_servlet_with_tomcat_and_Eclipse_tutorial http://www.avajava.com/tutorials/lessons/how-do-i-debug-my-web-project-in-tomcat-from-eclipse.html?page=1

I wonder if it is possible to Upgrade the Embedded Eclipse to Eclipse EE and do this? Anyone for a challenge?

3 answers

1
+3
-1
This one is the BEST answer!

Hi David

here is how we solved it in our company:

We're writing our code outside bonita studio in our favourite IDE (i.e. IntellijIdea) as a standard maven project that builds into jar archive. Then we're importing that jar into studio using Development>Manage jars>Import and we're setting that jar as a Process Dependency for our process (Configure > Process Dependencies > Others > Add). The second step is done only once. But the first (the import) we need to do every time the jar changes.

After dependeny is set we can create variables with data type Java Object and Class chosen from the jar (but remember: the class must be Serializable) and we can run our code from every groovy script. Something like:

import com.mycompany.MyGreatProcessAPI
import com.mycompany.APIAccessor

MyGreatProcessAPI api = APIAccessor.getMyGreatProcessAPI()
api.doStuff(variable)

(where variable is an instance of one of ours classes).

By moving our code out of Bonita Studio we can not only benefit from syntax validation or unit testing but also debug it! Pay attention, here comes the magic :)

Go to your Bonita installation folder and find BonitaBPMCommunity.ini file. Open it, paste the following line at the end and save:

-Dtomcat.extra.params=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

Then just set the correct settings in your ide debuging configuration (i.e. host localhost and port 8000) and connect with debugger after running the proces from studio. Don't forget to set dependencies for bonita source code, so you will be able to move around their code (very useful for tracking bugs!)

Hope this helps :)

Comments

Submitted by Sean McP on Thu, 04/23/2015 - 12:31

Nice!! It would be good if I understood any of it...

But way to go!

Submitted by Sean McP on Thu, 04/23/2015 - 17:12

I'm not the best Java programmer, Classes etc. to a point still confound me, with all the methods that you can build into them and the like.

I'm old school, learnt Jackson Structured programming, started off with Assembler, PL/S (IBM Mainframe version not the PC version) etc.

Just one of those things...and I'm still getting my head around objects etc...

That's what I mean by not fully understanding... :)

regards

1
+1
-1

I agree about debugging...

However: this is a common issue with all services that have two environments for development and execution. The studio is one environment and the Tomcat is another, and they simply don't meet like in JAVA EE, which is great for debugging code etc...Why doesn't Bonita use Eclipse JAVA EE with embedded Tomcat which can be debugged from within the environment? I wonder if this is a licensing issue? I love walking through code and debugging via logs is SO OLD SCHOOL...takes me back.

The Editor I must admit seems crippled when compared to normal Eclipse and wish Bonita would fix some of the issues (which I'm sure is because of their implementation of it).

For example: full and complete intellisense for groovy, java and javascript. Proper Code Colouring, Code Folding, Code Formatting, a mode for showing HTML possibly, etc. FIND and REPLACE for goodness sake in the expression editor!

Enough ranting, my thoughts anyway...

Below is my version of Yannicks' submission for logging,

import org.bonitasoft.engine.api.ProcessRuntimeAPI;
import java.util.logging.Logger;

int dI = 0;
boolean debug = true;

ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
String processName = processRuntimeAPI.getProcessInstance(processInstanceId).getName();

//set the name of the routine
String thisTrace = " "+processName+ " mySpecificName: "

Logger logger= Logger.getLogger("org.bonitasoft");
if(debug){dI++; logger.severe(dI+thisTrace+"Trace Start");}

//I always use ArrayList to return as I find I generally return more than one result
//this way in the last step of defining the connector I just have
// variable x Takes Value Of result[0]
// variable y Takes Value Of result[1]
//etc.

ArrayList<Object> returnList = new ArrayList<Object>();
//TODO - START OF Code goes in here

returnList.add(my first result);
returnList.add(my second result);
returnList.add(etc.);
//TODO - END OF Code goes in here

if(debug){dI++; logger.severe(dI+thisTrace+"returnList: "+returnList.toString());}
if(debug){dI++; logger.severe(dI+thisTrace+"Trace End");}
return returnList;

As stated in the code:

//I always use ArrayList to return as I find I generally return more than one result //this way in the last step of defining the connector I just have // variable x Takes Value Of result[0] // variable y Takes Value Of result[1] //etc.

for example:

i=0; while databaseRead.next(){ returnList.add(databaseRead.get(0)); i++; } returnList.add(i); // number of records

regards

1
0
-1

Hello aleksander,

many thanks for your answer, I hope other will find it profitable too.

I had something similar in mind, but wanted to be sure it was doable and your solution is much more elegant.

@Sean McP, what don't you understand ?

Notifications