|
|
|
@ -4,8 +4,8 @@ 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; |
|
|
|
@ -20,7 +20,6 @@ import com.fr.design.i18n.Toolkit;
|
|
|
|
|
import com.fr.design.layout.FRGUIPaneFactory; |
|
|
|
|
import com.fr.design.layout.TableLayout; |
|
|
|
|
import com.fr.design.layout.TableLayoutHelper; |
|
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
|
|
|
|
@ -29,7 +28,6 @@ import javax.swing.JComponent;
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JTable; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.SwingWorker; |
|
|
|
|
import javax.swing.event.CellEditorListener; |
|
|
|
|
import javax.swing.event.ChangeEvent; |
|
|
|
|
import javax.swing.table.TableCellEditor; |
|
|
|
@ -72,11 +70,16 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
/** |
|
|
|
|
* key为用户组唯一标识(id拼接),value为用户组名称 |
|
|
|
|
*/ |
|
|
|
|
private final Map<String, String> roleMap = new LinkedHashMap<>(); |
|
|
|
|
private Map<String, String> roleMap = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 当前最新的所有规则 |
|
|
|
|
*/ |
|
|
|
|
private Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> lastedRules = 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>> lastedRules) { |
|
|
|
|
// table相关
|
|
|
|
|
super(new String[]{ |
|
|
|
|
Toolkit.i18nText("Fine-Design_Report_Desensitization_Column"), |
|
|
|
@ -86,6 +89,17 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status"), |
|
|
|
|
}); |
|
|
|
|
this.parent = parent; |
|
|
|
|
this.columnNames = columnNames; |
|
|
|
|
this.roleMap = roleMap; |
|
|
|
|
this.lastedRules = lastedRules; |
|
|
|
|
|
|
|
|
|
initTable(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化Table |
|
|
|
|
*/ |
|
|
|
|
private void initTable() { |
|
|
|
|
this.setColumnClass(new Class[]{ |
|
|
|
|
// 列名选择
|
|
|
|
|
ColumnNamesComboBox.class, |
|
|
|
@ -108,31 +122,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
this.setDefaultRenderer(DesensitizationRuleStatusPane.class, new DesensitizationRuleStatusPane()); |
|
|
|
|
|
|
|
|
|
this.createTable().getColumnModel().getColumn(TableSequences.DesensitizationRuleStatus.getNum()).setMaxWidth(60); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new SwingWorker<Void, Void>() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected Void doInBackground() throws Exception { |
|
|
|
|
// 获取当前数据集的所有列名
|
|
|
|
|
columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData)); |
|
|
|
|
// 获取当前所有用户组
|
|
|
|
|
roleMap.putAll(TableDataPreviewDesensitizeManager.getInstance().getAllRoles()); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void done() { |
|
|
|
|
try { |
|
|
|
|
// 更新列名选择框和生效用户组选择框
|
|
|
|
|
columnNamesComboBox.refresh(); |
|
|
|
|
effectedRolesChooser.refresh(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, "[Desensitization] get column names or all roles failed for {}", e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.execute(); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -231,14 +220,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询到数据集列名后,更新到下拉框中 |
|
|
|
|
*/ |
|
|
|
|
public void refresh() { |
|
|
|
|
columnNameComboBox.refreshBoxItems(columnNames); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
|
|
|
|
columnNameComboBox.setSelectedItem(getList().get(row).getColumnName()); |
|
|
|
@ -269,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(lastedRules); |
|
|
|
|
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()); |
|
|
|
|
// 刷新规则名称、描述、状态
|
|
|
|
@ -356,7 +337,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
private UIComboCheckBox rolesCheckBox; |
|
|
|
|
|
|
|
|
|
EffectedRolesChooser() { |
|
|
|
|
this.rolesCheckBox = new UIComboCheckBox(new String[]{}, true) { |
|
|
|
|
this.rolesCheckBox = new UIComboCheckBox(roleMap.values().toArray(), true) { |
|
|
|
|
@Override |
|
|
|
|
protected void setLayoutAndAddComponents() { |
|
|
|
|
// 使用BorderLayout,否则默认使用的FlowLayout会让整个下拉选框使用最小Size,然后TableCell这边会出现空白
|
|
|
|
@ -390,13 +371,6 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 查询到所有用户组后,更新到下拉框中 |
|
|
|
|
*/ |
|
|
|
|
public void refresh() { |
|
|
|
|
rolesCheckBox.refreshCombo(roleMap.values().toArray()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { |
|
|
|
|
rolesCheckBox.setSelectedValues(generateRolesCheckBoxSelectedValues(getList().get(row))); |
|
|
|
@ -469,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, lastedRules); |
|
|
|
|
this.ruleStatusLabel.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Rule_Status_Abnormal")); |
|
|
|
|
this.ruleStatusLabel.setToolTipText(ruleStatus.getDescription()); |
|
|
|
|
} else { |
|
|
|
@ -542,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(), lastedRules); |
|
|
|
|
if (ruleStatus == DesensitizationRuleStatus.REMOVED) { |
|
|
|
|
// 规则被移除,则删除整条脱敏Item
|
|
|
|
|
iterator.remove(); |
|
|
|
|
} else { |
|
|
|
|
// 规则被修改、禁用等,更新一下规则
|
|
|
|
|
item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule())); |
|
|
|
|
item.setRule(DesensitizationRuleManager.getInstance().getLastedDesentizationRule(item.getRule(), lastedRules)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
fireTableDataChanged(); |
|
|
|
|