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