-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
174 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,5 @@ buildNumber.properties | |
|
||
### spring-boot ### | ||
application-prod.properties | ||
|
||
reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,2 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
/********************************************************************************************************************* | ||
* @Author : Robert Huang<[email protected]> * | ||
* @CreatedDate : 2023-03-07 00:03:27 * | ||
* @LastEditors : Robert Huang<[email protected]> * | ||
* @LastEditDate : 2023-06-28 13:00:08 * | ||
* @FilePath : src/main/java/com/da/crystal/report/CRJavaHelper.java * | ||
* @CopyRight : Dedienne Aerospace China ZhuHai * | ||
********************************************************************************************************************/ | ||
/********************************************************************************************************************** | ||
* @Author : Robert Huang<[email protected]> * | ||
* @CreatedDate : 2023-03-07 00:03:27 * | ||
* @LastEditors : Robert Huang<[email protected]> * | ||
* @LastEditDate : 2023-10-19 16:38:07 * | ||
* @FilePath : src/main/java/com/da/crystal/report/CRJavaHelper.java * | ||
* @CopyRight : Dedienne Aerospace China ZhuHai * | ||
*********************************************************************************************************************/ | ||
|
||
/** | ||
* This sample code is an example of how to use the Business Objects APIs. | ||
|
@@ -82,102 +82,108 @@ public static void logonDataSource(ReportClientDocument clientDoc, String userna | |
|
||
/** | ||
* Changes the DataSource for all table, include sub reports also. | ||
* ⚠️Suggest setup JNDI for best performance⚠️ | ||
* If it doesn't need to change the DataSource, it will do logon directly, | ||
* If changed the DataSource, it will save the datasource to the report | ||
* ⚠️Suggest using Command sql instead of tables⚠️ | ||
* | ||
* @param clientDoc The reportClientDocument representing the report being used | ||
* @param username The DB logon user name | ||
* @param password The DB logon password | ||
* @param connectionURL The connection URL | ||
* @param driverName The driver Name | ||
* @param jndiName The JNDI name, without "jdbc/", but you need set: <Resource name="jdbc/xxx" | ||
* @param jndiName The JNDI Name | ||
* @param fileName The file name | ||
* @param filePath The file path | ||
* // How to use a JNDI data source with the Crystal Reports Java SDK on Tomcat https://userapps.support.sap.com/sap/support/knowledge/en/1343290 | ||
* @throws ReportSDKException | ||
* @throws IOException | ||
*/ | ||
public static void changeDataSource( | ||
ReportClientDocument clientDoc, | ||
String username, | ||
String password, | ||
String connectionURL, | ||
String driverName, | ||
String jndiName | ||
) throws ReportSDKException { | ||
// Set new table connection property attributes | ||
PropertyBag newPropertyBag = new PropertyBag(); | ||
|
||
// Below is the list of values required to switch to use a JDBC/JNDI connection | ||
// How to use a JNDI data source with the Crystal Reports Java SDK on Tomcat | ||
// https://userapps.support.sap.com/sap/support/knowledge/en/1343290 | ||
if (jndiName == null || jndiName.isEmpty()) { | ||
log.info("JNDI name for Crystal Report is empty"); | ||
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"); | ||
} else if (!jndiName.startsWith("jdbc/", 0)) { | ||
log.warn("JNDI name for Crystal Report must start with 'jdbc/'"); | ||
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"); | ||
} else { | ||
jndiName = jndiName.replace("jdbc/", ""); | ||
newPropertyBag.put("Connection Name (Optional)", jndiName); | ||
} | ||
|
||
// If not JNDI and same jdbc info, just do login | ||
IConnectionInfo oldConnectionInfo = clientDoc.getDatabaseController().getConnectionInfos(null).get(0); | ||
PropertyBag oldPropertyBag = oldConnectionInfo.getAttributes(); | ||
if ( | ||
!newPropertyBag.containsKey("Connection Name (Optional)") && | ||
oldPropertyBag.getStringValue("Server Type").equals("JDBC (JNDI)") && | ||
oldPropertyBag.getStringValue("Connection URL").equals(connectionURL) && | ||
oldPropertyBag.getStringValue("Database Class Name").equals(driverName) | ||
) { | ||
logonDataSource(clientDoc, username, password); | ||
return; | ||
} | ||
String jndiName, | ||
String fileName, | ||
String filePath | ||
) { | ||
try { | ||
// Set new table connection property attributes | ||
PropertyBag newPropertyBag = new PropertyBag(); | ||
|
||
// Below is the list of values required to switch to use a JDBC/JNDI connection | ||
// How to use a JNDI data source with the Crystal Reports Java SDK on Tomcat | ||
// JNDI name for Crystal Report must start with 'jdbc/' | ||
// https://userapps.support.sap.com/sap/support/knowledge/en/1343290 | ||
|
||
if (!jndiName.isBlank()) { | ||
newPropertyBag.put("Connection Name (Optional)", jndiName); | ||
} 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"); | ||
} | ||
|
||
Tables tables = null; | ||
ITable table = null; | ||
ITable newTable = null; | ||
|
||
// Obtain collection of tables from this database controller | ||
tables = clientDoc.getDatabaseController().getDatabase().getTables(); | ||
for (int i = 0; i < tables.size(); i++) { | ||
table = tables.getTable(i); | ||
// ⚠️⚠️⚠️ Must Update the table with new table, It's seems a bug of Crystal Report | ||
newTable = changeDataSource(table, newPropertyBag, username, password); | ||
clientDoc.getDatabaseController().setTableLocation(table, newTable); | ||
} | ||
// If same jdbc info, just do login | ||
IConnectionInfo oldConnectionInfo = clientDoc.getDatabaseController().getConnectionInfos(null).get(0); | ||
PropertyBag oldPropertyBag = oldConnectionInfo.getAttributes(); | ||
if (jndiName.isBlank() && | ||
oldPropertyBag.getStringValue("Server Type").equals("JDBC (JNDI)") && | ||
oldPropertyBag.getStringValue("Connection URL").equals(connectionURL) && | ||
oldPropertyBag.getStringValue("Database Class Name").equals(driverName) | ||
) { | ||
logonDataSource(clientDoc, username, password); | ||
return; | ||
} | ||
|
||
// Next loop through all the subReports. | ||
IStrings subReportNames = clientDoc.getSubreportController().getSubreportNames(); | ||
for (int subNum = 0; subNum < subReportNames.size(); subNum++) { | ||
String subReportName = subReportNames.getString(subNum); | ||
Tables tables = null; | ||
ITable table = null; | ||
ITable newTable = null; | ||
|
||
tables = | ||
clientDoc | ||
.getSubreportController() | ||
.getSubreport(subReportName) | ||
.getDatabaseController() | ||
.getDatabase() | ||
.getTables(); | ||
// Obtain collection of tables from this database controller | ||
tables = clientDoc.getDatabaseController().getDatabase().getTables(); | ||
for (int i = 0; i < tables.size(); i++) { | ||
table = tables.getTable(i); | ||
|
||
// ⚠️⚠️⚠️ Must Update the table with new table, It's seems a bug of Crystal Report | ||
newTable = changeDataSource(table, newPropertyBag, username, password); | ||
clientDoc | ||
.getSubreportController() | ||
.getSubreport(subReportName) | ||
.getDatabaseController() | ||
.setTableLocation(table, newTable); | ||
clientDoc.getDatabaseController().setTableLocation(table, newTable); | ||
} | ||
|
||
// Next loop through all the subReports. | ||
IStrings subReportNames = clientDoc.getSubreportController().getSubreportNames(); | ||
for (int subNum = 0; subNum < subReportNames.size(); subNum++) { | ||
String subReportName = subReportNames.getString(subNum); | ||
|
||
tables = | ||
clientDoc | ||
.getSubreportController() | ||
.getSubreport(subReportName) | ||
.getDatabaseController() | ||
.getDatabase() | ||
.getTables(); | ||
for (int i = 0; i < tables.size(); i++) { | ||
table = tables.getTable(i); | ||
|
||
// ⚠️⚠️⚠️ Must Update the table with new table, It's seems a bug of Crystal Report | ||
newTable = changeDataSource(table, newPropertyBag, username, password); | ||
clientDoc | ||
.getSubreportController() | ||
.getSubreport(subReportName) | ||
.getDatabaseController() | ||
.setTableLocation(table, newTable); | ||
} | ||
} | ||
|
||
// if modified, save it, so that could directly login, change data source is slowly. | ||
clientDoc.saveAs(fileName, filePath, 1); | ||
} catch (ReportSDKExceptionBase e) { | ||
log.error(e.getMessage()); | ||
} catch (IOException e) { | ||
log.error(e.getMessage()); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.