From 59001462ddae74c01d8cbb7cd45b3ccb677948e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yvan-=E6=AC=A7=E9=98=B3=E5=B8=86?= Date: Thu, 13 Oct 2022 11:38:47 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-75091=20-=20=E6=95=B0=E6=8D=AE=E8=84=B1?= =?UTF-8?q?=E6=95=8F=EF=BC=88=E6=8A=A5=E8=A1=A8=EF=BC=89=20=E3=80=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=8E=9F=E5=9B=A0=E3=80=91=20=E3=80=90?= =?UTF-8?q?=E6=94=B9=E5=8A=A8=E6=80=9D=E8=B7=AF=E3=80=91=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E8=AF=84=E5=AE=A1=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9=E4=B8=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E3=80=81=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96=E7=AD=89?= =?UTF-8?q?=EF=BC=9B=E5=8F=A6=E8=A1=A5=E4=BA=86=E4=B8=80=E4=B8=AA=E6=BC=8F?= =?UTF-8?q?=E5=81=9A=E7=9A=84UI=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datapane/preview/PreviewTableModel.java | 8 +- .../TableDataPreviewDesensitizeManager.java | 42 +++++---- .../model/DesensitizedPreviewTableModel.java | 1 + .../view/common/DesensitizationOpenPane.java | 94 +++++++++++++++++++ .../rule/DesensitizationRuleChoosePane.java | 4 + .../rule/DesensitizationRuleDebugPane.java | 5 +- .../rule/DesensitizationRuleEditPane.java | 3 + .../view/rule/DesensitizationRulePane.java | 2 + .../DesensitizationRuleSourceChoosePane.java | 1 + .../TableDataDesensitizationSettingPane.java | 32 ++----- .../TableDataDesensitizationTableModel.java | 8 ++ .../TableDataDesensitizationTablePane.java | 2 + .../fr/design/standard/tip/tips_normal.svg | 3 + 13 files changed, 164 insertions(+), 41 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java create mode 100644 designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java index 91c8506b79..49ce4ba420 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java @@ -20,13 +20,19 @@ public class PreviewTableModel extends AbstractTableModel { private static final int LEN_LIMIT = 1000; private static final String THREE_DOT = "..."; + private static final int DEFAULT_MAX_ROW_COUNT = 10000; private DataModel dataModel; private String erroMessage = null; public IntList dateIndexs = new IntList(4); - public PreviewTableModel() {} + /** + * 为了兼容子类的空参构造,一般不主动使用 + */ + public PreviewTableModel() { + this(new ErrorResultSet(), DEFAULT_MAX_ROW_COUNT); + } public PreviewTableModel(int maxRowCount) { // peter:默认必须显示错误的数据源. diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java index e2d79fbf70..9cc82dfdda 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java @@ -30,6 +30,7 @@ import java.util.stream.Collectors; /** * 管理所有数据集预览过程中的脱敏计算 + * * @author Yvan * @version 11.0 * Created by Yvan on 2022/9/14 @@ -47,6 +48,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage /** * 获取TableDataPreviewDesensitizeManager单例 + * * @return */ public static TableDataPreviewDesensitizeManager getInstance() { @@ -72,29 +74,32 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage * @return */ public PreviewTableModel desensitizeTableModel(TableData tableData, PreviewTableModel model) { - if (needDesensitize(tableData)) { - Map desensitizationBeanMap = new LinkedHashMap<>(); - // 获取此数据集的所有脱敏信息 - Collection desensitizationBeans = ((AbstractDesensitizationTableData) tableData).getDesensitizationBeans(); - // 排个序 - List sortedBeans = desensitizationBeans.stream().sorted(Comparator.comparingInt(TableDataDesensitizationBean::getColumnIndex)).collect(Collectors.toList()); - int columnIndex = 0; - for (TableDataDesensitizationBean sortedBean : sortedBeans) { - // 当map中已包含列序号时,代表对这一列设置了不同的脱敏规则,将key + 1 - if (desensitizationBeanMap.containsKey(columnIndex)) { - columnIndex++; - } - desensitizationBeanMap.put(columnIndex, sortedBean); + + Map desensitizationBeanMap = new LinkedHashMap<>(); + // 获取此数据集的所有脱敏信息 + Collection desensitizationBeans = ((AbstractDesensitizationTableData) tableData).getDesensitizationBeans(); + // 去除被禁用的规则 + 排序 + List sortedBeans = desensitizationBeans + .stream() + .filter(bean -> bean.getDesensitizationRule().isEnable()) + .sorted(Comparator.comparingInt(TableDataDesensitizationBean::getColumnIndex)) + .collect(Collectors.toList()); + int columnIndex = 0; + for (TableDataDesensitizationBean sortedBean : sortedBeans) { + // 当map中已包含列序号时,代表对这一列设置了不同的脱敏规则,将key + 1 + if (desensitizationBeanMap.containsKey(columnIndex)) { + columnIndex++; } - // 包装TableModel - return new DesensitizedPreviewTableModel(model, desensitizationBeanMap); + desensitizationBeanMap.put(columnIndex, sortedBean); } - return model; + // 包装TableModel + return new DesensitizedPreviewTableModel(model, desensitizationBeanMap); } /** * 通过TableData获取其列名 * 实现逻辑有点绕,TableData本身并不能返回列名集合,只能先去获取当前模板所有数据集,然后匹配名称拿到TableDataWrapper再获取列名 + * * @param tableData * @return */ @@ -114,6 +119,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage /** * 这个api会返回 部门职位 + 自定义角色 的Map * 其中 key为 "pid" + "_" + "id",value为 "ptext" + "text" + * * @return */ public Map getAllRoles() { @@ -127,6 +133,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage /** * 获取所有的部门职位,按照 key为 "pid" + "_" + "id",value为 "ptext" + "text"的格式添加到参数Map中 + * * @param rolesMap */ private void addDepartmentAndPositionRoles2Map(Map rolesMap) { @@ -149,6 +156,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage /** * 获取所有的自定义角色,按照 id - name添加到参数map里 + * * @param rolesMap */ private void addCustomRoles2Map(Map rolesMap) { @@ -162,6 +170,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage /** * 合并部门 + 职位的名称 + * * @param departmentName * @param positionName * @return @@ -172,6 +181,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage /** * 合并部门 + 职位的id + * * @param departmentId * @param positionId * @return diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java index 066f11374b..e3598e39c0 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java @@ -98,6 +98,7 @@ public class DesensitizedPreviewTableModel extends PreviewTableModel { /** * 获取当前有效的脱敏字段个数 + * * @return */ public int getDesensitizeColumnsCount() { diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java new file mode 100644 index 0000000000..949069aaa8 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java @@ -0,0 +1,94 @@ +package com.fr.design.data.datapane.preview.desensitization.view.common; + +import com.fr.base.svg.IconUtils; +import com.fr.design.border.UITitledBorder; +import com.fr.design.constants.UIConstants; +import com.fr.design.gui.icheckbox.UICheckBox; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.layout.VerticalFlowLayout; +import com.fr.log.FineLoggerFactory; + +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Desktop; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.net.URL; + +/** + * 启用数据脱敏的面板 + * + * @author Yvan + * @version 11.0 + * Created by Yvan on 2022/10/12 + */ +public class DesensitizationOpenPane extends JPanel { + + /** + * 数据脱敏启用框 + */ + private UICheckBox desensitizeOpenCheckBox; + + /** + * 跳转帮助文档Label + */ + private UILabel hyperlinkLabel; + + /** + * 启用提示Label + */ + private UILabel tipsLabel; + + + public DesensitizationOpenPane() { + VerticalFlowLayout layout = new VerticalFlowLayout(VerticalFlowLayout.TOP); + layout.setAlignLeft(true); + this.setLayout(layout); + this.setBorder(UITitledBorder.createBorderWithTitle(Toolkit.i18nText("Fine-Design_Report_Desensitization_Config"))); + + JPanel panel = FRGUIPaneFactory.createLeftFlowZeroGapBorderPane(); + // 启用数据脱敏的勾选框 + desensitizeOpenCheckBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Desensitization_Opened")); + // 跳转帮助文档Label + hyperlinkLabel = new UILabel(IconUtils.readIcon("/com/fr/design/standard/tip/tips")); + hyperlinkLabel.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Open_Tips")); + hyperlinkLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent event) { + try { + URL url = new URL(Toolkit.i18nText("Fine-Design_Report_Desensitization_Help_Document_Url")); + Desktop.getDesktop().browse(url.toURI()); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e, "open browse of table data desensitization help document failed for {}", e.getMessage()); + } + } + }); + panel.add(desensitizeOpenCheckBox); + panel.add(hyperlinkLabel); + + // 提示Label + tipsLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Opened_Tooltips")); + tipsLabel.setForeground(UIConstants.CHECK_BOX_TIP_FONT_COLOR); + + this.add(panel); + this.add(tipsLabel); + } + + /** + * 数据脱敏启用状态 + * @return + */ + public boolean isDesensitizationOpened() { + return desensitizeOpenCheckBox.isSelected(); + } + + /** + * 设置数据脱敏启用状态 + * @param opened + */ + public void setDesensitizationOpened(boolean opened) { + desensitizeOpenCheckBox.setSelected(opened); + } +} diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java index 3f8485ffa5..16900defa4 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java @@ -62,6 +62,7 @@ public class DesensitizationRuleChoosePane extends JPanel { /** * 通过脱敏规则来源,切换显示不同的脱敏规则Table面板 + * * @param ruleSource */ public void switchPaneByRuleSource(DesensitizationRuleSource ruleSource) { @@ -125,10 +126,13 @@ public class DesensitizationRuleChoosePane extends JPanel { DesensitizationRule rule = getList().get(rowIndex); switch (columnIndex) { case 0: + // 选中状态 return rule.equals(getSelectedValue()); case 1: + // 脱敏规则名称 return rule.getRuleName(); case 2: + // 脱敏规则描述 return DesensitizationRule.getDescription(rule); default: return StringUtils.EMPTY; diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java index 71998b7bee..5f74dee9c0 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java @@ -24,6 +24,7 @@ import java.awt.event.FocusListener; /** * 脱敏规则调试页 + * * @author Yvan * @version 11.0 * Created by Yvan on 2022/9/8 @@ -53,7 +54,7 @@ public class DesensitizationRuleDebugPane extends BasicPane { UILabel desensitizationRule = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Algorithm")); UILabel characterReplace = new UILabel(rule.getRuleType().getTypeName()); UILabel description = new UILabel(DesensitizationRule.getDescription(rule)); - JComponent[][] components = new JComponent[][] { + JComponent[][] components = new JComponent[][]{ {desensitizationRule, characterReplace}, {new UILabel(), description} }; @@ -104,7 +105,7 @@ public class DesensitizationRuleDebugPane extends BasicPane { } }); - JComponent[][] components = new JComponent[][] { + JComponent[][] components = new JComponent[][]{ {beforeDesensitize, beforeDesensitizeText, desensitizeButton}, {afterDesensitize, afterDesensitizeText, new UILabel()} }; diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java index 9c2c467fe3..2f526f4b8f 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java @@ -136,6 +136,7 @@ public class DesensitizationRuleEditPane extends BasicBeanPane /** * 处理规则来源选择面板中改动来源的事件 + * * @param newRuleSource */ public void dealWithRuleSourceChanged(DesensitizationRuleSource newRuleSource) { diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java index f67512164e..05ace32bdd 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java @@ -11,6 +11,7 @@ import java.awt.FlowLayout; /** * 脱敏规则来源选择页面 + * * @author Yvan * @version 11.0 * Created by Yvan on 2022/9/26 diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java index f63bcdacc3..91119b4083 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java @@ -3,19 +3,17 @@ package com.fr.design.data.datapane.preview.desensitization.view.setting; import com.fr.data.desensitize.base.AbstractDesensitizationTableData; import com.fr.data.desensitize.base.TableDataDesensitizationBean; import com.fr.design.beans.BasicBeanPane; -import com.fr.design.constants.UIConstants; -import com.fr.design.gui.icheckbox.UICheckBox; -import com.fr.design.gui.ilable.UILabel; +import com.fr.design.data.datapane.preview.desensitization.view.common.DesensitizationOpenPane; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import javax.swing.JComponent; -import javax.swing.JPanel; import java.awt.BorderLayout; import java.util.List; /** * 数据集脱敏字段设置页面 + * * @author Yvan * @version 11.0 * Created by Yvan on 2022/9/8 @@ -27,7 +25,7 @@ public class TableDataDesensitizationSettingPane extends BasicBeanPane tableDataDesensitizationBeans) { diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java index 36322c3980..099f5d0b1b 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java @@ -109,12 +109,16 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter generateRolesIdsBySelectedValues() { diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java index 77546b9ef1..b9311f0c4b 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java @@ -12,6 +12,7 @@ import java.util.List; /** * 脱敏字段设置页面中的Table + * * @author Yvan * @version 11.0 * Created by Yvan on 2022/9/14 @@ -48,6 +49,7 @@ public class TableDataDesensitizationTablePane extends JPanel { /** * 展示此TableData中已配置的脱敏规则信息 + * * @param tableData */ public void populateDesensitizationSetting(AbstractDesensitizationTableData tableData) { diff --git a/designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg b/designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg new file mode 100644 index 0000000000..cfc3370a66 --- /dev/null +++ b/designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg @@ -0,0 +1,3 @@ + + +