Skip to content

Commit 68b61e6

Browse files
authored
Merge pull request #3 from boldbi/497868-object-model
Feature(497868): Update sample with embedconfig and embedToken approach
2 parents 7690810 + ab80edf commit 68b61e6

22 files changed

Lines changed: 284 additions & 152 deletions

.classpath

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15">
5-
<attributes>
6-
<attribute name="module" value="true"/>
7-
<attribute name="owner.project.facets" value="java"/>
8-
</attributes>
9-
</classpathentry>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-25"/>
105
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
116
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
127
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">

.project

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,15 @@
2828
<nature>org.eclipse.jdt.core.javanature</nature>
2929
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
3030
</natures>
31+
<filteredResources>
32+
<filter>
33+
<id>1770289273454</id>
34+
<name></name>
35+
<type>30</type>
36+
<matcher>
37+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
38+
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
39+
</matcher>
40+
</filter>
41+
</filteredResources>
3142
</projectDescription>
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=15
4-
org.eclipse.jdt.core.compiler.compliance=15
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=25
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=25
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
510
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
611
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
712
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
813
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
914
org.eclipse.jdt.core.compiler.release=enabled
10-
org.eclipse.jdt.core.compiler.source=15
15+
org.eclipse.jdt.core.compiler.source=25

.settings/org.eclipse.wst.common.project.facet.core.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<fixed facet="java"/>
55
<fixed facet="jst.web"/>
66
<fixed facet="wst.jsdt.web"/>
7-
<installed facet="java" version="14"/>
8-
<installed facet="jst.web" version="3.0"/>
97
<installed facet="wst.jsdt.web" version="1.0"/>
8+
<installed facet="jst.web" version="4.0"/>
9+
<installed facet="java" version="25"/>
1010
</faceted-project>

README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,41 @@
22

33
This Bold BI Java Servlet sample repository contains the Dashboard embedding sample. This sample demonstrates how to embed the dashboard which is available in your Bold BI server.
44

5-
This section guides you in using the Bold BI dashboard in your Java Servlet sample application.
5+
## Dashboard view
66

7-
* [Requirements to run the demo](#requirements-to-run-the-demo)
8-
* [Using the Java Servet sample](#using-the-java-servlet-sample)
9-
* [Online Demos](#online-demos)
10-
* [Documentation](#documentation)
7+
![Dashboard View](/images/dashboard.png)
118

12-
## Requirements to run the demo
9+
## Requirements
1310

1411
The samples require the following requirements to run.
1512

1613
* [Eclipse IDE](https://www.eclipse.org/downloads/)
14+
* Apache Tomcat
1715

18-
## Using the Java Servlet sample
16+
### Supported browsers
17+
18+
* Google Chrome, Microsoft Edge, and Mozilla Firefox.
1919

20-
* Open the file `index.jsp` of the sample in Eclipse.
20+
## Configuration
2121

22-
* Please change the following properties in the `index.jsp` file as per your Bold BI Server.
22+
* Please ensure you have enabled embed authentication on the `embed settings` page. If it is not currently enabled, please refer to the following image or detailed [instructions](https://help.boldbi.com/site-administration/embed-settings/#get-embed-secret-code?utm_source=github&utm_medium=backlinks) to enable it.
2323

24-
| **Parameter** | **Description** |
25-
|------------------|-----------------|
26-
| **RootUrl** | Dashboard Server URL (Eg: `http://localhost:5000/bi`, `http://demo.boldbi.com/bi`). |
27-
| **SiteIdentifier** | For the Bold BI Enterprise edition, it should be like `site/site1`. For Bold BI Cloud, it should be an empty string. |
28-
| **Environment** | Your Bold BI application environment. (If Cloud, you should use `cloud`, if Enterprise, you should use `onpremise`). |
29-
| **DashboardId** | Set the item id of the dashboard to embed from BI server. |
30-
| **EmbedSecret** | Get your EmbedSecret key from the Embed tab by enabling the `Enable embed authentication` on the Administration page [link](https://help.boldbi.com/embedded-bi/site-administration/embed-settings/?utm_source=github&utm_medium=backlinks). |
31-
| **UserEmail** | UserEmail of the Admin in your Bold BI, which would be used to get the dashboard list. |
24+
![Embed Settings](/images/enable-embedsecretkey.png)
25+
26+
* To download the `embedConfig.json` file, please follow this [link](https://help.boldbi.com/site-administration/embed-settings/#get-embed-configuration-file?utm_source=github&utm_medium=backlinks) for reference. Additionally, you can refer to the following image for visual guidance.
27+
28+
![Embed Settings Download](/images/download-embedsecretkey.png)
29+
![EmbedConfig Properties](/images/embedconfig-file.png)
30+
31+
* Copy the downloaded `embedConfig.json` file and paste it into the designated [location](https://github.com/boldbi/java-servlet-sample/tree/master/WebContent) within the application. Please ensure you have placed it in the application, as shown in the following image.
32+
33+
![EmbedConfig image](/images/embedconfig-location.png)
34+
35+
## Run a Java Servlet sample in Eclipse
36+
37+
* Import the sample [folder](https://github.com/boldbi/java-servlet-sample/tree/master) in Eclipse.
38+
39+
* Run the project by Right‑clicking it then `Run As → Run on Server`.
3240

3341
Please refer to the [help documentation](https://help.boldbi.com/embedded-bi/javascript-based/samples/v3.3.40-or-later/other-platform-samples/#java-servlet-sample-to-embed-dashboard?utm_source=github&utm_medium=backlinks) to know how to run the sample.
3442

WebContent/WEB-INF/web.xml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@
44
<welcome-file-list>
55
<welcome-file>index.jsp</welcome-file>
66
</welcome-file-list>
7+
8+
<servlet>
9+
<servlet-name>BoldBI</servlet-name>
10+
<servlet-class>com.javapapers.sample.ajax.BoldBI</servlet-class>
11+
<load-on-startup>2</load-on-startup>
12+
</servlet>
13+
14+
<servlet-mapping>
15+
<servlet-name>BoldBI</servlet-name>
16+
<url-pattern>/BoldBI.do</url-pattern>
17+
</servlet-mapping>
18+
19+
<listener>
20+
<listener-class>com.javapapers.sample.ajax.ConfigLoader</listener-class>
21+
</listener>
22+
723
<servlet>
8-
<servlet-name>BoldBI</servlet-name>
9-
<servlet-class>com.javapapers.sample.ajax.BoldBI</servlet-class>
10-
<load-on-startup>1</load-on-startup>
24+
<servlet-name>EmbedConfig</servlet-name>
25+
<servlet-class>com.javapapers.sample.ajax.EmbedConfigServlet</servlet-class>
1126
</servlet>
1227
<servlet-mapping>
13-
<servlet-name>BoldBI</servlet-name>
14-
<url-pattern>/BoldBI.do</url-pattern>
28+
<servlet-name>EmbedConfig</servlet-name>
29+
<url-pattern>/embedConfig.json</url-pattern>
1530
</servlet-mapping>
1631
</web-app>

WebContent/index.jsp

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,54 @@
11
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
2-
pageEncoding="ISO-8859-1"%>
2+
pageEncoding="ISO-8859-1"%>
33
<!DOCTYPE html>
44
<html>
55
<head>
6-
<meta charset="ISO-8859-1">
7-
<title>BoldBI Embed - JAVA Servlet</title>
8-
<script type="text/javascript" src="ajax.js"></script>
9-
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
10-
<script type="text/javascript" src="https://cdn.boldbi.com/embedded-sdk/v6.1.8/boldbi-embed.js"></script>
6+
<meta charset="ISO-8859-1">
7+
<title>BoldBI Embed - JAVA Servlet</title>
8+
<script type="text/javascript" src="ajax.js"></script>
9+
<script type="text/javascript"
10+
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
11+
<script type="text/javascript"
12+
src="https://cdn.boldbi.com/embedded-sdk/latest/boldbi-embed.js"></script>
1113
</head>
12-
<body>
13-
14-
<div style="height:100%;width:100%;overflow: hidden !important;" id="sample_dashboard"></div>
15-
<script>
16-
//Rooturl of the BoldBI. This can be domain name/IP/Localhost along with the '/bi' at the end as below
17-
var rootUrl = "http://localhost:64503/bi";
18-
//This is by defaul 'site/site1'. If you have created the new tenant in your onpremise version, it might be vary based on your entries
19-
var siteIdentifier = "/site/site1";
20-
//Your Bold BI application environment. (If Cloud, you should use `cloud`, if Enterprise, you should use `enterprise`)
21-
var environment = "enterprise";
22-
//Unique Id of the Dashboard
23-
var dashboardId = "606badda-ffbe-41b8-90c4-b1e4ba367aa3";
24-
//Authorization endpoint which has encrypt the user context and send back to the Bold BI Server for authorization.
25-
var authorizationUrl = "BoldBI.do"
26-
$(document).ready(function() {
27-
var boldbiEmbedInstance = BoldBI.create({
28-
serverUrl: rootUrl + siteIdentifier,
29-
dashboardId: dashboardId,
30-
embedContainerId: "sample_dashboard",
31-
embedType: BoldBI.EmbedType.Component,
32-
environment: environment == "enterprise" ? BoldBI.Environment.Enterprise : BoldBI.Environment.Cloud,
33-
width:"100%",
34-
height: window.innerHeight + 'px',
35-
expirationTime:100000,
36-
authorizationServer: {
37-
url: authorizationUrl
38-
}
39-
});
40-
boldbiEmbedInstance.loadDashboard();
41-
});
42-
</script>
14+
<body onload="embedSample()">
15+
<div id="dashboard"></div>
16+
<script>
17+
function embedSample() {
18+
// load configuration from webroot
19+
fetch('embedConfig.json')
20+
.then(r => r.json())
21+
.then(cfg => {
22+
getEmbedToken().then(accessToken => {
23+
var serverUrl = cfg.ServerUrl;
24+
if (cfg.SiteIdentifier) {
25+
serverUrl = serverUrl.replace(/\/$/, '') + '/' + cfg.SiteIdentifier.replace(/^\//, '');
26+
}
27+
var boldbiEmbedInstance = BoldBI.create({
28+
serverUrl: serverUrl,
29+
dashboardId: cfg.DashboardId,
30+
embedContainerId: "dashboard",
31+
embedToken: accessToken,
32+
});
33+
boldbiEmbedInstance.loadDashboard();
34+
}).catch(error => {
35+
console.error("Failed to get embed token:", error);
36+
});
37+
})
38+
.catch(err => console.error('Failed to load embedConfig.json', err));
39+
}
40+
41+
function getEmbedToken() {
42+
return fetch('BoldBI.do', {
43+
method: 'POST',
44+
headers: {
45+
'Content-Type': 'application/json'
46+
},
47+
body: JSON.stringify({})
48+
})
49+
.then(response => response.text())
50+
.then(data => data);
51+
}
52+
</script>
4353
</body>
4454
</html>
995 Bytes
Binary file not shown.
-345 Bytes
Binary file not shown.
2.73 KB
Binary file not shown.

0 commit comments

Comments
 (0)