Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Sv translation
languageen

You can create your own API Endpoints using BellaDati Extensions feature. This tutorial describes how to create an endpoint which exports public Report to PDF.

You can download complete Extension with an endpoint here and import it to BellaDati Extensions. Refer to Importing Extensions section in Extensions documentation.

Preconditions

  • You have BellaDati instance in version 2.8.6.1+.
  • You have role Super Admin in multi-domain environment or Domain Admin in single-domain environment.
  • You are familiar with Java/Groovy.
  • You have a public Report. Refer to Public Report section in Sharing Report documentation.

Tutorial

Step 1. Create an Extension

  1. Go to Manage extensions page that is available in the Extensions section, under Administration menu.
  2. Click on Create extension 
  3. Create an Extension with type Create new page
    Image Modified

Step 2. Create an API Endpoint in Extension

After creating the Extension you should be redirected to Extension detail.

  1. In the panel on the left click on API Endpoints
  2. Click on Add button
  3. Name the endpoint and click on Add
    Image Modified

Step 3. Write code which will export Report to PDF and send it to client

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:

Code Block
languagejava
package com.example;

import com.belladati.extension.BaseExtensionEndpoint;
import org.apache.tapestry5.StreamResponse;

public class MyEndpoint extends BaseExtensionEndpoint {
  
	@Override
	public StreamResponse doGet() {
      	
      try {
        // get parameter value from URL
      	def reportIdParameter = getParameter("reportId");
        int reportId = reportIdParameter.toInteger();
        // export Report to PDF
        File pdfFile = exportToPdf(reportId);
        InputStream is = new FileInputStream(pdfFile);
        
        /**
         * @param is data which are sent to client
         * @param mimeType MIME type of data
         * @param responseStatusCode response status
         */
        // createStreamResponse( InputStream is, String mimeType, int responseStatusCode)
        
       	// send Report exported as PDF to client  
        return createStreamResponse(is, "application/pdf", 200);
      } catch (Exception e) {
            return createStreamResponse(e);
      } 
	}
	@Override
	public StreamResponse doPost() {
		// TODO Auto-generated method stub. Please insert here your code for POST operation.
		return null;
	}
}

Step 4. Endpoint usage

Extension has to be activated before the endpoint can be used. We also have to activate Public access so public users will be able to use the endpoint.

Image Modified

Endpoint is now ready to use so we can try it. 

Clicking on Link above the code editor will open URL with our endpoint. We just have to append parameter "reportId" with ID of Report which should be exported (refer to implementation above).

Your URL should look like this:

Code Block
languagejs
https://service.belladati.com/extension/detail:endpoint/104/exportReportToPDF?reportId=12345

Example usage in HTML:

Code Block
languagexml
<!--Use relative URL in BellaDati Extension-->
<!--Clicking on the button will open the PDF in browser built-in PDF reader if supported-->
<a href="/extension/detail:endpoint/104/exportReportToPDF?reportId=12345">
	<div class="my-button">
	Export to PDF
	</div>
</a>
 
<!--Using download attribute-->
<!--Clicking on the button will save the file without opening it-->
<a 
	href="/extension/detail:endpoint/104/exportReportToPDF?reportId=12345"
	download
>
	<div class="my-button">
	Export to PDF
	</div>
</a>
Sv translation
languageja

Extensionsを使用して、独自のAPIエンドポイントを作成できます。このチュートリアルでは、パブリックレポートをPDFにエクスポートするエンドポイントを作成する方法について説明します。

ここからエンドポイントを含む完全な拡張機能をダウンロードして、BellaDati拡張機能にインポートできます。拡張機能の「拡張機能のインポート」セクションを参照してください。

前提条件

  • バージョン2.8.6.1以降のBellaDatiにインスタンスがあります。
  • マルチドメイン環境ではSuper Admin、シングルドメイン環境ではドメイン管理者の役割があります。
  • Java / Groovyに精通していること。
  • You have a public Report. Refer to Public Report section in Sharing Report documentation.
  • パブリックレポートであること。http://support.belladati.com/doc/Sharing+Reportのパブリックレポートのセクションを参照してください。

チュートリアル

Step 1. Create an Extension

  1. Go to Manage extensions page that is available in the Extensions section, under Administration menu.
  2. Click on Create extension 
  3. Create an Extension with type Create new page
    Image Added

Step 2. Create an API Endpoint in Extension

After creating the Extension you should be redirected to Extension detail.

  1. In the panel on the left click on API Endpoints
  2. Click on Add button
  3. Name the endpoint and click on Add
    Image Added

Step 3. Write code which will export Report to PDF and send it to client

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:

Code Block
languagejava
package com.example;

import com.belladati.extension.BaseExtensionEndpoint;
import org.apache.tapestry5.StreamResponse;

public class MyEndpoint extends BaseExtensionEndpoint {
  
	@Override
	public StreamResponse doGet() {
      	
      try {
        // get parameter value from URL
      	def reportIdParameter = getParameter("reportId");
        int reportId = reportIdParameter.toInteger();
        // export Report to PDF
        File pdfFile = exportToPdf(reportId);
        InputStream is = new FileInputStream(pdfFile);
        
        /**
         * @param is data which are sent to client
         * @param mimeType MIME type of data
         * @param responseStatusCode response status
         */
        // createStreamResponse( InputStream is, String mimeType, int responseStatusCode)
        
       	// send Report exported as PDF to client  
        return createStreamResponse(is, "application/pdf", 200);
      } catch (Exception e) {
            return createStreamResponse(e);
      } 
	}
	@Override
	public StreamResponse doPost() {
		// TODO Auto-generated method stub. Please insert here your code for POST operation.
		return null;
	}
}

Step 4. エンドポイントの使用

Extension has to be activated before the endpoint can be used. We also have to activate Public access so public users will be able to use the endpoint.

Image Added

Endpoint is now ready to use so we can try it. 

Clicking on Link above the code editor will open URL with our endpoint. We just have to append parameter "reportId" with ID of Report which should be exported (refer to implementation above).

Your URL should look like this:

Code Block
languagejs
https://service.belladati.com/extension/detail:endpoint/104/exportReportToPDF?reportId=12345

Example usage in HTML:

Code Block
languagexml
<!--Use relative URL in BellaDati Extension-->
<!--Clicking on the button will open the PDF in browser built-in PDF reader if supported-->
<a href="/extension/detail:endpoint/104/exportReportToPDF?reportId=12345">
	<div class="my-button">
	Export to PDF
	</div>
</a>
 
<!--Using download attribute-->
<!--Clicking on the button will save the file without opening it-->
<a 
	href="/extension/detail:endpoint/104/exportReportToPDF?reportId=12345"
	download
>
	<div class="my-button">
	Export to PDF
	</div>
</a>