Browse Source

REPORT-75091 - 数据脱敏(报表)

【问题原因】
【改动思路】根据评审意见修改下代码,添加注释、代码格式化等;另补了一个漏做的UI图标
feature/x
Yvan-欧阳帆 2 years ago
parent
commit
59001462dd
  1. 8
      designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java
  2. 42
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java
  3. 1
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java
  4. 94
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/common/DesensitizationOpenPane.java
  5. 4
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java
  6. 5
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java
  7. 3
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java
  8. 2
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java
  9. 1
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleSourceChoosePane.java
  10. 32
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java
  11. 8
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java
  12. 2
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java
  13. 3
      designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg

8
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:默认必须显示错误的数据源.

42
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<Integer, TableDataDesensitizationBean> desensitizationBeanMap = new LinkedHashMap<>();
// 获取此数据集的所有脱敏信息
Collection<TableDataDesensitizationBean> desensitizationBeans = ((AbstractDesensitizationTableData) tableData).getDesensitizationBeans();
// 排个序
List<TableDataDesensitizationBean> 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<Integer, TableDataDesensitizationBean> desensitizationBeanMap = new LinkedHashMap<>();
// 获取此数据集的所有脱敏信息
Collection<TableDataDesensitizationBean> desensitizationBeans = ((AbstractDesensitizationTableData) tableData).getDesensitizationBeans();
// 去除被禁用的规则 + 排序
List<TableDataDesensitizationBean> 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<String, String> getAllRoles() {
@ -127,6 +133,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
/**
* 获取所有的部门职位按照 key为 "pid" + "_" + "id"value为 "ptext" + "text"的格式添加到参数Map中
*
* @param rolesMap
*/
private void addDepartmentAndPositionRoles2Map(Map<String, String> rolesMap) {
@ -149,6 +156,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
/**
* 获取所有的自定义角色按照 id - name添加到参数map里
*
* @param rolesMap
*/
private void addCustomRoles2Map(Map<String, String> 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

1
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() {

94
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);
}
}

4
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;

5
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()}
};

3
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<DesensitizationRu
/**
* 初始化规则类型面板
*
* @return
*/
private JPanel initRuleTypePane() {
@ -148,6 +149,7 @@ public class DesensitizationRuleEditPane extends BasicBeanPane<DesensitizationRu
/**
* 初始化规则条件面板
*
* @return
*/
private JPanel initRuleConditionPane() {
@ -194,6 +196,7 @@ public class DesensitizationRuleEditPane extends BasicBeanPane<DesensitizationRu
/**
* 切换规则类型面板
*
* @param ruleType
*/
private void switchRuleConditionPane(DesensitizationRuleType ruleType) {

2
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRulePane.java

@ -12,6 +12,7 @@ import java.awt.BorderLayout;
/**
* 脱敏规则展示页
*
* @author Yvan
* @version 11.0
* Created by Yvan on 2022/9/8
@ -53,6 +54,7 @@ public class DesensitizationRulePane extends BasicBeanPane<DesensitizationRule>
/**
* 处理规则来源选择面板中改动来源的事件
*
* @param newRuleSource
*/
public void dealWithRuleSourceChanged(DesensitizationRuleSource newRuleSource) {

1
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

32
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<AbstractD
*/
private AbstractDesensitizationTableData tableData;
private UICheckBox desensitizeOpen;
private DesensitizationOpenPane desensitizationOpenPane;
private TableDataDesensitizationTablePane tableDataDesensitizationTablePane;
@ -45,20 +43,17 @@ public class TableDataDesensitizationSettingPane extends BasicBeanPane<AbstractD
/**
* 初始化启用数据脱敏面板
*
* @return
*/
private JComponent initNorthPane() {
JPanel northPane = FRGUIPaneFactory.createTopVerticalTitledBorderPane(Toolkit.i18nText("Fine-Design_Report_Desensitization_Config"));
this.desensitizeOpen = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Desensitization_Opened"));
northPane.add(desensitizeOpen);
UILabel tipLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Opened_Tooltips"));
tipLabel.setForeground(UIConstants.CHECK_BOX_TIP_FONT_COLOR);
northPane.add(tipLabel);
return northPane;
this.desensitizationOpenPane = new DesensitizationOpenPane();
return desensitizationOpenPane;
}
/**
* 初始化数据脱敏规则表面板
*
* @return
*/
private JComponent initCenterPane() {
@ -66,14 +61,6 @@ public class TableDataDesensitizationSettingPane extends BasicBeanPane<AbstractD
return tableDataDesensitizationTablePane;
}
/**
* 是否启用脱敏
* @return
*/
public boolean isDesensitizeOpened() {
return desensitizeOpen.isSelected();
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine-Design_Report_Desensitization_Config");
@ -82,7 +69,7 @@ public class TableDataDesensitizationSettingPane extends BasicBeanPane<AbstractD
@Override
public void populateBean(AbstractDesensitizationTableData tableData) {
this.tableData = tableData;
this.desensitizeOpen.setSelected(tableData.getDesensitizeOpen());
this.desensitizationOpenPane.setDesensitizationOpened(tableData.getDesensitizeOpen());
tableDataDesensitizationTablePane.populateDesensitizationSetting(tableData);
}
@ -97,11 +84,12 @@ public class TableDataDesensitizationSettingPane extends BasicBeanPane<AbstractD
* 保存脱敏启用状态
*/
public void saveDesensitizeOpened() {
tableData.setDesensitizeOpen(desensitizeOpen.isSelected());
tableData.setDesensitizeOpen(this.desensitizationOpenPane.isDesensitizationOpened());
}
/**
* 保存脱敏规则配置信息
*
* @param tableDataDesensitizationBeans
*/
public void saveDesensitizationBeans(List<TableDataDesensitizationBean> tableDataDesensitizationBeans) {

8
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<Tabl
TableDataDesensitizationBean desensitizationBean = this.getList().get(rowIndex);
switch (columnIndex) {
case 0:
// 选中的数据集字段名称
return getColumnNameValue(desensitizationBean);
case 1:
// 脱敏规则名称
return desensitizationBean.getDesensitizationRule().getRuleName();
case 2:
// 脱敏规则详情
return DesensitizationRule.getDescription(desensitizationBean.getDesensitizationRule());
case 3:
// 生效用户组
return matchRoleNamesByIds(desensitizationBean.getRoleIds());
default:
return StringUtils.EMPTY;
@ -123,6 +127,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
/**
* 根据当前选中的Bean获取其对应的列名字段
*
* @param desensitizationBean
* @return
*/
@ -139,6 +144,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
/**
* 判断字段索引是否越界
*
* @param columnIndex
* @return
*/
@ -378,6 +384,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
/**
* 根据当前的规则配置信息生成选中的rolesMap用来展示
*
* @param desensitizationBean
* @return
*/
@ -397,6 +404,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
/**
* 根据当前的RoleName选择项生成其对应的RoleId的set存入规则配置信息
*
* @return
*/
private Set<String> generateRolesIdsBySelectedValues() {

2
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) {

3
designer-base/src/main/resources/com/fr/design/standard/tip/tips_normal.svg

@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8C15 11.866 11.866 15 8 15ZM8 14C11.3137 14 14 11.3137 14 8C14 4.68629 11.3137 2 8 2C4.68629 2 2 4.68629 2 8C2 11.3137 4.68629 14 8 14ZM6.193 4.696C6.655 4.223 7.293 3.992 8.107 3.992C8.811 3.992 9.383 4.179 9.823 4.575C10.263 4.96 10.483 5.488 10.483 6.148C10.483 6.687 10.34 7.138 10.065 7.49C9.966 7.611 9.658 7.897 9.141 8.348C8.932 8.524 8.778 8.722 8.679 8.92C8.558 9.14 8.503 9.382 8.503 9.646V9.733C8.503 9.78823 8.45823 9.833 8.403 9.833H7.426C7.37077 9.833 7.326 9.78823 7.326 9.733V9.646C7.326 9.239 7.392 8.887 7.546 8.601C7.689 8.293 8.107 7.842 8.789 7.237L8.976 7.028C9.174 6.775 9.284 6.511 9.284 6.225C9.284 5.84 9.174 5.543 8.965 5.323C8.745 5.103 8.426 4.993 8.03 4.993C7.535 4.993 7.172 5.147 6.952 5.466C6.76786 5.71152 6.66935 6.05217 6.65646 6.48796C6.65482 6.54316 6.61023 6.588 6.555 6.588H5.6C5.54477 6.588 5.49986 6.54311 5.50122 6.4879C5.51978 5.7327 5.75038 5.13862 6.193 4.696ZM7.337 10.647C7.491 10.493 7.689 10.427 7.909 10.427C8.14 10.427 8.338 10.493 8.492 10.647C8.646 10.79 8.723 10.977 8.723 11.208C8.723 11.439 8.635 11.626 8.481 11.78C8.327 11.923 8.129 12 7.909 12C7.689 12 7.491 11.923 7.337 11.769C7.183 11.615 7.106 11.428 7.106 11.208C7.106 10.977 7.183 10.79 7.337 10.647Z" fill="#333334"/>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

Loading…
Cancel
Save