Skip to content

Commit

Permalink
release: 🎉1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hks2002 committed Oct 19, 2023
1 parent ea6e581 commit d264a8a
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Release-Please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
workflow_dispatch:
push:
branches:
- 'main'
- 'master'

# https://github.com/OWNER/REPO/settings/actions
# MUST CHANGE GITHUB_TOKEN PERMISSION FROM READ TO WRITE
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ buildNumber.properties

### spring-boot ###
application-prod.properties

reports
20 changes: 2 additions & 18 deletions .mvn/wrapper/maven-wrapper.properties
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
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
"internal-terms": false // Disable the `internal-terms` dictionary
},
"auto-header-plus.pathContainsWorkspaceFolder": false,
"java.debug.settings.onBuildFailureProceed": true
"java.debug.settings.onBuildFailureProceed": true,
"auto-header-plus.commentElementsValue": {
"CopyRight": "Dedienne Aerospace China ZhuHai"
},
"auto-header-plus.style.0": {
"lineWidth": 120
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ An Crystal Report server run in java.

### Linux System Prepare

1. Copy fonts to`JAVA_HOME/lib/fonts`, and set permission to this folder。
1. Copy fonts to`$JAVA_HOME/lib/fonts`, and set permission to this folder。
```
sudo chmod -R $JAVA_HOME/lib/fonts 755
```
Expand All @@ -34,10 +34,10 @@ An Crystal Report server run in java.
2. Config your database url, driverClassName, user, password in `application.properties`.
3. Run `maven package` to get `war` package.
4. Copy `war` to tomcat, copy crystal dependency `lib` files to `WEB-INF/lib` folder, and run tomcat.
5. Then copy your crystal report files to `WEB-INF/reports` folder, you can add them at anytime.
5. Then copy your crystal report files to `WEB-INF/class/reports` folder, you can add them at anytime.
6. Open `http://server:port/Report/{ReportTemplateName}/{format}?param0=val0&param1=val1` in browser, you can see your report.
7. If chinese text can't display in pdf, please configure /ect/locale.conf `LANG=zh_CN.UTF-8`
> Note: `{ReportTemplateName}` is the name of your report template file without extension, `{format}` is the format you want, such as `pdf` `doc` `xls`, `param0` and `param1` are the parameters of your report, give a param named with `filename`, this param value will be used as the file name.
> Suggestion: Using `Command SQL` instead of `Table Link` for better performance, reduce the report generation duration.
> Suggestion: Set Tomcat JNI for better performance, reduce the report generation duration.
6 changes: 3 additions & 3 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

### Linux 系统环境准备

1. 将需要到字体复制到`JAVA_HOME/lib/fonts`目录中, 并设置好权限。
1. 将需要到字体复制到`$JAVA_HOME/lib/fonts`目录中, 并设置好权限。
```
sudo chmod -R $JAVA_HOME/lib/fonts 755
```
Expand All @@ -34,10 +34,10 @@
2. 在 `application.properties` 中配置数据库连接信息。
3. 运行 `maven package` 生成 `war` 包,将 `war` 包拷贝到 tomcat(或者其他容器) 中运行, `war`包是为了更新报表更便捷。
4. 将依赖库`lib`文件拷贝到`WEB-INF/lib` 文件夹中。
5. 将水晶报表`rpt`文件拷贝到 `WEB-INF/reports` 文件夹中,可以随时添加。
5. 将水晶报表`rpt`文件拷贝到 `WEB-INF/class/reports` 文件夹中,可以随时添加。
6. 在浏览器中打开 `http://server:port/Report/{ReportTemplateName}/{format}?param0=val0&param1=val1`,即可看到报表。
7. 如果 pdf 文件不能显示中文, 请编辑/ect/locale.conf `LANG=zh_CN.UTF-8`
> 说明:`{ReportTemplateName}` 是报表模板文件名,不包含扩展名;`{format}` 是报表格式,如 `pdf` `doc` `xls`;`param0` 和 `param1` 是报表参数,如果有一个参数名包含 `filename`,则该参数值将作为文件名。
> 建议:使用`Command SQL`代替`Table Link`,可以获得更快的报表生成速度。
> 建议:配置 Tomcat JNDI 数据库连接池,可以获得更快到报表生成速度。
Binary file modified lib/CrystalCommon2.jar
Binary file not shown.
Binary file modified lib/CrystalReportsRuntime.jar
Binary file not shown.
Binary file modified lib/DatabaseConnectors.jar
Binary file not shown.
Binary file modified lib/JDBInterface.jar
Binary file not shown.
Binary file modified lib/QueryBuilder.jar
Binary file not shown.
Binary file modified lib/cvom.jar
Binary file not shown.
Binary file modified lib/jrcerom.jar
Binary file not shown.
Binary file modified lib/logging.jar
Binary file not shown.
Binary file modified lib/pfjgraphics.jar
Binary file not shown.
16 changes: 12 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
<version>3.1.4</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<groupId>com.da</groupId>
Expand Down Expand Up @@ -49,7 +50,7 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down Expand Up @@ -281,9 +282,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.0</version>
<configuration>
<webResources>
<resource>
<directory>${pom.basedir}/lib</directory>
<includes>
<include>*.jar</include>
</includes>
<targetPath>WEB-INF/lib</targetPath>
</resource>
</webResources>
<packagingIncludes>
</packagingIncludes>
Expand Down
Binary file modified reports/TEST.rpt
Binary file not shown.
166 changes: 86 additions & 80 deletions src/main/java/com/da/crystal/report/CRJavaHelper.java
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.
Expand Down Expand Up @@ -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());
}
}

Expand Down
Loading

0 comments on commit d264a8a

Please sign in to comment.