|
|
|
@ -4,12 +4,11 @@ import com.fr.data.desensitize.base.DesensitizationTableData;
|
|
|
|
|
import com.fr.data.desensitize.base.TableDataDesensitizationItem; |
|
|
|
|
import com.fr.data.desensitize.rule.DesensitizationRuleManager; |
|
|
|
|
import com.fr.data.desensitize.rule.base.DesensitizationRule; |
|
|
|
|
import com.fr.data.desensitize.rule.base.DesensitizationRuleSource; |
|
|
|
|
import com.fr.data.desensitize.rule.base.DesensitizationRuleStatus; |
|
|
|
|
import com.fr.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; |
|
|
|
|
import com.fr.design.data.datapane.preview.desensitization.view.rule.DesensitizationRulePane; |
|
|
|
|
import com.fr.design.dialog.BasicDialog; |
|
|
|
|
import com.fr.design.dialog.DialogActionAdapter; |
|
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.icombobox.UIComboBox; |
|
|
|
|
import com.fr.design.gui.icombocheckbox.UIComboCheckBox; |
|
|
|
@ -38,9 +37,11 @@ import java.awt.Color;
|
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Iterator; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.LinkedHashSet; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
@ -61,21 +62,24 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
|
|
|
|
|
private static final String COMMA = ","; |
|
|
|
|
|
|
|
|
|
private DesensitizationTableData tableData; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当前数据集的所有列名 |
|
|
|
|
*/ |
|
|
|
|
private List<String> columnNames; |
|
|
|
|
private List<String> columnNames = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* key为用户组唯一标识(id拼接),value为用户组名称 |
|
|
|
|
*/ |
|
|
|
|
private Map<String, String> roleMap; |
|
|
|
|
private Map<String, String> roleMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当前最新的所有规则 |
|
|
|
|
*/ |
|
|
|
|
private Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> latestRules = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
private Component parent; |
|
|
|
|
|
|
|
|
|
public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent) { |
|
|
|
|
public TableDataDesensitizationTableModel(DesensitizationTableData tableData, Component parent, List<String> columnNames, Map<String, String> roleMap, Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> latestRules) { |
|
|
|
|
// table相关
|
|
|
|
|
super(new String[]{ |
|
|
|
|
Toolkit.i18nText("Fine-Design_Report_Desensitization_Column"), |
|
|
|
@ -84,13 +88,18 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
Toolkit.i18nText("Fine-Design_Report_Desensitization_Effected_Roles"), |
|
|
|
|
Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"), |
|
|
|
|
}); |
|
|
|
|
// 一些数据相关
|
|
|
|
|
this.tableData = tableData; |
|
|
|
|
// 获取当前数据集的所有列名
|
|
|
|
|
this.columnNames = TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData); |
|
|
|
|
// 获取当前所有用户组
|
|
|
|
|
this.roleMap = TableDataPreviewDesensitizeManager.getInstance().getAllRoles(); |
|
|
|
|
this.parent = parent; |
|
|
|
|
this.columnNames = columnNames; |
|
|
|
|
this.roleMap = roleMap; |
|
|
|
|
this.latestRules = latestRules; |
|
|
|
|
|
|
|
|
|
initTable(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化Table |
|
|
|
|
*/ |
|
|
|
|
private void initTable() { |
|
|
|
|
this.setColumnClass(new Class[]{ |
|
|
|
|
// 列名选择
|
|
|
|
|
ColumnNamesComboBox.class, |
|
|
|
@ -103,11 +112,12 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
// 规则状态
|
|
|
|
|
DesensitizationRuleStatusPane.class |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.setDefaultEditor(ColumnNamesComboBox.class, new ColumnNamesComboBox()); |
|
|
|
|
ColumnNamesComboBox columnNamesComboBox = new ColumnNamesComboBox(); |
|
|
|
|
this.setDefaultEditor(ColumnNamesComboBox.class, columnNamesComboBox); |
|
|
|
|
this.setDefaultEditor(DesensitizationRuleChooser.class, new DesensitizationRuleChooser()); |
|
|
|
|
this.setDefaultEditor(DesensitizationRuleDescriptionPane.class, new DesensitizationRuleDescriptionPane()); |
|
|
|
|
this.setDefaultEditor(EffectedRolesChooser.class, new EffectedRolesChooser()); |
|
|
|
|
EffectedRolesChooser effectedRolesChooser = new EffectedRolesChooser(); |
|
|
|
|
this.setDefaultEditor(EffectedRolesChooser.class, effectedRolesChooser); |
|
|
|
|
this.setDefaultEditor(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); |
|
|
|
|
this.setDefaultRenderer(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); |
|
|
|
|
|
|
|
|
@ -210,7 +220,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
|
|
|
|
columnNameComboBox.setSelectedItem(getList().get(row).getColumnName()); |
|
|
|
@ -241,14 +250,14 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
private ActionListener chooseRuleListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
DesensitizationRulePane rulePane = new DesensitizationRulePane(); |
|
|
|
|
DesensitizationRulePane rulePane = new DesensitizationRulePane(latestRules); |
|
|
|
|
TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); |
|
|
|
|
int selectedRow = table.getSelectedRow(); |
|
|
|
|
BasicDialog ruleDialog = rulePane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() { |
|
|
|
|
@Override |
|
|
|
|
public void doOk() { |
|
|
|
|
DesensitizationRule rule = rulePane.updateBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationItem) && Objects.nonNull(rule)) { |
|
|
|
|
if (Objects.nonNull(desensitizationItem) && DesensitizationRule.valid(rule)) { |
|
|
|
|
desensitizationItem.setRule(rule); |
|
|
|
|
desensitizationItem.setRuleName(rule.getRuleName()); |
|
|
|
|
// 刷新规则名称、描述、状态
|
|
|
|
@ -434,7 +443,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
DesensitizationRule rule = currentItem.getRule(); |
|
|
|
|
if (needMarkRule(rule)) { |
|
|
|
|
// 非正常规则,根据规则状态展示不同提示文字
|
|
|
|
|
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule); |
|
|
|
|
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules); |
|
|
|
|
this.ruleStatusLabel.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal")); |
|
|
|
|
this.ruleStatusLabel.setToolTipText(ruleStatus.getDescription()); |
|
|
|
|
} else { |
|
|
|
@ -444,36 +453,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 标签点击后,处理原规则 |
|
|
|
|
*/ |
|
|
|
|
private void ruleStatusLabelClick(TableDataDesensitizationItem currentItem) { |
|
|
|
|
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(currentItem.getRule()); |
|
|
|
|
if (ruleStatus == DesensitizationRuleStatus.NORMAL) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// 点击Label后,弹窗提示
|
|
|
|
|
int option = FineJOptionPane.showConfirmDialog( |
|
|
|
|
parent, |
|
|
|
|
ruleStatus.getDescription(), |
|
|
|
|
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), |
|
|
|
|
FineJOptionPane.OK_CANCEL_OPTION, |
|
|
|
|
FineJOptionPane.INFORMATION_MESSAGE); |
|
|
|
|
if (option == FineJOptionPane.OK_OPTION && table.getSelectedRow() != -1) { |
|
|
|
|
int selectedRow = table.getSelectedRow(); |
|
|
|
|
// 点击确定后,根据规则状态对规则做处理
|
|
|
|
|
if (ruleStatus == DesensitizationRuleStatus.REMOVED || ruleStatus == DesensitizationRuleStatus.WRONG) { |
|
|
|
|
// 规则被删除或读取错误时,直接删掉
|
|
|
|
|
removeRow(selectedRow); |
|
|
|
|
} else if (ruleStatus == DesensitizationRuleStatus.MODIFIED) { |
|
|
|
|
// 规则被修改时,用新规则替换
|
|
|
|
|
DesensitizationRule lastedRule = DesensitizationRuleManager.getInstance().getLastedDesentizationRule(currentItem.getRule()); |
|
|
|
|
currentItem.setRule(lastedRule); |
|
|
|
|
setRowAt(currentItem, selectedRow); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
|
|
|
|
refreshRuleStatus(getList().get(row)); |
|
|
|
@ -537,13 +516,13 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
Iterator<TableDataDesensitizationItem> iterator = items.iterator(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
TableDataDesensitizationItem item = iterator.next(); |
|
|
|
|
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule()); |
|
|
|
|
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(item.getRule(), latestRules); |
|
|
|
|
if (ruleStatus == DesensitizationRuleStatus.REMOVED) { |
|
|
|
|
// 规则被移除,则删除整条脱敏Item
|
|
|
|
|
iterator.remove(); |
|
|
|
|
} else { |
|
|
|
|
// 规则被修改、禁用等,更新一下规则
|
|
|
|
|
item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule())); |
|
|
|
|
item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule(), latestRules)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fireTableDataChanged(); |
|
|
|
@ -624,7 +603,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
*/ |
|
|
|
|
private boolean needMarkRule(DesensitizationRule rule) { |
|
|
|
|
return !rule.equals(DesensitizationRule.createDefaultEmptyRule()) && |
|
|
|
|
DesensitizationRuleManager.getInstance().getRuleStatus(rule) != DesensitizationRuleStatus.NORMAL; |
|
|
|
|
DesensitizationRuleManager.getInstance().getRuleStatus(rule, latestRules) != DesensitizationRuleStatus.NORMAL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|