|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
package com.fr.design.data.datapane.preview.desensitization.view.setting; |
|
|
|
|
|
|
|
|
|
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.design.data.datapane.preview.desensitization.TableDataPreviewDesensitizeManager; |
|
|
|
|
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.TableLayoutHelper; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.collections.CollectionUtils; |
|
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
|
|
|
|
|
import javax.swing.AbstractCellEditor; |
|
|
|
@ -33,6 +32,7 @@ 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.LinkedHashSet; |
|
|
|
|
import java.util.List; |
|
|
|
@ -48,7 +48,7 @@ import java.util.Set;
|
|
|
|
|
* @version 11.0 |
|
|
|
|
* Created by Yvan on 2022/9/23 |
|
|
|
|
*/ |
|
|
|
|
public class TableDataDesensitizationTableModel extends UITableModelAdapter<TableDataDesensitizationBean> { |
|
|
|
|
public class TableDataDesensitizationTableModel extends UITableModelAdapter<TableDataDesensitizationItem> { |
|
|
|
|
|
|
|
|
|
private static final String APOSTROPHE = "..."; |
|
|
|
|
|
|
|
|
@ -106,59 +106,32 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Object getValueAt(int rowIndex, int columnIndex) { |
|
|
|
|
TableDataDesensitizationBean desensitizationBean = this.getList().get(rowIndex); |
|
|
|
|
TableDataDesensitizationItem desensitizationItem = this.getList().get(rowIndex); |
|
|
|
|
switch (columnIndex) { |
|
|
|
|
case 0: |
|
|
|
|
// 选中的数据集字段名称
|
|
|
|
|
return getColumnNameValue(desensitizationBean); |
|
|
|
|
return desensitizationItem.getColumnName(); |
|
|
|
|
case 1: |
|
|
|
|
// 脱敏规则名称
|
|
|
|
|
return desensitizationBean.getDesensitizationRule().getRuleName(); |
|
|
|
|
return desensitizationItem.getRule().getRuleName(); |
|
|
|
|
case 2: |
|
|
|
|
// 脱敏规则详情
|
|
|
|
|
return DesensitizationRule.getDescription(desensitizationBean.getDesensitizationRule()); |
|
|
|
|
return DesensitizationRule.getDescription(desensitizationItem.getRule()); |
|
|
|
|
case 3: |
|
|
|
|
// 生效用户组
|
|
|
|
|
return matchRoleNamesByIds(desensitizationBean.getRoleIds()); |
|
|
|
|
return matchRoleNamesByIds(desensitizationItem.getRoleIds()); |
|
|
|
|
default: |
|
|
|
|
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匹配此用户组对应的部门职位名称(或者说自定义角色名称) |
|
|
|
|
* |
|
|
|
|
* @param roleIds |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private List<String> matchRoleNamesByIds(Set<String> roleIds) { |
|
|
|
|
private List<String> matchRoleNamesByIds(Collection<String> roleIds) { |
|
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
|
for (String roleId : roleIds) { |
|
|
|
|
if (roleMap != null && roleMap.containsKey(roleId)) { |
|
|
|
@ -184,7 +157,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@Nullable |
|
|
|
|
private TableDataDesensitizationBean getCurrentSelectBean() { |
|
|
|
|
private TableDataDesensitizationItem getCurrentSelectBean() { |
|
|
|
|
return table.getSelectedRow() == -1 ? |
|
|
|
|
null : |
|
|
|
|
getList().get(table.getSelectedRow()); |
|
|
|
@ -203,9 +176,9 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
@Override |
|
|
|
|
public void editingStopped(ChangeEvent e) { |
|
|
|
|
|
|
|
|
|
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationBean)) { |
|
|
|
|
desensitizationBean.setColumnIndex(columnNameComboBox.getSelectedIndex()); |
|
|
|
|
TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationItem)) { |
|
|
|
|
desensitizationItem.setColumnName(columnNames.get(columnNameComboBox.getSelectedIndex())); |
|
|
|
|
fireTableDataChanged(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -220,7 +193,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -232,7 +205,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -263,9 +236,10 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
@Override |
|
|
|
|
public void doOk() { |
|
|
|
|
rule = rulePane.updateBean(); |
|
|
|
|
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationBean) && Objects.nonNull(rule)) { |
|
|
|
|
desensitizationBean.setDesensitizationRule(rule); |
|
|
|
|
TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationItem) && Objects.nonNull(rule)) { |
|
|
|
|
desensitizationItem.setRule(rule); |
|
|
|
|
desensitizationItem.setRuleName(rule.getRuleName()); |
|
|
|
|
fireTableDataChanged(); |
|
|
|
|
} |
|
|
|
|
rule = null; |
|
|
|
@ -296,9 +270,10 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void editingStopped(ChangeEvent e) { |
|
|
|
|
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationBean) && Objects.nonNull(rule)) { |
|
|
|
|
desensitizationBean.setDesensitizationRule(rule); |
|
|
|
|
TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationItem) && Objects.nonNull(rule)) { |
|
|
|
|
desensitizationItem.setRule(rule); |
|
|
|
|
desensitizationItem.setRuleName(rule.getRuleName()); |
|
|
|
|
fireTableDataChanged(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -307,7 +282,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -343,7 +318,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -362,9 +337,9 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
this.addCellEditorListener(new CellEditorListener() { |
|
|
|
|
@Override |
|
|
|
|
public void editingStopped(ChangeEvent e) { |
|
|
|
|
TableDataDesensitizationBean desensitizationBean = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationBean)) { |
|
|
|
|
desensitizationBean.setRoleIds(generateRolesIdsBySelectedValues()); |
|
|
|
|
TableDataDesensitizationItem desensitizationItem = getCurrentSelectBean(); |
|
|
|
|
if (Objects.nonNull(desensitizationItem)) { |
|
|
|
|
desensitizationItem.setRoleIds(generateRolesIdsBySelectedValues()); |
|
|
|
|
fireTableDataChanged(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -385,15 +360,15 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
/** |
|
|
|
|
* 根据当前的规则配置信息,生成选中的rolesMap用来展示 |
|
|
|
|
* |
|
|
|
|
* @param desensitizationBean |
|
|
|
|
* @param desensitizationItem |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Map<Object, Boolean> generateRolesCheckBoxSelectedValues(TableDataDesensitizationBean desensitizationBean) { |
|
|
|
|
private Map<Object, Boolean> generateRolesCheckBoxSelectedValues(TableDataDesensitizationItem desensitizationItem) { |
|
|
|
|
Map<Object, Boolean> result = new HashMap<>(roleMap.size()); |
|
|
|
|
for (Map.Entry<String, String> roleEntry : roleMap.entrySet()) { |
|
|
|
|
String roleId = roleEntry.getKey(); |
|
|
|
|
String roleName = roleEntry.getValue(); |
|
|
|
|
if (desensitizationBean.getRoleIds().contains(roleId)) { |
|
|
|
|
if (desensitizationItem.getRoleIds().contains(roleId)) { |
|
|
|
|
result.put(roleName, true); |
|
|
|
|
} else { |
|
|
|
|
result.put(roleName, false); |
|
|
|
@ -444,7 +419,7 @@ public class TableDataDesensitizationTableModel extends UITableModelAdapter<Tabl
|
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
super.actionPerformed(e); |
|
|
|
|
// 添加一条空白数据
|
|
|
|
|
addRow(TableDataDesensitizationBean.createEmyptBean()); |
|
|
|
|
addRow(TableDataDesensitizationItem.createDefault()); |
|
|
|
|
fireTableDataChanged(); |
|
|
|
|
table.getSelectionModel().setSelectionInterval(table.getRowCount() - 1, table.getRowCount() - 1); |
|
|
|
|
} |
|
|
|
|