Problème RestAPI pour récupérer données dans BDM

1
0
-1

Bonjour,
J'essaie de développer une RestAPI (Bonita 7.2.2) qui retourne en JSON le contenu d'une table de la BDM mais je bute sur des problème de login/session ou de tenantAP :

  1. import org.apache.http.HttpHeaders
  2. import org.bonitasoft.engine.bdm.BusinessObjectDAOFactory
  3. import org.bonitasoft.engine.session.APISession
  4. import org.bonitasoft.web.extension.ResourceProvider
  5. import org.bonitasoft.web.extension.rest.RestApiResponse
  6. import org.bonitasoft.web.extension.rest.RestApiResponseBuilder
  7. import org.slf4j.Logger
  8. import org.slf4j.LoggerFactory
  9. import com.bonitasoft.engine.api.LoginAPI
  10. import org.bonitasoft.engine.platform.LoginException
  11. import com.bonitasoft.web.extension.rest.RestAPIContext
  12. import com.bonitasoft.web.extension.rest.RestApiController
  13.  
  14. class Index implements RestApiController {
  15.  
  16. @Override
  17. RestApiResponse doHandle(HttpServletRequest request, RestApiResponseBuilder responseBuilder, RestAPIContext context) {
  18. // To retrieve query parameters use the request.getParameter(..) method.
  19. // Be careful, parameter values are always returned as String values
  20. LOGGER.info("###AccesVehicule### " +
  21. "\n Context - ApiSession.id/username: " + context.getApiSession().getId()+ " - " + context.getApiSession().getUserName());
  22. /*
  23. * Execute business logic here
  24. */
  25. DateFormat dateTimeJSON = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
  26. Date dateJour = new Date();
  27. String strDateJour = dateTimeJSON.format(dateJour);
  28.  
  29. //Get the apiSession from the context
  30. final LoginAPI loginAPI = TenantAPIAccessor.getLoginAPI();
  31. final APISession session = context.getApiSession();
  32.  
  33. //APISession apiSession = loginAPI.login(context.getApiSession().getTenantId(), context.getApiSession().getUserName(), "bpm");
  34. if (session != null) {
  35. LOGGER.info("Session: " + session.getId() + " - " + session.getUserName());
  36. } else {
  37. LOGGER.info("Session: apiSession est null !");
  38. }
  39.  
  40. //Create a DAO factory
  41. BusinessObjectDAOFactory daoFactory = new BusinessObjectDAOFactory();
  42.  
  43. //Use the factory to obtain a DAO object
  44. DemandeAccesVehiculesDAO dao = daoFactory.createDAO(session, DemandeAccesVehiculesDAO.class);
  45.  
  46. //Use methods on DAO object to access data from the BDM. You can pass input values pre-calculated to the method
  47. List<AccesVehicule> resultat = new ArrayList<AccesVehicule>();
  48.  
  49. def List<DemandeAccesVehicules> demandeAccesVehiculess = dao.findByDate(strDateJour, p, c);
  50. //...
  51.  
  52. // Send the result as a JSON representation
  53. // You may use buildPagedResponse if your result is multiple
  54. return buildResponse(responseBuilder, HttpServletResponse.SC_OK, new JsonBuilder(resultat).toPrettyString())
  55. }
  56. }

J'obtiens des erreurs du type :

2017-04-21 11:29:35.734 +0200 org.bonitasoft.console.common.server.page.RestApiRenderer org.bonitasoft.console.common.server.page.RestApiRenderer renderResponse 
GRAVE: Error when executing rest api extension call to apiExtension|GET|aw/getListeAccesVehicule
groovy.lang.MissingPropertyException: No such property: TenantAPIAccessor for class: fr.universcience.rest.api.Index

Pas mieux en ajoutant :

  1. final APISession session = loginAPI.login(context.getApiSession().getTenantId(), context.getApiSession().getUserName(), "bpm");`
1 answer

1
0
-1

try using

apiAccessor instead of TenantAPIAccessor

regards
Seán

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

Testing
Notifications