|
|
@@ -8,6 +8,7 @@ import com.crystaldecisions.sdk.occa.report.data.IDatabase;
|
|
|
import com.crystaldecisions.sdk.occa.report.data.ITable;
|
|
|
import com.crystaldecisions.sdk.occa.report.data.Tables;
|
|
|
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
|
|
|
+import com.uas.report.util.ArrayUtils;
|
|
|
import com.uas.report.util.FileUtils;
|
|
|
import com.uas.report.util.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -18,6 +19,8 @@ import java.io.FileFilter;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
+ * 在报表的视图名称前添加前缀
|
|
|
+ *
|
|
|
* @author sunyj
|
|
|
* @since 2017/12/22 10:42
|
|
|
*/
|
|
|
@@ -30,6 +33,7 @@ public class CrystalReplaceView {
|
|
|
logger.error("参数缺失\neg. java -jar target/crystal-replace-view-0.0.1.jar src/test/resources/rpts HUASL_");
|
|
|
return;
|
|
|
}
|
|
|
+ // 命令行接收两个参数:报表路径、需添加的前缀
|
|
|
File src = new File(args[0]);
|
|
|
String prefix = args[1];
|
|
|
try {
|
|
|
@@ -39,6 +43,13 @@ public class CrystalReplaceView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 替换报表的视图名称
|
|
|
+ *
|
|
|
+ * @param src 报表文件(夹)
|
|
|
+ * @param prefix 需添加的视图前缀
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
public static void replaceReports(File src, String prefix) throws IOException {
|
|
|
logger.info("start...");
|
|
|
if (src == null || StringUtils.isEmpty(prefix)) {
|
|
|
@@ -53,6 +64,14 @@ public class CrystalReplaceView {
|
|
|
logger.info("completed...");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 替换指定文件夹下报表的视图名称
|
|
|
+ *
|
|
|
+ * @param reportDir 报表文件夹
|
|
|
+ * @param successDir 报表替换成功后,新报表的路径
|
|
|
+ * @param prefix 需添加的视图前缀
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
private static void replaceReports(File reportDir, File successDir, String prefix) throws IOException {
|
|
|
FileUtils.checkDir(reportDir);
|
|
|
File[] files = reportDir.listFiles(new FileFilter() {
|
|
|
@@ -67,19 +86,19 @@ public class CrystalReplaceView {
|
|
|
|| filePath.contains("/success/")) {
|
|
|
return false;
|
|
|
}
|
|
|
- // 文件必须是rpt或者zip格式
|
|
|
- if (file.isFile() && !filePath.endsWith(".rpt") && !filePath.endsWith(".zip")) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
+ // 文件必须是 rpt 格式
|
|
|
+ return !file.isFile() || filePath.endsWith(".rpt");
|
|
|
}
|
|
|
});
|
|
|
+ if (ArrayUtils.isEmpty(files)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
for (File file : files) {
|
|
|
try {
|
|
|
String fileName = file.getName();
|
|
|
// 是文件夹的话,递归处理
|
|
|
if (file.isDirectory()) {
|
|
|
- // 不可直接修改successDir和outDir,否则会造成其他文件的路径有问题
|
|
|
+ // 不可直接修改 successDir,否则会造成其他文件的路径有问题
|
|
|
File successDirCopy = new File(successDir, fileName);
|
|
|
replaceReports(file, successDirCopy, prefix);
|
|
|
} else {
|
|
|
@@ -91,6 +110,14 @@ public class CrystalReplaceView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 替换单个报表的视图名称
|
|
|
+ *
|
|
|
+ * @param reportFile 报表文件
|
|
|
+ * @param successDir 报表替换成功后,新报表的路径
|
|
|
+ * @param prefix 需添加的视图前缀
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
private static void replaceReport(File reportFile, File successDir, String prefix) throws IOException {
|
|
|
logger.info("replacing... " + reportFile.getName());
|
|
|
FileUtils.initDir(successDir);
|
|
|
@@ -102,9 +129,9 @@ public class CrystalReplaceView {
|
|
|
DatabaseController databaseController = client.getDatabaseController();
|
|
|
IDatabase database = databaseController.getDatabase();
|
|
|
Tables tables = database.getTables();
|
|
|
- for (int j = 0; j < tables.size(); j++) {
|
|
|
- ITable iTable = tables.get(j);
|
|
|
+ for (ITable iTable : tables) {
|
|
|
String alias = iTable.getAlias();
|
|
|
+ // 只替换以 '_VIEW' 结尾的视图,不替换表
|
|
|
if (alias.toUpperCase().endsWith("_VIEW")) {
|
|
|
logger.info("replacing table: name=" + iTable.getName() + ", alias=" + alias);
|
|
|
// 修改视图名称
|