From 9a5e08b4717a11de2d536c9d721f86f266b44ab1 Mon Sep 17 00:00:00 2001 From: hades Date: Tue, 27 Oct 2020 11:41:05 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-40646=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=AF=B9=E6=8E=A5=E5=B9=B3=E5=8F=B0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 52 ++++-- .../design/dialog/link/MessageWithLink.java | 55 +++++++ .../main/java/com/fr/env/RemoteEnvPane.java | 19 ++- .../java/com/fr/env/RemoteWorkspaceURL.java | 2 + .../java/com/fr/env/TestConnectionResult.java | 155 +++++++++++++++++- 5 files changed, 266 insertions(+), 17 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index ce495cdb97..382709c92f 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -5,6 +5,7 @@ import com.fr.design.data.DesignTableDataManager; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.dialog.link.MessageWithLink; import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; @@ -18,7 +19,10 @@ import com.fr.design.mainframe.JTemplate; import com.fr.design.utils.DesignUtils; import com.fr.env.CheckServiceDialog; import com.fr.env.EnvListPane; +import com.fr.env.RemoteWorkspaceURL; +import com.fr.env.TestConnectionResult; import com.fr.exit.DesignerExiter; +import com.fr.general.ComparatorUtils; import com.fr.general.GeneralUtils; import com.fr.invoke.Reflect; import com.fr.json.JSONArray; @@ -40,6 +44,7 @@ import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.base.FineObjectPool; import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; import com.fr.workspace.engine.exception.WorkspaceAuthException; +import com.fr.workspace.engine.exception.WorkspaceCheckException; import com.fr.workspace.engine.exception.WorkspaceConnectionException; import com.fr.workspace.engine.rpc.WorkspaceProxyPool; @@ -145,21 +150,28 @@ public class EnvChangeEntrance { strategy.showTip(new PopTip() { @Override public void show() { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon")); } }); return false; + } catch (WorkspaceCheckException e) { + handleWorkspaceCheckException(e, strategy, connectionInfo); + return false; } catch (Exception exception) { - FineLoggerFactory.getLogger().error(exception.getMessage(), exception); - strategy.showTip(new PopTip() { - @Override - public void show() { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); - } - }); - + if (exception.getCause() instanceof WorkspaceCheckException) { + handleWorkspaceCheckException((WorkspaceCheckException) exception.getCause(), strategy, connectionInfo); + } else { + FineLoggerFactory.getLogger().error(exception.getMessage(), exception); + strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon"))); + } return false; } TemplateTreePane.getInstance().refreshDockingView(); @@ -170,6 +182,24 @@ public class EnvChangeEntrance { return true; } + private void handleWorkspaceCheckException(WorkspaceCheckException e, PopTipStrategy strategy, WorkspaceConnectionInfo info) { + TestConnectionResult result = TestConnectionResult.parseByException(e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); + if (ComparatorUtils.equals(result, TestConnectionResult.AUTH_FAILED)) { + strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon"))); + } else { + strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), info.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon"))); + } + } + /** * 这个功能留着,可能会加回来,先做注释处理 * 切换远程环境之前,进行版本检测,当版本不一致的时候,提示。 diff --git a/designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java b/designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java new file mode 100644 index 0000000000..8a1f55cbdf --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java @@ -0,0 +1,55 @@ +package com.fr.design.dialog.link; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StringUtils; +import java.awt.Color; +import java.awt.Desktop; +import java.awt.Font; +import java.net.URI; +import javax.swing.JEditorPane; +import javax.swing.event.HyperlinkEvent; + +/** + * 用来构建JOptionPane带超链的消息提示 + * + * @author hades + * @version 10.0 + * Created by hades on 2020/10/23 + */ +public class MessageWithLink extends JEditorPane { + + public MessageWithLink(String message, String linkName, String link) { + super("text/html", "" + message + "" + linkName + "" + ""); + addHyperlinkListener(e -> { + if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { + try { + Desktop.getDesktop().browse(URI.create(link)); + } catch (Exception exception) { + FineLoggerFactory.getLogger().error(exception.getMessage(), exception); + } + } + }); + setEditable(false); + setBorder(null); + } + + public MessageWithLink(String linkName, String link ) { + this(StringUtils.EMPTY, linkName, link); + } + + private static StringBuilder getStyle() { + // 构建和相同风格样式 + UILabel label = new UILabel(); + Font font = label.getFont(); + Color color = label.getBackground(); + + StringBuilder style = new StringBuilder("font-family:" + font.getFamily() + ";"); + style.append("font-weight:").append(font.isBold() ? "bold" : "normal").append(";"); + style.append("font-size:").append(font.getSize()).append("pt;"); + style.append("background-color: rgb(").append(color.getRed()).append(",").append(color.getGreen()).append(",").append(color.getBlue()).append(");"); + + return style; + } + +} diff --git a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java index 5257e74f42..0b7d64ee1f 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -4,6 +4,8 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.beans.BasicBeanPane; import com.fr.design.border.UITitledBorder; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.dialog.link.MessageWithLink; import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.gui.ibutton.UIButton; @@ -16,6 +18,7 @@ import com.fr.design.gui.itextfield.UITextField; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.DesignerContext; import com.fr.design.scrollruler.ModLineBorder; import com.fr.license.exception.RegistEditionException; import com.fr.log.FineLoggerFactory; @@ -25,6 +28,7 @@ import com.fr.workspace.WorkContext; import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.exception.WorkspaceAuthException; +import com.fr.workspace.engine.exception.WorkspaceCheckException; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JDialog; @@ -53,12 +57,13 @@ import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; -import java.util.function.Supplier; + import static com.fr.design.layout.TableLayout.FILL; import static com.fr.design.layout.TableLayout.PREFERRED; import static com.fr.env.TestConnectionResult.AUTH_FAILED; import static com.fr.third.guava.base.Optional.fromNullable; +import static javax.swing.JOptionPane.ERROR_MESSAGE; /** * @author yaohwu @@ -583,6 +588,8 @@ public class RemoteEnvPane extends BasicBeanPane { } catch (RegistEditionException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); throw e; + } catch (WorkspaceCheckException e) { + return TestConnectionResult.parseByException(e); } } @@ -591,6 +598,14 @@ public class RemoteEnvPane extends BasicBeanPane { okButton.setEnabled(true); try { TestConnectionResult result = get(); + if (result.isVerifyResult()) { + dialog.dispose(); + FineJOptionPane.showMessageDialog(RemoteEnvPane.this, + new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), connection.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH), + Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon")); + } message.setText(result.getText()); uiLabel.setIcon(result.getIcon()); } catch (Exception e) { @@ -635,7 +650,7 @@ public class RemoteEnvPane extends BasicBeanPane { message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0)); okButton.setEnabled(false); - dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(RemoteEnvPane.this), UIManager.getString("OptionPane.messageDialogTitle"), true); + dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(RemoteEnvPane.this), Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"), true); dialog.setSize(new Dimension(308, 132)); okButton.setEnabled(false); diff --git a/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java b/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java index dee40422c7..4ea950e845 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java +++ b/designer-base/src/main/java/com/fr/env/RemoteWorkspaceURL.java @@ -9,6 +9,8 @@ import com.fr.stable.StringUtils; */ public class RemoteWorkspaceURL implements FCloneable { + public static final String SYSTEM_LOGIN_PATH = "#management/system/login"; + /** * 默认 web app name */ diff --git a/designer-base/src/main/java/com/fr/env/TestConnectionResult.java b/designer-base/src/main/java/com/fr/env/TestConnectionResult.java index 4524254f40..5d96612cb1 100644 --- a/designer-base/src/main/java/com/fr/env/TestConnectionResult.java +++ b/designer-base/src/main/java/com/fr/env/TestConnectionResult.java @@ -1,14 +1,20 @@ package com.fr.env; +import com.fr.decision.webservice.exception.login.UserLoginLockException; +import com.fr.decision.webservice.exception.login.UserPasswordNeedUpdateException; +import com.fr.decision.webservice.exception.user.UserPasswordStrengthLimitException; import com.fr.design.i18n.Toolkit; -import com.fr.log.FineLoggerFactory; -import com.fr.stable.AssistUtils; -import com.fr.workspace.WorkContext; +import com.fr.exception.RemoteDesignPermissionDeniedException; +import com.fr.general.ComparatorUtils; +import com.fr.stable.StringUtils; import com.fr.workspace.connect.WorkspaceConnectionInfo; -import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; +import com.fr.workspace.engine.exception.WorkspaceCheckException; +import java.util.HashSet; +import java.util.Set; import javax.swing.Icon; import javax.swing.UIManager; +import org.json.Test; /** * 测试连接的结果。 @@ -76,12 +82,127 @@ public enum TestConnectionResult { public String getText() { return Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed"); } + }, + + /** + * 登录锁定 + */ + LOGIN_LOCK { + + private String value; + + @Override + public Icon getIcon() { + return UIManager.getIcon("OptionPane.errorIcon"); + } + + @Override + public String getText() { + return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Login_Lock", value); + } + + @Override + public String errorCode() { + return UserLoginLockException.ERROR_CODE; + } + + @Override + public void setValue(String lockMin) { + this.value = lockMin; + } + + @Override + public boolean isVerifyResult() { + return true; + } + }, + + /** + * 没有远程设计权限 + */ + PERMISSION_DENIED { + @Override + public Icon getIcon() { + return UIManager.getIcon("OptionPane.errorIcon"); + } + + @Override + public String getText() { + return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Permission_Denied"); + } + + @Override + public String errorCode() { + return RemoteDesignPermissionDeniedException.ERROR_CODE; + } + }, + + /** + * 弱密码 + */ + PASSWORD_STRENGTH_LIMIT () { + @Override + public Icon getIcon() { + return UIManager.getIcon("OptionPane.errorIcon"); + } + + @Override + public String getText() { + return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Weak_Password"); + } + + @Override + public String errorCode() { + return UserPasswordStrengthLimitException.ERROR_CODE; + } + + @Override + public boolean isVerifyResult() { + return true; + } + }, + + /** + * 密码更新 + */ + PASSWORD_NEED_UPDATE { + @Override + public Icon getIcon() { + return UIManager.getIcon("OptionPane.errorIcon"); + } + + @Override + public String getText() { + return Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Update_Password"); + } + + @Override + public String errorCode() { + return UserPasswordNeedUpdateException.ERROR_CODE; + } + + @Override + public boolean isVerifyResult() { + return true; + } }; public abstract Icon getIcon(); public abstract String getText(); + public void setValue(String value) { + // do noting + } + + public String errorCode() { + return StringUtils.EMPTY; + } + + public boolean isVerifyResult() { + return false; + } + public static TestConnectionResult parse(Boolean value, WorkspaceConnectionInfo info) { if (value == null) { return AUTH_FAILED; @@ -92,4 +213,30 @@ public enum TestConnectionResult { //去掉测试连接时所做的检测 return FULLY_SUCCESS; } + + public static TestConnectionResult parseByException(WorkspaceCheckException e) { + for (TestConnectionResult result : values()) { + if (ComparatorUtils.equals(e.errorCode(), result.errorCode())) { + // 登录锁定 获取下锁定的时间 + if (ComparatorUtils.equals(result, LOGIN_LOCK)) { + result.setValue(e.getMessage().replaceAll("\\D+", StringUtils.EMPTY)); + } + return result; + } + + } + return AUTH_FAILED; + } + + private final static Set VERIFY_SET = new HashSet<>(); + + static { + VERIFY_SET.add(LOGIN_LOCK); + VERIFY_SET.add(PASSWORD_NEED_UPDATE); + VERIFY_SET.add(PASSWORD_STRENGTH_LIMIT); + } + + public static boolean isVerifyResult(TestConnectionResult result) { + return VERIFY_SET.contains(result); + } }