How to use more files in Rest API extension?

1
0
-1

Hello,

I made a Rest API extension based on this documentation (the last part: Returning the whole object with an API link load in the lazy fields)

https://documentation.bonitasoft.com/bonita/7.11/bdm-in-rest-api

My properties file looks like this:

RateBDMQuery.pathTemplate=RateBDMQuery
displayName=Rate Query
name=custompage_RateBDMQuery
description=Lekéréseket végez
RateBDMQuery.method=GET
RateBDMQuery.permissions=task_visualization
RateBDMQuery.classFileName=RateBDMQuery.groovy
contentType=apiExtension
apiExtensions=RateBDMQuery

If i use the same exact order: SERIALIZER, MAPPER, INDEX

Then my Rest API doesnt work (although i renamed my class it isnt INDEX). The portal loads the first class it sees and if it isnt the Rest API controller, then it doesnt work. If i switch the order and put the controller class at the start, it works.

I also tried to pack the 3 classes in 3 files, but the extension cant find the other classes, can i define them as dependencies in this properties files?

I want to make more reusable classes, and use them in a Rest API extension, but until now i didnt found a way to do that, i needed to put the class in the same file as the index. So if i want to use it in a another extension i need to copy the code, and if i need to change it i need to change it in multiple places. This is not so convinient, thats the reason why im asking, if there is a way to include other class files in the extension?

1 answer

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

Hi,

Here is an example of the REST API extension project using multiple endpoints.

In term of reusability, the project above is a common maven project so you can create all the classes and use all the maven dependencies you need (as long as they are not conflicting with the runtime).

I hope it will help you solving your issue.

Romain

Comments

Submitted by kurucsai.zoltan... on Tue, 03/16/2021 - 15:51

Hi,

Thank you, i will try using the extension, does this work with 7.11.4 version of Bonita? I remember a youtube video explaining how to use maven etc with 2021.1 version of Bonita, but is is possible to use this example for the older 7.11.4 version?

Another question if i want to create a RestAPI extension similar to the Bonita BDM API

./API/bdm/businessData/{{businessDataType}}?q={{queryName}}&p=0&c=10&f={{filter}}

Is there a good example how to extract the f parameter? I know i can user request.getParameters("f"), and then i get an array containing the name/value pairs with = between them, and that i can split and evaluate. But i bet there is a more beautiful way of doing this :)

Regards

Zoltan

Submitted by romain.bioteau on Tue, 03/16/2021 - 16:56

The example I've provide is compliant with 7.11.4 ;) (note that it is also compatible with 2021.1, it is just that in 2021.1 the archetype use a maven assembly that is not backward compatible)

I'd recommend to develop more specific API for you BDM instead of trying to reimplement ours. Ours where design this way in order to be generic. You could however for your project directly design API like this for your apps:

../API/extension/bdm/MyBusinessObject?id={{persistenceId}} or ../API/extension/bdm/MyBusinessObject/find?p=0&c=10 or ../API/extension/bdm/MyBusinessObject/customQuery?p=0&c=10&customParam=a... and so on

HTH
Romain

Submitted by kurucsai.zoltan... on Wed, 03/17/2021 - 08:04

Hi,

Thank you for the advice :)

I have 1 problem with the example, im using spring tool suit (it is basicly ecplise), and have this error in the projects pom.xml:

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (execution: default-compile, phase: compile) pom.xml /multi-endpoint-api-example-main line 122 Maven Project Build Lifecycle Mapping Problem

I still searching for a solution, im just curious, maybe you know the answer to this, someone mentioned to put
tag before plugins (and of course the close tag after plugins). But this didnt work.

Submitted by romain.bioteau on Wed, 03/17/2021 - 09:53

You need to install the eclipse m2e connectors. Eclipse prompt a wizard to install them when you import the project as a maven project in your worksapce.

You will also need to install groovy-eclipse from the eclipse marketplace. Becarefull as groovy eclipse just released a new version that dropped the support for groovy 2.4.x (which is the version currently used in bonita). So you should installed the previous version (3.9.x) using their update site.

HTH
Romain

Notifications