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 c1c11553f7..b7c572650a 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -6,32 +6,45 @@ import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; +import com.fr.design.env.RemoteWorkspace; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.TemplateTreePane; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.utils.DesignUtils; +import com.fr.design.write.submit.CheckServiceDialog; import com.fr.env.EnvListPane; import com.fr.general.GeneralContext; +import com.fr.general.GeneralUtils; +import com.fr.invoke.Reflect; +import com.fr.json.JSONArray; import com.fr.license.exception.RegistEditionException; import com.fr.log.FineLoggerFactory; +import com.fr.rpc.Result; import com.fr.stable.AssistUtils; import com.fr.stable.EnvChangedListener; import com.fr.start.server.ServerTray; import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContextCallback; import com.fr.workspace.Workspace; +import com.fr.workspace.base.WorkspaceAPI; 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.WorkspaceConnectionException; +import com.fr.workspace.engine.rpc.WorkspaceProxyPool; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Set; +import java.util.HashSet; import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.QUESTION_MESSAGE; @@ -83,6 +96,7 @@ public class EnvChangeEntrance { private boolean switch2Env(final String envName, PopTipStrategy strategy) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); + WorkspaceConnectionInfo connectionInfo = selectedEnv.getConnection(); try { Workspace workspace = DesignerWorkspaceGenerator.generate(selectedEnv); @@ -121,6 +135,33 @@ public class EnvChangeEntrance { template.refreshToolArea(); } + String localBranch; + String remoteBranch; + localBranch = GeneralUtils.readFullBuildNO(); + try { + remoteBranch = new FunctionalHttpRequest(connectionInfo).getServerBranch(); + } catch (WorkspaceConnectionException e){ + remoteBranch = Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Is_Old") + formatBranch(localBranch); + } + //通过是否包含#来避免当前版本为非安装版本(主要是内部开发版本) + if(localBranch.contains("#") && localBranch.equals(remoteBranch)){ + //说明版本一致,仅做日志记录 + FineLoggerFactory.getLogger().info("Remote Designer version consistency"); + }else { + localBranch = formatBranch(localBranch); + remoteBranch = formatBranch(remoteBranch); + Set noExistServiceSet = getNoExistServiceSet(connectionInfo); + StringBuilder textBuilder = new StringBuilder(); + for(Class clazz : noExistServiceSet){ + WorkspaceAPI workspaceAPI = (WorkspaceAPI) clazz.getAnnotation(WorkspaceAPI.class); + String descriptionOfCN = Toolkit.i18nText(workspaceAPI.description()); + textBuilder.append(descriptionOfCN).append("\n"); + } + String areaText = textBuilder.toString(); + CheckServiceDialog dialog = new CheckServiceDialog(DesignerContext.getDesignerFrame(),areaText,localBranch,remoteBranch); + dialog.setVisible(true); + } + } catch (WorkspaceAuthException | RegistEditionException e) { // String title = Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed"); // String title = Toolkit.i18nText("Fine-Design_Basic_Lic_Does_Not_Support_Remote"); @@ -196,6 +237,60 @@ public class EnvChangeEntrance { return true; } + public Set getNoExistServiceSet(WorkspaceConnectionInfo info){ + Set noExistServiceSet = new HashSet(); + Set remoteServiceSet = new HashSet(); + Set localServiceSet = FineObjectPool.getInstance().getServerPool().keySet(); + + try { + JSONArray serviceArray = new FunctionalHttpRequest(info).getServiceList(); + for(int i = 0; i < serviceArray.size(); i++){ + try{ + Class clazz = Class.forName((String) serviceArray.get(i)); + remoteServiceSet.add(clazz); + } catch (Exception e){ + continue; + } + } + noExistServiceSet.addAll(localServiceSet); + noExistServiceSet.removeAll(remoteServiceSet); + return noExistServiceSet; + } catch (WorkspaceConnectionException e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + //根据本地的服务列表做逐一检测 + for(Class clazz : localServiceSet) { + Method testMethod = Reflect.on(Method.class).create(clazz, "connectTest", new Class[0], String.class, new Class[0], 1025, 8, null, null, null, null).get(); + WorkspaceProxyPool proxyPool = (WorkspaceProxyPool) (((RemoteWorkspace) WorkContext.getCurrent()).getClient()).getPool(); + Result result = proxyPool.testInvoker(testMethod); + Exception invokeException = (Exception) result.getException(); + if(invokeException != null){ + Exception cause = (Exception) invokeException.getCause(); + //获取被包装最底层的异常 + while (cause != null) { + invokeException = cause; + cause = (Exception) invokeException.getCause(); + } + //该异常表示服务不存在 + if(invokeException instanceof ClassNotFoundException){ + noExistServiceSet.add(clazz); + } + } + } + return noExistServiceSet; + } catch (Exception e){ + e.printStackTrace(); + return null; + } + } + + private String formatBranch(String branch){ + if(branch.contains("#")){ + return branch.substring(branch.lastIndexOf("#") + 1, branch.length() - 13); + } + return branch; + } + + /** * 编辑items * diff --git a/designer-base/src/main/java/com/fr/design/env/RemoteWorkspace.java b/designer-base/src/main/java/com/fr/design/env/RemoteWorkspace.java index 36d8e7f7a5..4abd7e63c8 100644 --- a/designer-base/src/main/java/com/fr/design/env/RemoteWorkspace.java +++ b/designer-base/src/main/java/com/fr/design/env/RemoteWorkspace.java @@ -8,6 +8,9 @@ import com.fr.workspace.connect.WorkspaceClient; import com.fr.workspace.connect.WorkspaceConnection; import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.server.authority.decision.DecisionOperator; +import com.fr.workspace.engine.rpc.WorkspaceProxyPool; +import com.fr.workspace.pool.WorkObjectPool; +import java.lang.reflect.Method; /** * Created by juhaoyu on 2018/6/14. @@ -78,6 +81,18 @@ public class RemoteWorkspace implements Workspace { return client.getPool().get(type); } + + public T get(Class type, Method defaultMethod){ + if(defaultMethod != null) { + WorkObjectPool objectPool = client.getPool(); + if (objectPool instanceof WorkspaceProxyPool) { + return ((WorkspaceProxyPool) objectPool).get(type, defaultMethod); + }else { + return client.getPool().get(type); + } + } + return client.getPool().get(type); + } @Override public void close() { @@ -96,4 +111,8 @@ public class RemoteWorkspace implements Workspace { return obj instanceof RemoteWorkspace && AssistUtils.equals(((RemoteWorkspace) obj).connection, this.connection); } + + public WorkspaceClient getClient(){ + return client; + } } diff --git a/designer-base/src/main/java/com/fr/design/write/submit/CheckServiceDialog.java b/designer-base/src/main/java/com/fr/design/write/submit/CheckServiceDialog.java new file mode 100644 index 0000000000..e55de3fe26 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/write/submit/CheckServiceDialog.java @@ -0,0 +1,97 @@ +package com.fr.design.write.submit; + +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.i18n.Toolkit; +import com.fr.design.layout.FRGUIPaneFactory; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.FRFont; +import com.fr.general.IOUtils; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author: Maksim + * @Date: Created in 2020/2/3 + * @Description: 远程连接时,服务检测提醒对话框 + */ +public class CheckServiceDialog extends JDialog implements ActionListener { + private JPanel topPanel; + private JPanel centerPanel; + private JPanel bottomPanel; + + public CheckServiceDialog(Frame parent, String areaText, String localBranch, String remoteBranch){ + super(parent,true); + //上面的标签面板 + topPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); + JPanel imagePanel = new JPanel(); + ImageIcon icon = (ImageIcon) IOUtils.readIcon("com/fr/design/images/warnings/warning4.png"); + + JLabel imageLabel = new JLabel(); + imageLabel.setIcon(icon); + imagePanel.add(imageLabel); + imagePanel.setPreferredSize(new Dimension(100,80)); + + JPanel verticalPanel = FRGUIPaneFactory.createVerticalFlowLayout_S_Pane(true); + FRFont font = FRFont.getInstance(); + font = font.applySize(15).applyStyle(1); + JLabel label = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Inconsistency")); + label.setFont(font); + label.setPreferredSize(new Dimension(500,30)); + JLabel label2 = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Local_Designer") + + localBranch + "/" + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Remote_Server") + remoteBranch); + label2.setPreferredSize(new Dimension(500,20)); + JLabel label3 = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Need_Update")); + label3.setPreferredSize(new Dimension(500,20)); + + verticalPanel.add(label); + verticalPanel.add(label2); + verticalPanel.add(label3); + + topPanel.add(imagePanel,BorderLayout.WEST); + topPanel.add(verticalPanel,BorderLayout.CENTER); + + //中间的文本域面板 + centerPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); + centerPanel.setBorder(BorderFactory.createEmptyBorder(0,10,10,10)); + centerPanel.setPreferredSize(new Dimension(480,320)); + + JLabel titleLabel = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Affected_Function")); + titleLabel.setPreferredSize(new Dimension(400,40)); + JTextArea checkArea = new JTextArea(areaText); + checkArea.setEnabled(false); + centerPanel.add(titleLabel,BorderLayout.NORTH); + centerPanel.add(checkArea,BorderLayout.CENTER); + + //下面的按钮面板 + UIButton okButton = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Button_Confirm")); + JPanel buttonPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); + buttonPanel.add(okButton); + okButton.addActionListener(this ); + bottomPanel = FRGUIPaneFactory.createBorderLayout_L_Pane(); + bottomPanel.add(buttonPanel); + + this.setTitle(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Title_Hint")); + this.setResizable(false); + + this.add(topPanel,BorderLayout.NORTH); + this.add(centerPanel, BorderLayout.CENTER); + this.add(buttonPanel,BorderLayout.SOUTH); + this.setSize(new Dimension(600, 500)); + + GUICoreUtils.centerWindow(this); + } + @Override + public void actionPerformed(ActionEvent e) { + this.dispose(); + } +} diff --git a/designer-base/src/main/resources/com/fr/design/images/warnings/warning4.png b/designer-base/src/main/resources/com/fr/design/images/warnings/warning4.png new file mode 100644 index 0000000000..a982ee864b Binary files /dev/null and b/designer-base/src/main/resources/com/fr/design/images/warnings/warning4.png differ