Skip to content

Commit

Permalink
feat: ✨add jndi support
Browse files Browse the repository at this point in the history
  • Loading branch information
hks2002 committed Oct 19, 2023
1 parent f6c060f commit 9437a2b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
21 changes: 13 additions & 8 deletions src/main/java/com/da/crystal/report/CRJavaHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author : Robert Huang<[email protected]> *
* @CreatedDate : 2023-03-07 00:03:27 *
* @LastEditors : Robert Huang<[email protected]> *
* @LastEditDate : 2023-10-19 10:46:00 *
* @LastEditDate : 2023-10-19 14:47:59 *
* @FilePath : src/main/java/com/da/crystal/report/CRJavaHelper.java *
* @CopyRight : Dedienne Aerospace China ZhuHai *
*********************************************************************************************************************/
Expand Down Expand Up @@ -103,6 +103,7 @@ public static void changeDataSource(
String password,
String connectionURL,
String driverName,
String JNDI,
String fileName,
String filePath
) {
Expand All @@ -115,17 +116,21 @@ public static void changeDataSource(
// JNDI name for Crystal Report must start with 'jdbc/'
// https://userapps.support.sap.com/sap/support/knowledge/en/1343290

newPropertyBag.put("Server Type", "JDBC (JNDI)");
newPropertyBag.put("Use JDBC", "true");
newPropertyBag.put("Trusted_Connection", "false");
newPropertyBag.put("Connection URL", connectionURL);
newPropertyBag.put("Database Class Name", driverName);
newPropertyBag.put("Database DLL", "crdb_jdbc.dll");
if (!JNDI.isBlank()) {
newPropertyBag.put("Connection Name (Optional)", JNDI);
} else {
newPropertyBag.put("Server Type", "JDBC (JNDI)");
newPropertyBag.put("Use JDBC", "true");
newPropertyBag.put("Trusted_Connection", "false");
newPropertyBag.put("Connection URL", connectionURL);
newPropertyBag.put("Database Class Name", driverName);
newPropertyBag.put("Database DLL", "crdb_jdbc.dll");
}

// If same jdbc info, just do login
IConnectionInfo oldConnectionInfo = clientDoc.getDatabaseController().getConnectionInfos(null).get(0);
PropertyBag oldPropertyBag = oldConnectionInfo.getAttributes();
if (
if (JNDI.isBlank() &&
oldPropertyBag.getStringValue("Server Type").equals("JDBC (JNDI)") &&
oldPropertyBag.getStringValue("Connection URL").equals(connectionURL) &&
oldPropertyBag.getStringValue("Database Class Name").equals(driverName)
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/da/crystal/report/ReportController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author : Robert Huang<[email protected]> *
* @CreatedDate : 2023-03-06 21:22:42 *
* @LastEditors : Robert Huang<[email protected]> *
* @LastEditDate : 2023-10-19 14:16:56 *
* @LastEditDate : 2023-10-19 14:50:30 *
* @FilePath : src/main/java/com/da/crystal/report/ReportController.java *
* @CopyRight : Dedienne Aerospace China ZhuHai *
*********************************************************************************************************************/
Expand Down Expand Up @@ -47,6 +47,9 @@ public class ReportController {
@Value("${rpt.datasource.password}")
private String password;

@Value("${rpt.datasource.JNDI}")
private String JNDI;

@GetMapping("/Report/*/*")
public void handReportRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try {
Expand Down Expand Up @@ -98,7 +101,7 @@ public void handReportRequest(HttpServletRequest req, HttpServletResponse resp)

// open report
clientDoc = ReportClientDocument.openReport(file);

// Check/Set report param
List<String> reportParams = CRJavaHelper.getTopParams(clientDoc);
for (String param : reportParams) {
Expand Down Expand Up @@ -126,8 +129,17 @@ public void handReportRequest(HttpServletRequest req, HttpServletResponse resp)
clientDoc.setSummaryInfo(summaryInfo);

// set Database connection
CRJavaHelper.changeDataSource(clientDoc, username, password, url, driverClassName, report + ".rpt", reportsPath);

CRJavaHelper.changeDataSource(
clientDoc,
username,
password,
url,
driverClassName,
JNDI,
report + ".rpt",
reportsPath
);

// export report
switch (format) {
case "pdf":
Expand Down

0 comments on commit 9437a2b

Please sign in to comment.