Date: Thu, 28 Mar 2024 09:29:08 +0000 (UTC) Message-ID: <269183570.3914.1711618148029@localhost> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3913_377135124.1711618148029" ------=_Part_3913_377135124.1711618148029 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
You can create your own API Endpoints using BellaDati Extensions feature. This tutoria= l describes how to create an endpoint which exports public Report to PDF.= p>
You can download complete Extension with an endpoint here and import it to BellaD= ati Extensions. Refer to Importing Extensions section= in Extensions documentation.
After creating the Extension you should be redirected to Extension detai= l.
After creating the Endpoint you should be redirected to Endpoint detail = with code editor where you can write/paste your code.
In the Endpoint class are 2 methods, doGet() and doPost(). Each will be = executed based on the endpoint call method (GET/POST).
We will call this endpoint as GET so we will write the code in the doGet= () method. Refer to the code below:
package= com.example; import com.belladati.extension.BaseExtensionEndpoint; import org.apache.tapestry5.StreamResponse; public class MyEndpoint extends BaseExtensionEndpoint { =20 =09@Override =09public StreamResponse doGet() { =09 try { // get parameter value from URL =09def reportIdParameter =3D getParameter("reportId"); int reportId =3D reportIdParameter.toInteger(); // export Report to PDF File pdfFile =3D exportToPdf(reportId); InputStream is =3D new FileInputStream(pdfFile); =20 /** * @param is data which are sent to client * @param mimeType MIME type of data * @param responseStatusCode response status */ // createStreamResponse( InputStream is, String mimeType, int respo= nseStatusCode) =20 =09// send Report exported as PDF to client =20 return createStreamResponse(is, "application/pdf", 200); } catch (Exception e) { return createStreamResponse(e); }=20 =09} =09@Override =09public StreamResponse doPost() { =09=09// TODO Auto-generated method stub. Please insert here your code for = POST operation. =09=09return null; =09} }
Extension has to be activated before the endpoint can be used. We also h= ave to activate Public access so public users will be able to use the endpo= int.
Endpoint is now ready to use so we can try it.
Clicking on Link above the code editor will open U= RL with our endpoint. We just have to append parameter "reportId" with ID o= f Report which should be exported (refer to implementation above).
Your URL should look like this:
https://s= ervice.belladati.com/extension/detail:endpoint/104/exportReportToPDF?report= Id=3D12345
Example usage in HTML:
<!--U= se relative URL in BellaDati Extension--> <!--Clicking on the button will open the PDF in browser built-in PDF rea= der if supported--> <a href=3D"/extension/detail:endpoint/104/exportReportToPDF?reportId=3D1= 2345"> =09<div class=3D"my-button"> =09Export to PDF =09</div> </a> <!--Using download attribute--> <!--Clicking on the button will save the file without opening it--> <a=20 =09href=3D"/extension/detail:endpoint/104/exportReportToPDF?reportId=3D1234= 5" =09download > =09<div class=3D"my-button"> =09Export to PDF =09</div> </a>