Browse Source

REPORT-80693 - 数据脱敏二期(报表)

【问题原因】rt
【改动思路】详见https://kms.fineres.com/pages/viewpage.action?pageId=550539157
【review建议】文档忘记提交评审了,review的时候帮忙打个分,感谢
feature/x
Yvan-欧阳帆 2 years ago
parent
commit
b08e6be68d
  1. 13
      designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java
  2. 2
      designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java
  3. 51
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java
  4. 26
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java
  5. 3
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleChoosePane.java
  6. 2
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleDebugPane.java
  7. 10
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/rule/DesensitizationRuleEditPane.java
  8. 12
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java
  9. 89
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java
  10. 8
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java

13
designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTableModel.java

@ -116,6 +116,19 @@ public class PreviewTableModel extends AbstractTableModel {
} }
} }
/**
* 根据列名获取列序号当返回-1时代表异常异常会被忽略不打印日志或给出前台提示
* @param columnName
* @return
*/
public int getColumnIndexWithExceptionIngore(String columnName) {
try {
return dataModel.getColumnIndex(columnName);
} catch (TableDataException ingore) {
return -1;
}
}
public int getRowCount() { public int getRowCount() {
try { try {
return this.dataModel.getRowCount(); return this.dataModel.getRowCount();

2
designer-base/src/main/java/com/fr/design/data/datapane/preview/PreviewTablePane.java

@ -776,6 +776,6 @@ public class PreviewTablePane extends BasicPane {
*/ */
private boolean isDesensitizeOpened() { private boolean isDesensitizeOpened() {
return tableData instanceof DesensitizationTableData && return tableData instanceof DesensitizationTableData &&
((DesensitizationTableData) tableData).isDesensitizeOpen(); ((DesensitizationTableData) tableData).getDesensitizationConfig().isDesensitizeOpened();
} }
} }

51
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java

@ -3,7 +3,7 @@ package com.fr.design.data.datapane.preview.desensitization;
import com.fr.base.TableData; import com.fr.base.TableData;
import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.DesensitizationTableData;
import com.fr.data.desensitize.base.TableDataDesensitizationBean; import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.data.desensitize.manage.DesensitizationManager; import com.fr.data.desensitize.manage.DesensitizationManager;
import com.fr.data.desensitize.util.DesentizationUtils; import com.fr.data.desensitize.util.DesentizationUtils;
import com.fr.decision.webservice.bean.user.DepartmentPostBean; import com.fr.decision.webservice.bean.user.DepartmentPostBean;
@ -14,12 +14,10 @@ import com.fr.decision.webservice.v10.user.PositionService;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.preview.PreviewTableModel; import com.fr.design.data.datapane.preview.PreviewTableModel;
import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel; import com.fr.design.data.datapane.preview.desensitization.model.DesensitizedPreviewTableModel;
import com.fr.design.data.tabledata.wrapper.TableDataWrapper;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -57,14 +55,14 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
/** /**
* 判断数据集预览时是否需要脱敏这里不需要判断roleIds因为默认有权限编辑的人一定有权限看脱敏前后字段值 * 判断数据集预览时是否需要脱敏这里不需要判断roleIds因为默认有权限编辑的人一定有权限看脱敏前后字段值
* 只需要保证此数据集存在脱敏配置就行
* *
* @param tableData * @param tableData
* @return * @return
*/ */
public boolean needDesensitize(TableData tableData) { public boolean needDesensitize(TableData tableData) {
return tableData instanceof DesensitizationTableData && return tableData instanceof DesensitizationTableData &&
DesentizationUtils.isCollectionNotEmpty(((DesensitizationTableData) tableData).getDesensitizationBeans()) && DesentizationUtils.isCollectionNotEmpty(((DesensitizationTableData) tableData).getDesensitizationConfig().getDesensitizationItems());
((DesensitizationTableData) tableData).getDesensitizationBeans().stream().noneMatch(TableDataDesensitizationBean::invalid);
} }
/** /**
@ -75,25 +73,23 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
*/ */
public PreviewTableModel desensitizeTableModel(TableData tableData, PreviewTableModel model) { public PreviewTableModel desensitizeTableModel(TableData tableData, PreviewTableModel model) {
Map<Integer, TableDataDesensitizationBean> desensitizationBeanMap = new LinkedHashMap<>(); Map<Integer, TableDataDesensitizationItem> desensitizationItemMap = new LinkedHashMap<>();
// 获取此数据集的所有脱敏信息 // 获取此数据集的所有脱敏信息
Collection<TableDataDesensitizationBean> desensitizationBeans = ((DesensitizationTableData) tableData).getDesensitizationBeans(); Collection<TableDataDesensitizationItem> desensitizationItems = ((DesensitizationTableData) tableData).getDesensitizationConfig().getDesensitizationItems();
// 去除被禁用的规则 + 排序 if (DesentizationUtils.isCollectionNotEmpty(desensitizationItems)) {
List<TableDataDesensitizationBean> sortedBeans = desensitizationBeans // 先对脱敏配置项集合做过滤和排序处理
.stream() List<TableDataDesensitizationItem> items = desensitizationItems.stream()
.filter(bean -> bean.getDesensitizationRule().isEnable()) .filter(item -> item.getRule().isEnable() &&
.sorted(Comparator.comparingInt(TableDataDesensitizationBean::getColumnIndex)) matchColumnIndex(item, model) >= 0)
.collect(Collectors.toList()); .sorted(Comparator.comparingInt(item -> matchColumnIndex(item, model)))
int columnIndex = 0; .collect(Collectors.toList());
for (TableDataDesensitizationBean sortedBean : sortedBeans) { // 然后转换成Map
// 当map中已包含列序号时,代表对这一列设置了不同的脱敏规则,将key + 1 for (int i = 0; i < items.size(); i++) {
if (desensitizationBeanMap.containsKey(columnIndex)) { desensitizationItemMap.put(i, items.get(i));
columnIndex++;
} }
desensitizationBeanMap.put(columnIndex, sortedBean);
} }
// 包装TableModel // 包装TableModel
return new DesensitizedPreviewTableModel(model, desensitizationBeanMap); return new DesensitizedPreviewTableModel(model, desensitizationItemMap);
} }
/** /**
@ -104,16 +100,7 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
* @return * @return
*/ */
public List<String> getColumnNamesByTableData(TableData tableData) { public List<String> getColumnNamesByTableData(TableData tableData) {
List<Map<String, TableDataWrapper>> editingDataSet = DesignTableDataManager.getEditingDataSet(DesignTableDataManager.getEditingTableDataSource()); return DesignTableDataManager.getColumnNamesByTableData(tableData);
// 当前所有模板数据集Wrapper,不包括存储过程
Map<String, TableDataWrapper> templeteDataMap = editingDataSet.get(0);
// 当前所有模板数据集Wrapper,包括存储过程
Map<String, TableDataWrapper> dataWrapperMap = DesignTableDataManager.getAllDataSetIncludingProcedure(templeteDataMap);
// 找到匹配当前数据集名称的Wrapper
TableDataWrapper tableDataWrapper = dataWrapperMap.get(tableData.getName());
return tableDataWrapper == null ?
new ArrayList<>() :
tableDataWrapper.calculateColumnNameList();
} }
/** /**
@ -189,4 +176,8 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
public String mergeRoleId(String departmentId, String positionId) { public String mergeRoleId(String departmentId, String positionId) {
return departmentId + CONNECTOR + positionId; return departmentId + CONNECTOR + positionId;
} }
public int matchColumnIndex(TableDataDesensitizationItem desensitizationItem, PreviewTableModel previewModel) {
return previewModel.getColumnIndexWithExceptionIngore(desensitizationItem.getColumnName());
}
} }

26
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/model/DesensitizedPreviewTableModel.java

@ -1,10 +1,11 @@
package com.fr.design.data.datapane.preview.desensitization.model; package com.fr.design.data.datapane.preview.desensitization.model;
import com.fr.data.desensitize.base.TableDataDesensitizationBean; import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.data.desensitize.calculate.DesensitizationCalculator; import com.fr.data.desensitize.calculate.DesensitizationCalculator;
import com.fr.data.desensitize.rule.base.DesensitizationRule; import com.fr.data.desensitize.rule.base.DesensitizationRule;
import com.fr.design.data.datapane.preview.PreviewTableModel; import com.fr.design.data.datapane.preview.PreviewTableModel;
import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -26,20 +27,20 @@ public class DesensitizedPreviewTableModel extends PreviewTableModel {
/** /**
* 脱敏后新组装的TableModel中列序号 - 脱敏信息 对应的Map * 脱敏后新组装的TableModel中列序号 - 脱敏信息 对应的Map
*/ */
private Map<Integer, TableDataDesensitizationBean> desensitizationBeanMap; private Map<Integer, TableDataDesensitizationItem> desensitizationItemMap;
private boolean needDesensitize = false; private boolean needDesensitize = false;
public DesensitizedPreviewTableModel(PreviewTableModel previewTableModel, Map<Integer, TableDataDesensitizationBean> desensitizationBeanMap) { public DesensitizedPreviewTableModel(PreviewTableModel previewTableModel, Map<Integer, TableDataDesensitizationItem> desensitizationItemMap) {
this.previewTableModel = previewTableModel; this.previewTableModel = previewTableModel;
this.desensitizationBeanMap = desensitizationBeanMap; this.desensitizationItemMap = desensitizationItemMap;
} }
@Override @Override
public String getColumnName(int column) { public String getColumnName(int column) {
int originIndex = needDesensitize && Objects.nonNull(desensitizationBeanMap.get(column)) ? return needDesensitize ?
desensitizationBeanMap.get(column).getColumnIndex() : column; desensitizationItemMap.get(column).getColumnName() :
return previewTableModel.getColumnName(originIndex); previewTableModel.getColumnName(column);
} }
@Override @Override
@ -56,7 +57,7 @@ public class DesensitizedPreviewTableModel extends PreviewTableModel {
@Override @Override
public Object getValueAt(int rowIndex, int columnIndex) { public Object getValueAt(int rowIndex, int columnIndex) {
return needDesensitize && Objects.nonNull(desensitizationBeanMap.get(columnIndex)) ? return needDesensitize && Objects.nonNull(desensitizationItemMap.get(columnIndex)) ?
getDesensitizedValue(rowIndex, columnIndex) : getDesensitizedValue(rowIndex, columnIndex) :
previewTableModel.getValueAt(rowIndex, columnIndex); previewTableModel.getValueAt(rowIndex, columnIndex);
} }
@ -70,7 +71,7 @@ public class DesensitizedPreviewTableModel extends PreviewTableModel {
*/ */
private Object getDesensitizedValue(int rowIndex, int columnIndex) { private Object getDesensitizedValue(int rowIndex, int columnIndex) {
// 先通过columnIndex找到对应原TableModel的列序号 // 先通过columnIndex找到对应原TableModel的列序号
int originColumnIndex = desensitizationBeanMap.get(columnIndex).getColumnIndex(); int originColumnIndex = TableDataPreviewDesensitizeManager.getInstance().matchColumnIndex(desensitizationItemMap.get(columnIndex), previewTableModel);
// 获取原值 // 获取原值
Object value = previewTableModel.getValueAt(rowIndex, originColumnIndex); Object value = previewTableModel.getValueAt(rowIndex, originColumnIndex);
// 判空 // 判空
@ -91,9 +92,8 @@ public class DesensitizedPreviewTableModel extends PreviewTableModel {
* @return * @return
*/ */
private String desensitizeValue(String strValue, int columnIndex) { private String desensitizeValue(String strValue, int columnIndex) {
TableDataDesensitizationBean desensitizationBean = desensitizationBeanMap.get(columnIndex); DesensitizationRule rule = desensitizationItemMap.get(columnIndex).getRule();
DesensitizationRule desensitizationRule = desensitizationBean.getDesensitizationRule(); return DesensitizationCalculator.getInstance().desensitize(strValue, rule);
return DesensitizationCalculator.getInstance().desensitize(strValue, desensitizationRule);
} }
/** /**
@ -102,7 +102,7 @@ public class DesensitizedPreviewTableModel extends PreviewTableModel {
* @return * @return
*/ */
public int getDesensitizeColumnsCount() { public int getDesensitizeColumnsCount() {
return desensitizationBeanMap.size(); return desensitizationItemMap.size();
} }
/** /**

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

@ -305,6 +305,9 @@ public class DesensitizationRuleChoosePane extends JPanel {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// 获取当前选中规则 // 获取当前选中规则
DesensitizationRule selectedRule = getSelectedValue(); DesensitizationRule selectedRule = getSelectedValue();
if (selectedRule == null) {
return;
}
DesensitizationRuleDebugPane ruleDebugPane = new DesensitizationRuleDebugPane(selectedRule); DesensitizationRuleDebugPane ruleDebugPane = new DesensitizationRuleDebugPane(selectedRule);
BasicDialog ruleDebugDialog = ruleDebugPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), null, BasicDialog.DEFAULT); BasicDialog ruleDebugDialog = ruleDebugPane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), null, BasicDialog.DEFAULT);
ruleDebugDialog.setVisible(true); ruleDebugDialog.setVisible(true);

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

@ -52,7 +52,7 @@ public class DesensitizationRuleDebugPane extends BasicPane {
JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane();
panel.setBorder(BorderFactory.createEmptyBorder(20, 10, 0, 0)); panel.setBorder(BorderFactory.createEmptyBorder(20, 10, 0, 0));
UILabel desensitizationRule = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Algorithm")); UILabel desensitizationRule = new UILabel(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Algorithm"));
UILabel characterReplace = new UILabel(rule.getRuleType().getTypeName()); UILabel characterReplace = new UILabel(rule.getRuleType().getRuleTypeName());
UILabel description = new UILabel(DesensitizationRule.getDescription(rule)); UILabel description = new UILabel(DesensitizationRule.getDescription(rule));
JComponent[][] components = new JComponent[][]{ JComponent[][] components = new JComponent[][]{
{desensitizationRule, characterReplace}, {desensitizationRule, characterReplace},

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

@ -185,8 +185,8 @@ public class DesensitizationRuleEditPane extends BasicBeanPane<DesensitizationRu
characterAllReplacePane.add(allReplaceLabel); characterAllReplacePane.add(allReplaceLabel);
characterAllReplacePane.add(secondSymbolTextField); characterAllReplacePane.add(secondSymbolTextField);
ruleConditionPane.add(characterReplacePane, DesensitizationRuleType.CHARACTER_REPLACE.getTypeName()); ruleConditionPane.add(characterReplacePane, DesensitizationRuleType.CHARACTER_REPLACE.getRuleTypeName());
ruleConditionPane.add(characterAllReplacePane, DesensitizationRuleType.ALL_CHARACTERS_REPLACE.getTypeName()); ruleConditionPane.add(characterAllReplacePane, DesensitizationRuleType.ALL_CHARACTERS_REPLACE.getRuleTypeName());
// 初始化状态为字符替换 // 初始化状态为字符替换
switchRuleConditionPane(DesensitizationRuleType.CHARACTER_REPLACE); switchRuleConditionPane(DesensitizationRuleType.CHARACTER_REPLACE);
@ -200,14 +200,14 @@ public class DesensitizationRuleEditPane extends BasicBeanPane<DesensitizationRu
* @param ruleType * @param ruleType
*/ */
private void switchRuleConditionPane(DesensitizationRuleType ruleType) { private void switchRuleConditionPane(DesensitizationRuleType ruleType) {
this.cardLayout.show(ruleConditionPane, ruleType.getTypeName()); this.cardLayout.show(ruleConditionPane, ruleType.getRuleTypeName());
} }
/** /**
* 初始化规则类型下拉框 * 初始化规则类型下拉框
*/ */
private void initRuleTypeComboBox() { private void initRuleTypeComboBox() {
ruleTypeComboBox = new UIComboBox(Arrays.stream(DesensitizationRuleType.values()).map(DesensitizationRuleType::getTypeName).toArray()); ruleTypeComboBox = new UIComboBox(Arrays.stream(DesensitizationRuleType.values()).map(DesensitizationRuleType::getRuleTypeName).toArray());
ruleTypeComboBox.setSelectedIndex(0); ruleTypeComboBox.setSelectedIndex(0);
ruleTypeComboBox.registerChangeListener(new UIObserverListener() { ruleTypeComboBox.registerChangeListener(new UIObserverListener() {
@Override @Override
@ -253,7 +253,7 @@ public class DesensitizationRuleEditPane extends BasicBeanPane<DesensitizationRu
public void populateBean(DesensitizationRule ob) { public void populateBean(DesensitizationRule ob) {
this.rule = ob; this.rule = ob;
this.ruleNameTextField.setText(rule.getRuleName()); this.ruleNameTextField.setText(rule.getRuleName());
String typeName = rule.getRuleType().getTypeName(); String typeName = rule.getRuleType().getRuleTypeName();
this.ruleTypeComboBox.setSelectedItem(typeName); this.ruleTypeComboBox.setSelectedItem(typeName);
switch (DesensitizationRuleType.matchByTypeName(typeName)) { switch (DesensitizationRuleType.matchByTypeName(typeName)) {
case CHARACTER_REPLACE: case CHARACTER_REPLACE:

12
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationSettingPane.java

@ -1,7 +1,7 @@
package com.fr.design.data.datapane.preview.desensitization.view.setting; package com.fr.design.data.datapane.preview.desensitization.view.setting;
import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.DesensitizationTableData;
import com.fr.data.desensitize.base.TableDataDesensitizationBean; import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.BasicBeanPane;
import com.fr.design.data.datapane.preview.desensitization.view.common.DesensitizationOpenPane; import com.fr.design.data.datapane.preview.desensitization.view.common.DesensitizationOpenPane;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
@ -69,7 +69,7 @@ public class TableDataDesensitizationSettingPane extends BasicBeanPane<Desensiti
@Override @Override
public void populateBean(DesensitizationTableData tableData) { public void populateBean(DesensitizationTableData tableData) {
this.tableData = tableData; this.tableData = tableData;
this.desensitizationOpenPane.setDesensitizationOpened(tableData.isDesensitizeOpen()); this.desensitizationOpenPane.setDesensitizationOpened(tableData.getDesensitizationConfig().isDesensitizeOpened());
tableDataDesensitizationTablePane.populateDesensitizationSetting(tableData); tableDataDesensitizationTablePane.populateDesensitizationSetting(tableData);
} }
@ -84,15 +84,15 @@ public class TableDataDesensitizationSettingPane extends BasicBeanPane<Desensiti
* 保存脱敏启用状态 * 保存脱敏启用状态
*/ */
public void saveDesensitizeOpened() { public void saveDesensitizeOpened() {
tableData.setDesensitizeOpen(this.desensitizationOpenPane.isDesensitizationOpened()); tableData.getDesensitizationConfig().setDesensitizeOpened(this.desensitizationOpenPane.isDesensitizationOpened());
} }
/** /**
* 保存脱敏规则配置信息 * 保存脱敏规则配置信息
* *
* @param tableDataDesensitizationBeans * @param desensitizationItems
*/ */
public void saveDesensitizationBeans(List<TableDataDesensitizationBean> tableDataDesensitizationBeans) { public void saveDesensitizationBeans(List<TableDataDesensitizationItem> desensitizationItems) {
tableData.setDesensitizationBeans(tableDataDesensitizationBeans); tableData.getDesensitizationConfig().setDesensitizationItems(desensitizationItems);
} }
} }

89
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTableModel.java

@ -1,7 +1,7 @@
package com.fr.design.data.datapane.preview.desensitization.view.setting; package com.fr.design.data.datapane.preview.desensitization.view.setting;
import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.DesensitizationTableData;
import com.fr.data.desensitize.base.TableDataDesensitizationBean; import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.data.desensitize.rule.base.DesensitizationRule; import com.fr.data.desensitize.rule.base.DesensitizationRule;
import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager;
import com.fr.design.data.datapane.preview.desensitization.view.rule.DesensitizationRulePane; import com.fr.design.data.datapane.preview.desensitization.view.rule.DesensitizationRulePane;
@ -18,7 +18,6 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.collections.CollectionUtils;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import javax.swing.AbstractCellEditor; import javax.swing.AbstractCellEditor;
@ -33,6 +32,7 @@ import java.awt.Component;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -48,7 +48,7 @@ import java.util.Set;
* @version 11.0 * @version 11.0
* Created by Yvan on 2022/9/23 * Created by Yvan on 2022/9/23
*/ */
public class TableDataDesensitizationTableModel extends UITableModelAdapter<TableDataDesensitizationBean> { public class TableDataDesensitizationTableModel extends UITableModelAdapter<TableDataDesensitizationItem> {
private static final String APOSTROPHE = "..."; private static final String APOSTROPHE = "...";
@ -106,59 +106,32 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public Object getValueAt(int rowIndex, int columnIndex) { public Object getValueAt(int rowIndex, int columnIndex) {
TableDataDesensitizationBean desensitizationBean = this.getList().get(rowIndex); TableDataDesensitizationItem desensitizationItem = this.getList().get(rowIndex);
switch (columnIndex) { switch (columnIndex) {
case 0: case 0:
// 选中的数据集字段名称 // 选中的数据集字段名称
return getColumnNameValue(desensitizationBean); return desensitizationItem.getColumnName();
case 1: case 1:
// 脱敏规则名称 // 脱敏规则名称
return desensitizationBean.getDesensitizationRule().getRuleName(); return desensitizationItem.getRule().getRuleName();
case 2: case 2:
// 脱敏规则详情 // 脱敏规则详情
return DesensitizationRule.getDescription(desensitizationBean.getDesensitizationRule()); return DesensitizationRule.getDescription(desensitizationItem.getRule());
case 3: case 3:
// 生效用户组 // 生效用户组
return matchRoleNamesByIds(desensitizationBean.getRoleIds()); return matchRoleNamesByIds(desensitizationItem.getRoleIds());
default: default:
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
} }
/**
* 根据当前选中的Bean获取其对应的列名字段
*
* @param desensitizationBean
* @return
*/
private Object getColumnNameValue(TableDataDesensitizationBean desensitizationBean) {
// 内部列名list为空时直接返回空字符串
if (CollectionUtils.isEmpty(columnNames)) {
return StringUtils.EMPTY;
}
// bean的列字段index不对劲时,返回空字符串
return validColumnIndex(desensitizationBean.getColumnIndex()) ?
columnNames.get(desensitizationBean.getColumnIndex()) :
StringUtils.EMPTY;
}
/**
* 判断字段索引是否越界
*
* @param columnIndex
* @return
*/
private boolean validColumnIndex(int columnIndex) {
return columnIndex >= 0 && columnIndex < columnNames.size();
}
/** /**
* 通过id匹配此用户组对应的部门职位名称或者说自定义角色名称 * 通过id匹配此用户组对应的部门职位名称或者说自定义角色名称
* *
* @param roleIds * @param roleIds
* @return * @return
*/ */
private List<String> matchRoleNamesByIds(Set<String> roleIds) { private List<String> matchRoleNamesByIds(Collection<String> roleIds) {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
for (String roleId : roleIds) { for (String roleId : roleIds) {
if (roleMap != null && roleMap.containsKey(roleId)) { if (roleMap != null && roleMap.containsKey(roleId)) {
@ -184,7 +157,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
* @return * @return
*/ */
@Nullable @Nullable
private TableDataDesensitizationBean getCurrentSelectBean() { private TableDataDesensitizationItem getCurrentSelectBean() {
return table.getSelectedRow() == -1 ? return table.getSelectedRow() == -1 ?
null : null :
getList().get(table.getSelectedRow()); getList().get(table.getSelectedRow());
@ -203,9 +176,9 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public void editingStopped(ChangeEvent e) { public void editingStopped(ChangeEvent e) {
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean();
if (Objects.nonNull(desensitizationBean)) { if (Objects.nonNull(desensitizationItem)) {
desensitizationBean.setColumnIndex(columnNameComboBox.getSelectedIndex()); desensitizationItem.setColumnName(columnNames.get(columnNameComboBox.getSelectedIndex()));
fireTableDataChanged(); fireTableDataChanged();
} }
} }
@ -220,7 +193,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
columnNameComboBox.setSelectedIndex(getList().get(row).getColumnIndex()); columnNameComboBox.setSelectedItem(getList().get(row).getColumnName());
return columnNameComboBox; return columnNameComboBox;
} }
@ -232,7 +205,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
columnNameComboBox.setSelectedIndex(getList().get(row).getColumnIndex()); columnNameComboBox.setSelectedItem(getList().get(row).getColumnName());
return columnNameComboBox; return columnNameComboBox;
} }
} }
@ -263,9 +236,10 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public void doOk() { public void doOk() {
rule = rulePane.updateBean(); rule = rulePane.updateBean();
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean();
if (Objects.nonNull(desensitizationBean) && Objects.nonNull(rule)) { if (Objects.nonNull(desensitizationItem) && Objects.nonNull(rule)) {
desensitizationBean.setDesensitizationRule(rule); desensitizationItem.setRule(rule);
desensitizationItem.setRuleName(rule.getRuleName());
fireTableDataChanged(); fireTableDataChanged();
} }
rule = null; rule = null;
@ -296,9 +270,10 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public void editingStopped(ChangeEvent e) { public void editingStopped(ChangeEvent e) {
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean();
if (Objects.nonNull(desensitizationBean) && Objects.nonNull(rule)) { if (Objects.nonNull(desensitizationItem) && Objects.nonNull(rule)) {
desensitizationBean.setDesensitizationRule(rule); desensitizationItem.setRule(rule);
desensitizationItem.setRuleName(rule.getRuleName());
fireTableDataChanged(); fireTableDataChanged();
} }
} }
@ -307,7 +282,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
ruleNameTextField.setText(getList().get(row).getDesensitizationRule().getRuleName()); ruleNameTextField.setText(getList().get(row).getRule().getRuleName());
return choosePane; return choosePane;
} }
@ -343,7 +318,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
@Override @Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
refreshDescription(getList().get(row).getDesensitizationRule()); refreshDescription(getList().get(row).getRule());
return descriptionLabel; return descriptionLabel;
} }
@ -362,9 +337,9 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
this.addCellEditorListener(new CellEditorListener() { this.addCellEditorListener(new CellEditorListener() {
@Override @Override
public void editingStopped(ChangeEvent e) { public void editingStopped(ChangeEvent e) {
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean();
if (Objects.nonNull(desensitizationBean)) { if (Objects.nonNull(desensitizationItem)) {
desensitizationBean.setRoleIds(generateRolesIdsBySelectedValues()); desensitizationItem.setRoleIds(generateRolesIdsBySelectedValues());
fireTableDataChanged(); fireTableDataChanged();
} }
} }
@ -385,15 +360,15 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
/** /**
* 根据当前的规则配置信息生成选中的rolesMap用来展示 * 根据当前的规则配置信息生成选中的rolesMap用来展示
* *
* @param desensitizationBean * @param desensitizationItem
* @return * @return
*/ */
private Map<Object, Boolean> generateRolesCheckBoxSelectedValues(TableDataDesensitizationBean desensitizationBean) { private Map<Object, Boolean> generateRolesCheckBoxSelectedValues(TableDataDesensitizationItem desensitizationItem) {
Map<Object, Boolean> result = new HashMap<>(roleMap.size()); Map<Object, Boolean> result = new HashMap<>(roleMap.size());
for (Map.Entry<String, String> roleEntry : roleMap.entrySet()) { for (Map.Entry<String, String> roleEntry : roleMap.entrySet()) {
String roleId = roleEntry.getKey(); String roleId = roleEntry.getKey();
String roleName = roleEntry.getValue(); String roleName = roleEntry.getValue();
if (desensitizationBean.getRoleIds().contains(roleId)) { if (desensitizationItem.getRoleIds().contains(roleId)) {
result.put(roleName, true); result.put(roleName, true);
} else { } else {
result.put(roleName, false); result.put(roleName, false);
@ -444,7 +419,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
super.actionPerformed(e); super.actionPerformed(e);
// 添加一条空白数据 // 添加一条空白数据
addRow(TableDataDesensitizationBean.createEmyptBean()); addRow(TableDataDesensitizationItem.createDefault());
fireTableDataChanged(); fireTableDataChanged();
table.getSelectionModel().setSelectionInterval(table.getRowCount() - 1, table.getRowCount() - 1); table.getSelectionModel().setSelectionInterval(table.getRowCount() - 1, table.getRowCount() - 1);
} }

8
designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java

@ -1,7 +1,7 @@
package com.fr.design.data.datapane.preview.desensitization.view.setting; package com.fr.design.data.datapane.preview.desensitization.view.setting;
import com.fr.data.desensitize.base.DesensitizationTableData; import com.fr.data.desensitize.base.DesensitizationTableData;
import com.fr.data.desensitize.base.TableDataDesensitizationBean; import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.design.gui.itableeditorpane.UITableEditorPane; import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
@ -32,7 +32,7 @@ public class TableDataDesensitizationTablePane extends JPanel {
/** /**
* 脱敏信息Table * 脱敏信息Table
*/ */
private UITableEditorPane<TableDataDesensitizationBean> editorPane; private UITableEditorPane<TableDataDesensitizationItem> editorPane;
public TableDataDesensitizationTablePane(DesensitizationTableData tableData, Component parent) { public TableDataDesensitizationTablePane(DesensitizationTableData tableData, Component parent) {
this.tableData = tableData; this.tableData = tableData;
@ -54,13 +54,13 @@ public class TableDataDesensitizationTablePane extends JPanel {
*/ */
public void populateDesensitizationSetting(DesensitizationTableData tableData) { public void populateDesensitizationSetting(DesensitizationTableData tableData) {
this.tableData = tableData; this.tableData = tableData;
editorPane.populate(tableData.getDesensitizationBeans().toArray(new TableDataDesensitizationBean[0])); editorPane.populate(tableData.getDesensitizationConfig().getDesensitizationItems().toArray(new TableDataDesensitizationItem[0]));
} }
/** /**
* 获取当前对TableData的配置脱敏规则信息 * 获取当前对TableData的配置脱敏规则信息
*/ */
public List<TableDataDesensitizationBean> updateDesensitizationSetting() { public List<TableDataDesensitizationItem> updateDesensitizationSetting() {
return editorPane.update(); return editorPane.update();
} }
} }

Loading…
Cancel
Save