Browse Source

Pull request #11341: REPORT-83849 && REPORT-89327

Merge in DESIGN/design from ~LEO.QIN/design:release/11.0 to release/11.0

* commit '2e97b4532853134885d9f5b5fc2867462e044109':
  REPORT-83849 && REPORT-89327 修改代码质量
  REPORT-83849 && REPORT-89327 【问题原因】未设计远程调用接口;脱敏计算获取的部门id api接口有误,未拼接部分id与职位id 【改动思路】增加远程调用接口;修改获取部分id 的api接口
release/11.0
Leo.Qin-覃宇攀 2 years ago
parent
commit
5828bb4304
  1. 74
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/TableDataPreviewDesensitizeManager.java
  2. 4
      designer-base/src/main/java/com/fr/design/data/datapane/preview/desensitization/view/setting/TableDataDesensitizationTablePane.java
  3. 6
      designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/desensitization/model/DesensitizationCellEditor.java
  4. 55
      designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/desensitization/model/DesensitizationCellPane.java
  5. 47
      designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/desensitization/model/UpdateDataWorker.java

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

@ -124,80 +124,6 @@ public class TableDataPreviewDesensitizeManager implements DesensitizationManage
return Collections.EMPTY_LIST;
}
/**
* 这个api会返回 部门职位 + 自定义角色 的Map
* 其中 key为 "pid" + "_" + "id"value为 "ptext" + "text"
*
* @return
*/
public Map<String, String> getAllRoles() {
Map<String, String> rolesMap = new LinkedHashMap<>();
// 处理部门职位相关的用户组
addDepartmentAndPositionRoles2Map(rolesMap);
// 处理自定义角色相关的用户组
addCustomRoles2Map(rolesMap);
return rolesMap;
}
/**
* 获取所有的部门职位按照 key为 "pid" + "_" + "id"value为 "ptext" + "text"的格式添加到参数Map中
*
* @param rolesMap
*/
private void addDepartmentAndPositionRoles2Map(Map<String, String> rolesMap) {
try {
List<DepartmentPostBean> postBeans = PositionService.getInstance().getDepartmentPostNameList();
for (DepartmentPostBean postBean : postBeans) {
String department = postBean.getpText();
String position = postBean.getText();
String departmentId = postBean.getpId();
String positionId = postBean.getId();
if (!ComparatorUtils.equals(DecisionServiceConstants.DECISION_DEP_ROOT, postBean.getId()) && StringUtils.isNotEmpty(position)) {
// 只添加部门和职位同时存在的
rolesMap.put(mergeRoleId(departmentId, positionId), mergeRoleText(department, position));
}
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[Desensitization] failed to add department and position roles to map for {}", e.getMessage());
}
}
/**
* 获取所有的自定义角色按照 id - name添加到参数map里
*
* @param rolesMap
*/
private void addCustomRoles2Map(Map<String, String> rolesMap) {
try {
List<RoleBean> allCustomRole = CustomRoleService.getInstance().getAllCustomRoleNameList(null);
allCustomRole.forEach(roleBean -> rolesMap.put(roleBean.getId(), roleBean.getText()));
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e, "[Desensitization] failed to add custom role to map for {}", e.getMessage());
}
}
/**
* 合并部门 + 职位的名称
*
* @param departmentName
* @param positionName
* @return
*/
private String mergeRoleText(String departmentName, String positionName) {
return departmentName + positionName;
}
/**
* 合并部门 + 职位的id
*
* @param departmentId
* @param positionId
* @return
*/
private String mergeRoleId(String departmentId, String positionId) {
return departmentId + CONNECTOR + positionId;
}
/**
* 根据列名从PreviewTableModel中匹配列序号如果返回-1代表未匹配到
* @param desensitizationItem

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

@ -1,5 +1,6 @@
package com.fr.design.data.datapane.preview.desensitization.view.setting;
import com.fr.base.operator.org.OrganizationOperator;
import com.fr.data.desensitize.base.DesensitizationTableData;
import com.fr.data.desensitize.base.TableDataDesensitizationItem;
import com.fr.data.desensitize.rule.DesensitizationRuleManager;
@ -10,6 +11,7 @@ import com.fr.design.data.tabledata.tabledatapane.loading.TipsPane;
import com.fr.design.gui.itableeditorpane.UITableEditorPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.workspace.WorkContext;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
@ -89,7 +91,7 @@ public class TableDataDesensitizationTablePane extends JPanel {
// 获取当前数据集的所有列名
columnNames.addAll(TableDataPreviewDesensitizeManager.getInstance().getColumnNamesByTableData(tableData));
// 获取当前所有用户组
roleMap.putAll(TableDataPreviewDesensitizeManager.getInstance().getAllRoles());
roleMap.putAll(WorkContext.getCurrent().get(OrganizationOperator.class).getAllRoles4Desensitization());
// 获取当前最新的所有规则
latestRules.putAll(DesensitizationRuleManager.getInstance().getAllRules());
return null;

6
designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/desensitization/model/DesensitizationCellEditor.java

@ -5,10 +5,12 @@ import com.fr.report.cell.desensitization.CellDesensitizationBean;
import javax.swing.AbstractCellEditor;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.SwingWorker;
import javax.swing.border.LineBorder;
import javax.swing.table.TableCellEditor;
import java.awt.Color;
import java.awt.Component;
import java.util.Map;
/**
* 脱敏规则设置cellEditor
@ -23,9 +25,11 @@ public class DesensitizationCellEditor extends AbstractCellEditor implements Tab
editPane = new DesensitizationCellPane(parent, model);
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
// 点击脱敏设置时刷新用户组信息和所有规则
SwingWorker<Map<String, Object>, Void> updateDateWorker = new UpdateDataWorker();
updateDateWorker.execute();
editPane.populate((CellDesensitizationBean) value, row);

55
designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/desensitization/model/DesensitizationCellPane.java

@ -1,15 +1,16 @@
package com.fr.design.mainframe.cell.settingpane.desensitization.model;
import com.fr.base.operator.org.OrganizationOperator;
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.beans.BasicBeanPane;
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.event.UIObserverListener;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombocheckbox.UIComboCheckBox;
import com.fr.design.gui.ilable.UILabel;
@ -19,9 +20,12 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.layout.VerticalFlowLayout;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.JTemplateActionListener;
import com.fr.report.cell.desensitization.CellDesensitizationBean;
import com.fr.stable.StringUtils;
import com.fr.third.org.apache.commons.collections4.map.HashedMap;
import com.fr.workspace.WorkContext;
import javax.swing.JComponent;
import javax.swing.JPanel;
@ -39,6 +43,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
/**
* 单元格脱敏规则设置面板
@ -56,10 +61,11 @@ public class DesensitizationCellPane extends BasicBeanPane {
private UITextField ruleTextField;
private UIComboCheckBox rolesComboBox;
private static final String APOSTROPHE = "...";
private Map<String, String> roleMap;
private DesensitizationRule rule;
private static Map<String, String> roleMap;
private static Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> latestRules;
private CellDesensitizationTableModel model;
private static final CellDesensitizationBean EMPTY_BEAN = CellDesensitizationBean.createEmptyBean();
DesensitizationCellPane(Component parent, CellDesensitizationTableModel model) {
@ -141,7 +147,6 @@ public class DesensitizationCellPane extends BasicBeanPane {
public void actionPerformed(ActionEvent e) {
CellDesensitizationBean selectBean = model.getSelectedValue();
latestRules = DesensitizationRuleManager.getInstance().getAllRules();
DesensitizationRulePane rulePane = new DesensitizationRulePane(latestRules);
BasicDialog ruleDialog = rulePane.showWindowWithCustomSize(SwingUtilities.getWindowAncestor(parent), new DialogActionAdapter() {
@ -150,10 +155,6 @@ public class DesensitizationCellPane extends BasicBeanPane {
rule = rulePane.updateBean();
if (Objects.nonNull(selectBean) && Objects.nonNull(rule) && !selectBean.getDesensitizationRule().equals(rule)) {
selectBean.setDesensitizationRule(rule);
ruleTextField.setText(rule.getRuleName());
// 非正常状态需要颜色修改为红色
refreshRuleState(selectBean);
model.fireTableDataChanged();
}
@ -205,32 +206,41 @@ public class DesensitizationCellPane extends BasicBeanPane {
refreshRoles();
String ruleName = value.getDesensitizationRule().getRuleName();
ruleTextField.setText(ruleName);
refreshRuleText(value);
// 非正常状态需要颜色修改为红色
refreshRuleState(value);
Map<Object, Boolean> map = generateRolesCheckBoxSelectedValues(value);
rolesComboBox.setSelectedValues(map);
label.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Setting") + row);
label.setText(Toolkit.i18nText("Fine-Design_Report_Desensitization_Setting") + (row + 1));
}
/**
* 刷新用户组信息
* 刷新规则文本
*
* @param value
*/
private void refreshRoles() {
Map<String, String> roles = TableDataPreviewDesensitizeManager.getInstance().getAllRoles();
if (!roleMap.equals(roles)) {
roleMap = roles;
rolesComboBox.refreshCombo(roles.values().toArray());
private void refreshRuleText(CellDesensitizationBean value) {
ruleTextField.setText(StringUtils.EMPTY);
DesensitizationRule desensitizationRule = value.getDesensitizationRule();
if (desensitizationRule != null) {
String ruleName = desensitizationRule.getRuleName();
ruleTextField.setText(ruleName);
}
}
/**
* combobox组件刷新用户组信息
*/
private void refreshRoles() {
rolesComboBox.clearText();
rolesComboBox.refreshCombo(roleMap.values().toArray());
}
private void refreshRuleState(CellDesensitizationBean value) {
DesensitizationRuleStatus ruleStatus = DesensitizationRuleManager.getInstance().getRuleStatus(value.getDesensitizationRule(), latestRules);
if (value.equals(CellDesensitizationBean.createEmptyBean())) {
if (EMPTY_BEAN.equals(value)) {
ruleTextField.setForeground(Color.GRAY);
} else if (ruleStatus != DesensitizationRuleStatus.NORMAL) {
ruleTextField.setForeground(Color.RED);
@ -310,4 +320,13 @@ public class DesensitizationCellPane extends BasicBeanPane {
return omitText.equals(StringUtils.EMPTY) ? text : omitText;
}
}
/**
* 更新用户组和平台规则
*/
public static void updateData(Map<String, String> roleMap, Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> latestRules) {
DesensitizationCellPane.roleMap = roleMap;
DesensitizationCellPane.latestRules = latestRules;
}
}

47
designer-realize/src/main/java/com/fr/design/mainframe/cell/settingpane/desensitization/model/UpdateDataWorker.java

@ -0,0 +1,47 @@
package com.fr.design.mainframe.cell.settingpane.desensitization.model;
import com.fr.base.operator.org.OrganizationOperator;
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.workspace.WorkContext;
import javax.swing.SwingWorker;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
/**
* 刷新脱敏设置全局 roles rules SwingWorker
*
* @author Leo.Qin
* @version 11.0
* Created by Leo.Qin on 2023/1/5
*/
public class UpdateDataWorker extends SwingWorker<Map<String, Object>, Void> {
private final String ROLE_KEY = "Roles";
private final String RULE_KEY = "Rules";
@Override
protected Map<String, Object> doInBackground() {
Map<String, Object> result = new HashMap<>();
Map<String, String> allRoles = WorkContext.getCurrent().get(OrganizationOperator.class).getAllRoles4Desensitization();
Map<DesensitizationRuleSource, Map<String, DesensitizationRule>> allRules = DesensitizationRuleManager.getInstance().getAllRules();
result.put(ROLE_KEY, allRoles);
result.put(RULE_KEY, allRules);
return result;
}
@Override
protected void done() {
try {
Map<String, Object> result = get();
DesensitizationCellPane.updateData((Map<String, String>) result.get(ROLE_KEY), (Map<DesensitizationRuleSource, Map<String, DesensitizationRule>>) result.get(RULE_KEY));
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
}
Loading…
Cancel
Save