Search in sources :

Example 1 with ClientServerInfo

use of cbit.vcell.client.server.ClientServerInfo in project vcell by virtualcell.

the class VCellClientTest method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    class ParseVCellUserEvents implements Runnable {

        AWTEvent event;

        public ParseVCellUserEvents(AWTEvent event) {
            this.event = event;
        }

        @Override
        public void run() {
            if (event instanceof MouseEvent) {
                MouseEvent mouseEvent = (MouseEvent) event;
                Object details = null;
                if (mouseEvent.getID() == MouseEvent.MOUSE_RELEASED) {
                    if (mouseEvent.getComponent() instanceof JTable) {
                        JTable comp = (JTable) mouseEvent.getComponent();
                        int[] selRows = comp.getSelectedRows();
                        if (selRows != null && selRows.length > 0) {
                            StringBuffer sb = new StringBuffer();
                            for (int i = 0; i < selRows.length; i++) {
                                for (int j = 0; j < comp.getColumnCount(); j++) {
                                    try {
                                        sb.append((j == 0 ? "" : ",") + comp.getColumnName(j) + "='" + comp.getModel().getValueAt(selRows[i], j) + "'");
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                            details = sb.toString();
                        }
                    } else if (mouseEvent.getComponent() instanceof JTree) {
                        JTree comp = (JTree) mouseEvent.getComponent();
                        TreePath treePath = comp.getSelectionPath();
                        if (treePath != null) {
                            details = treePath.getLastPathComponent();
                            // BioModel, MathModel, Geometry document tree selections
                            if (details instanceof BioModelNode) {
                                // VCellBasicCellRenderer.VCDocumentInfoNode
                                BioModelNode bioModelNode = (BioModelNode) details;
                                boolean isVCDocumentInfo = bioModelNode.getUserObject() instanceof VCDocumentInfo;
                                boolean isBioModelsNetModelInfo = bioModelNode.getUserObject() instanceof BioModelsNetModelInfo;
                                if (!isVCDocumentInfo && bioModelNode.getChildCount() > 0 && bioModelNode.getUserObject() instanceof VCellBasicCellRenderer.VCDocumentInfoNode) {
                                    TreeNode treeNode = bioModelNode.getFirstChild();
                                    if (treeNode instanceof BioModelNode && ((BioModelNode) treeNode).getUserObject() instanceof VCDocumentInfo) {
                                        details = ((BioModelNode) treeNode).getUserObject();
                                    }
                                } else if (isBioModelsNetModelInfo) {
                                    details = BioModelsNetModelInfo.class.getSimpleName() + " '" + ((BioModelsNetModelInfo) bioModelNode.getUserObject()).getName() + "'";
                                }
                            }
                        }
                    } else if (mouseEvent.getComponent() instanceof JTabbedPane) {
                        JTabbedPane comp = (JTabbedPane) mouseEvent.getComponent();
                        details = "'" + comp.getTitleAt(comp.getSelectedIndex()) + "'";
                    } else if (mouseEvent.getComponent() instanceof JMenuItem) {
                        JMenuItem comp = (JMenuItem) mouseEvent.getComponent();
                        details = "'" + comp.getText() + "'";
                    } else if (mouseEvent.getComponent() instanceof AbstractButton) {
                        AbstractButton comp = (AbstractButton) mouseEvent.getComponent();
                        Boolean bSelected = (comp instanceof JToggleButton ? ((JToggleButton) comp).isSelected() : null);
                        details = (bSelected != null ? "(" + (bSelected ? "selected" : "unselected") + ")" : "") + "'" + comp.getText() + "'";
                    } else if (mouseEvent.getComponent() instanceof JComboBox<?>) {
                        JComboBox<?> comp = (JComboBox<?>) mouseEvent.getComponent();
                        details = "'" + comp.getSelectedItem().toString() + "'";
                    } else if (mouseEvent.getComponent() instanceof JList<?>) {
                        JList<?> comp = (JList<?>) mouseEvent.getComponent();
                        details = "'" + comp.getSelectedValue() + "'";
                    } else {
                        details = "TBD " + mouseEvent.getComponent();
                    }
                    Component parentComponent = mouseEvent.getComponent();
                    StringBuffer parentInfo = new StringBuffer();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BeanUtils.vcDateFormat, Locale.US);
                    do {
                        String title = "";
                        if (parentComponent instanceof Dialog) {
                            title = ((Dialog) parentComponent).getTitle();
                        } else if (parentComponent instanceof Frame) {
                            title = ((Frame) parentComponent).getTitle();
                        }
                        parentInfo.append(parentComponent.getClass().getTypeName() + "(" + parentComponent.getName() + (title != null && title.length() > 0 ? ",title='" + title + "'" : "") + ")");
                        if (parentComponent instanceof DocumentWindow && ((DocumentWindow) parentComponent).getTopLevelWindowManager() instanceof DocumentWindowManager) {
                            VCDocument vcDocument = ((DocumentWindowManager) ((DocumentWindow) parentComponent).getTopLevelWindowManager()).getVCDocument();
                            if (vcDocument != null) {
                                String date = (vcDocument.getVersion() != null && vcDocument.getVersion().getDate() != null ? simpleDateFormat.format(vcDocument.getVersion().getDate()) : "nodate");
                                parentInfo.append("doc=" + vcDocument.getDocumentType() + " '" + vcDocument.getName() + "' " + date);
                            }
                        }
                        parentInfo.append(" -> ");
                    } while ((parentComponent = parentComponent.getParent()) != null);
                    // try to add event, if full remove an event from the top
                    while (!recordedUserEvents.offer(mouseEvent.getClickCount() + " " + (details == null ? "null" : details.toString()) + BeanUtils.PLAINTEXT_EMAIL_NEWLINE + parentInfo.toString())) {
                        recordedUserEvents.poll();
                    }
                }
            }
        }
    }
    ;
    AWTEventListener awtEventListener = new AWTEventListener() {

        @Override
        public void eventDispatched(final AWTEvent event) {
            if (event instanceof MouseEvent) {
                if (((MouseEvent) event).getID() == MouseEvent.MOUSE_RELEASED) {
                    new Thread(new ParseVCellUserEvents(event)).start();
                }
            }
        }
    };
    Toolkit.getDefaultToolkit().addAWTEventListener(awtEventListener, AWTEvent.MOUSE_EVENT_MASK);
    // check synchronize Proxy prefs, Proxy Properties
    Preferences prefs = Preferences.userNodeForPackage(RemoteProxyVCellConnectionFactory.class);
    Boolean bHttp = (System.getProperty(NetworkProxyUtils.PROXY_HTTP_HOST) == null && System.getProperty(NetworkProxyUtils.PROXY_SOCKS_HOST) == null ? null : System.getProperty(NetworkProxyUtils.PROXY_HTTP_HOST) != null);
    String currentProxyHost = (bHttp == null ? null : (bHttp ? System.getProperty(NetworkProxyUtils.PROXY_HTTP_HOST) : System.getProperty(NetworkProxyUtils.PROXY_SOCKS_HOST)));
    String currentProxyPort = (bHttp == null ? null : (bHttp ? System.getProperty(NetworkProxyUtils.PROXY_HTTP_PORT) : System.getProperty(NetworkProxyUtils.PROXY_SOCKS_PORT)));
    NetworkProxyUtils.setProxyProperties(false, null, prefs.get(NetworkProxyPreferences.prefProxyType, NetworkProxyPreferences.prefProxyType), currentProxyHost, currentProxyPort, prefs.get(NetworkProxyPreferences.prefProxyType, NetworkProxyPreferences.prefProxyType), prefs.get(NetworkProxyPreferences.prefProxyHost, NetworkProxyPreferences.prefProxyHost), prefs.get(NetworkProxyPreferences.prefProxyPort, NetworkProxyPreferences.prefProxyPort));
    final boolean IS_DEBUG = ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
    if (!IS_DEBUG) {
        String siteName = VCellSoftwareVersion.fromSystemProperty().getSite().name().toLowerCase();
        ConsoleCapture.getInstance().captureStandardOutAndError(new File(ResourceUtil.getLogDir(), "vcellrun_" + siteName + ".log"));
    }
    Logging.init();
    ErrorUtils.setDebug(IS_DEBUG);
    if (args != null && args.length >= 1 && args[0].equals("-console")) {
        // remove install4j parameter
        List<String> newArgs = new ArrayList<String>();
        newArgs.addAll(Arrays.asList(args));
        newArgs.remove(0);
        args = newArgs.toArray(new String[0]);
    }
    StringBuffer stringBuffer = new StringBuffer();
    for (int i = 0; i < args.length; i++) {
        stringBuffer.append("arg" + i + "=\"" + args[i] + "\" ");
    }
    System.out.println("starting with arguments [" + stringBuffer + "]");
    System.out.println("Running under Java major version: ONE point " + ResourceUtil.getJavaVersion().toString() + ".  Specifically: Java " + (System.getProperty("java.version")) + ", published by " + (System.getProperty("java.vendor")) + ", on the " + (System.getProperty("os.arch")) + " architecture running version " + (System.getProperty("os.version")) + " of the " + (System.getProperty("os.name")) + " operating system");
    ClientServerInfo csInfo = null;
    String hoststr = System.getProperty(PropertyLoader.vcellServerHost);
    String[] hosts = null;
    if (hoststr != null) {
        StringTokenizer st = new StringTokenizer(hoststr, " ,;");
        if (st.countTokens() >= 1) {
            hosts = new String[st.countTokens()];
            int count = 0;
            while (st.hasMoreTokens()) {
                hosts[count++] = st.nextToken();
            }
        }
    }
    if (hosts == null) {
        hosts = new String[1];
    }
    String user = null;
    String password = null;
    VCDocument initialDocument = null;
    if (args.length == 3) {
        hosts[0] = args[0];
        user = args[1];
        password = args[2];
    } else if (args.length == 0) {
    // this is ok
    } else if (args.length == 1) {
        // Check if arg is drag-n-drop file or a 'hostname'
        try {
            // drag and drop file on install4j VCell launcher will pass filepath as single arg to VCell
            File openThisVCellFile = new File(args[0]);
            if (openThisVCellFile.exists() && openThisVCellFile.isFile()) {
                initialDocument = startupWithOpen(args[0]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        // continue to hostname check
        }
        // If startup file not exist assume arg is a hostname
        if (initialDocument == null) {
            hosts[0] = args[0];
        }
    // If install4j drag-n-drop, hosts[0] stays null and host is assumed to be loaded from a client property
    } else if (args.length == 2 && args[0].equals("-open")) {
        // hosts[0] = "-local";
        initialDocument = startupWithOpen(args[1]);
    } else {
        System.out.println("usage: VCellClientTest ( ((-local|host[:port]) [userid password]) | ([-open] filename) )");
        System.exit(1);
    }
    if (hosts[0] != null && hosts[0].equalsIgnoreCase("-local")) {
        csInfo = ClientServerInfo.createLocalServerInfo(user, (password == null || password.length() == 0 ? null : new UserLoginInfo.DigestedPassword(password)));
    } else {
        String[] hostParts = hosts[0].split(":");
        String apihost = hostParts[0];
        int apiport = Integer.parseInt(hostParts[1]);
        csInfo = ClientServerInfo.createRemoteServerInfo(apihost, apiport, user, (password == null || password.length() == 0 ? null : new UserLoginInfo.DigestedPassword(password)));
    }
    try {
        String propertyFile = PropertyLoader.getProperty(PropertyLoader.propertyFileProperty, "");
        if (propertyFile.length() > 0) {
            PropertyLoader.loadProperties(ArrayUtils.addAll(REQUIRED_CLIENT_PROPERTIES, REQUIRED_LOCAL_PROPERTIES));
            try {
                VCMongoMessage.enabled = true;
                VCMongoMessage.serviceStartup(ServiceName.client, null, null);
                PropertyLoader.sendErrorsToMongo();
            } catch (Exception e) {
                System.out.println("failed to start Mongo logging");
            }
        } else {
            PropertyLoader.loadProperties(REQUIRED_CLIENT_PROPERTIES);
            VCMongoMessage.enabled = false;
        }
        // call in main thread, since it's quick and not necessarily thread safe
        ResourceUtil.setNativeLibraryDirectory();
        vcellClient = VCellClient.startClient(initialDocument, csInfo);
        VCellClientDataService vcellClientDataService = new VCellClientDataServiceImpl(vcellClient);
        VCellProxyServer.startVCellVisitDataServerThread(vcellClientDataService);
        // starting loading libraries
        new LibraryLoaderThread(true).start();
        try {
            PythonSupport.verifyInstallation(PythonPackage.values());
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
    // SimulationService.Iface simService = new SimulationServiceImpl();
    // VCellIJServer.startVCellVisitDataServerThread(simService, false);
    } catch (Throwable exception) {
        ErrorUtils.sendRemoteLogMessage(csInfo.getUserLoginInfo(), csInfo.toString() + "\nvcell startup failed\n\n" + exception.getMessage());
        JOptionPane.showMessageDialog(null, exception.getMessage(), "Fatal Error", JOptionPane.OK_OPTION);
        System.err.println("Exception occurred in main() of VCellApplication");
        exception.printStackTrace(System.out);
    }
}
Also used : VCellClientDataService(cbit.vcell.client.pyvcellproxy.VCellClientDataService) BioModelsNetModelInfo(cbit.vcell.client.desktop.biomodel.BioModelsNetModelInfo) ArrayList(java.util.ArrayList) ClientServerInfo(cbit.vcell.client.server.ClientServerInfo) JToggleButton(javax.swing.JToggleButton) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) TreeNode(javax.swing.tree.TreeNode) Dialog(java.awt.Dialog) AWTEvent(java.awt.AWTEvent) AbstractButton(javax.swing.AbstractButton) VCDocument(org.vcell.util.document.VCDocument) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) JTree(javax.swing.JTree) JTable(javax.swing.JTable) File(java.io.File) JList(javax.swing.JList) Frame(java.awt.Frame) AWTEventListener(java.awt.event.AWTEventListener) JTabbedPane(javax.swing.JTabbedPane) BioModelNode(cbit.vcell.desktop.BioModelNode) VCellClientDataServiceImpl(cbit.vcell.client.data.VCellClientDataServiceImpl) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) NetworkProxyPreferences(cbit.vcell.client.desktop.NetworkProxyPreferences) Preferences(java.util.prefs.Preferences) MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) LibraryLoaderThread(cbit.vcell.resource.LibraryLoaderThread) LibraryLoaderThread(cbit.vcell.resource.LibraryLoaderThread) StringTokenizer(java.util.StringTokenizer) TreePath(javax.swing.tree.TreePath) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with ClientServerInfo

use of cbit.vcell.client.server.ClientServerInfo in project vcell by virtualcell.

the class VCellClient method login.

public static void login(final RequestManager requestManager, final ClientServerInfo clientServerInfo, final DocumentWindowManager currWindowManager) {
    final LoginManager loginManager = new LoginManager();
    LoginDelegate loginDelegate = new LoginDelegate() {

        public void login(final String userid, final UserLoginInfo.DigestedPassword digestedPassword) {
            AsynchClientTask task1 = new AsynchClientTask("connect to server", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

                @Override
                public void run(Hashtable<String, Object> hashTable) throws Exception {
                    ClientServerInfo newClientServerInfo = createClientServerInfo(clientServerInfo, userid, digestedPassword);
                    requestManager.connectToServer(currWindowManager, newClientServerInfo);
                }
            };
            AsynchClientTask task2 = new AsynchClientTask("logging in", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

                @Override
                public void run(Hashtable<String, Object> hashTable) throws Exception {
                    ConnectionStatus connectionStatus = requestManager.getConnectionStatus();
                    loginManager.close();
                    if (connectionStatus.getStatus() != ConnectionStatus.CONNECTED) {
                        VCellClient.login(requestManager, clientServerInfo, currWindowManager);
                    } else {
                        ErrorUtils.setLoginInfo(clientServerInfo.getUserLoginInfo());
                    }
                }
            };
            ClientTaskDispatcher.dispatch(currWindowManager.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 });
        }

        public void registerRequest() {
            loginManager.close();
            try {
                UserRegistrationManager.registrationOperationGUI(requestManager, currWindowManager, clientServerInfo, LoginManager.USERACTION_REGISTER, null);
            } catch (UserCancelException e) {
            // do nothing
            } catch (Exception e) {
                e.printStackTrace();
                PopupGenerator.showErrorDialog(currWindowManager, "New user Registration error:\n" + e.getMessage());
            }
        }

        public void lostPasswordRequest(String userid) {
            try {
                ClientServerInfo newClientServerInfo = createClientServerInfo(clientServerInfo, userid, null);
                UserRegistrationManager.registrationOperationGUI(requestManager, currWindowManager, newClientServerInfo, LoginManager.USERACTION_LOSTPASSWORD, null);
            } catch (UserCancelException e) {
            // do nothing
            } catch (Exception e) {
                e.printStackTrace();
                PopupGenerator.showErrorDialog(currWindowManager, "New user Registration error:\n" + e.getMessage());
            }
        }

        public void userCancel() {
            loginManager.close();
            PopupGenerator.showInfoDialog(currWindowManager, "Note:  The Login dialog can be accessed any time under the 'Server' main menu as 'Change User...'");
        }
    };
    loginManager.showLoginDialog(currWindowManager.getComponent(), currWindowManager, loginDelegate);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) LoginManager(cbit.vcell.desktop.LoginManager) Hashtable(java.util.Hashtable) ClientServerInfo(cbit.vcell.client.server.ClientServerInfo) UserCancelException(org.vcell.util.UserCancelException) LoginDelegate(cbit.vcell.desktop.LoginDelegate) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) ConnectionStatus(cbit.vcell.client.server.ConnectionStatus) UserCancelException(org.vcell.util.UserCancelException)

Example 3 with ClientServerInfo

use of cbit.vcell.client.server.ClientServerInfo in project vcell by virtualcell.

the class UserRegistrationManager method registrationOperationGUI.

public static void registrationOperationGUI(final RequestManager requestManager, final DocumentWindowManager currWindowManager, final ClientServerInfo currentClientServerInfo, final String userAction, final ClientServerManager clientServerManager) throws Exception {
    if (!(userAction.equals(LoginManager.USERACTION_REGISTER) || userAction.equals(LoginManager.USERACTION_EDITINFO) || userAction.equals(LoginManager.USERACTION_LOSTPASSWORD))) {
        throw new IllegalArgumentException(UserRegistrationOP.class.getName() + ".registrationOperationGUI:  Only New registration, Edit UserInfo or Lost Password allowed.");
    }
    if ((userAction.equals(LoginManager.USERACTION_REGISTER) || userAction.equals(LoginManager.USERACTION_LOSTPASSWORD)) && clientServerManager != null) {
        throw new IllegalArgumentException(UserRegistrationOP.class.getName() + ".registrationOperationGUI:  Register New User Info requires clientServerManager null.");
    }
    if (userAction.equals(LoginManager.USERACTION_EDITINFO) && clientServerManager == null) {
        throw new IllegalArgumentException(UserRegistrationOP.class.getName() + ".registrationOperationGUI:  Edit User Info requires clientServerManager not null.");
    }
    RegistrationService registrationService = null;
    if (clientServerManager != null) {
        registrationService = clientServerManager.getRegistrationProvider();
    } else {
        registrationService = VCellServiceHelper.getInstance().loadService(RegistrationService.class);
    }
    if (userAction.equals(LoginManager.USERACTION_LOSTPASSWORD)) {
        if (currentClientServerInfo.getUsername() == null || currentClientServerInfo.getUsername().length() == 0) {
            throw new IllegalArgumentException("Lost Password requires a VCell User Name.");
        }
        String result = PopupGenerator.showWarningDialog(currWindowManager, null, new UserMessage("Sending Password via email for user '" + currentClientServerInfo.getUsername() + "'\nusing currently registered email address.", new String[] { "OK", "Cancel" }, "OK"), null);
        if (!result.equals("OK")) {
            throw UserCancelException.CANCEL_GENERIC;
        }
        registrationService.sendLostPassword(currentClientServerInfo.getUsername());
        return;
    }
    final RegistrationService finalRegistrationProvider = registrationService;
    final String ORIGINAL_USER_INFO_HOLDER = "originalUserInfoHolder";
    // final String DIGESTED_USERIDS_KEY = "DIGESTED_USERIDS_KEY";
    AsynchClientTask gatherInfoTask = new AsynchClientTask("gathering user info for updating", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (userAction.equals(LoginManager.USERACTION_EDITINFO)) {
                UserInfo originalUserInfoHolder = finalRegistrationProvider.getUserInfo(clientServerManager.getUser().getID());
                hashTable.put(ORIGINAL_USER_INFO_HOLDER, originalUserInfoHolder);
            }
        }
    };
    final String NEW_USER_INFO_KEY = "NEW_USER_INFO_KEY";
    AsynchClientTask showPanelTask = new AsynchClientTask("please fill the user registration form", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (registrationPanel == null) {
                registrationPanel = new RegistrationPanel();
            } else {
                if (currentClientServerInfo.getUsername() != null) {
                    // another user already connected
                    registrationPanel.reset();
                }
            }
            UserInfo originalUserInfoHolder = (UserInfo) hashTable.get(ORIGINAL_USER_INFO_HOLDER);
            ;
            if (userAction.equals(LoginManager.USERACTION_EDITINFO) && originalUserInfoHolder != null) {
                registrationPanel.setUserInfo(originalUserInfoHolder, true);
            }
            do {
                int result = DialogUtils.showComponentOKCancelDialog(currWindowManager.getComponent(), registrationPanel, (userAction.equals(LoginManager.USERACTION_REGISTER) ? "Create New User Registration" : "Update Registration Information (" + clientServerManager.getUser().getName() + ")"));
                if (result != JOptionPane.OK_OPTION) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
                UserRegistrationOP.NewPasswordUserInfo newUserInfo = registrationPanel.getUserInfo();
                if (userAction.equals(LoginManager.USERACTION_EDITINFO)) {
                    // set existing digestPassword
                    if (newUserInfo.digestedPassword0 == null && originalUserInfoHolder.digestedPassword0 != null) {
                        newUserInfo.digestedPassword0 = originalUserInfoHolder.digestedPassword0;
                    }
                    if (newUserInfo.otherDigestedPassword == null && originalUserInfoHolder.digestedPassword0 != null) {
                        newUserInfo.otherDigestedPassword = originalUserInfoHolder.digestedPassword0;
                    }
                }
                try {
                    if (!checkUserInfo(currWindowManager, originalUserInfoHolder, newUserInfo, userAction)) {
                        PopupGenerator.showInfoDialog(currWindowManager, "No registration information has changed.");
                        continue;
                    }
                } catch (UserCancelException ex) {
                    continue;
                } catch (Exception ex) {
                    PopupGenerator.showErrorDialog(currWindowManager, ex.getMessage());
                    continue;
                }
                hashTable.put(NEW_USER_INFO_KEY, newUserInfo);
                break;
            } while (true);
        }
    };
    // final String USERID_NOT_UNIQUE = "USERID_NOT_UNIQUE";
    AsynchClientTask updateDbTask = new AsynchClientTask(userAction.equals(LoginManager.USERACTION_REGISTER) ? "registering new user" : "updating user info", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            UserInfo newUserInfo = (UserInfo) hashTable.get(NEW_USER_INFO_KEY);
            // }
            try {
                UserInfo registeredUserInfo = finalRegistrationProvider.insertUserInfo(newUserInfo, (userAction.equals(LoginManager.USERACTION_EDITINFO) ? true : false));
                hashTable.put("registeredUserInfo", registeredUserInfo);
            } catch (UseridIDExistsException e) {
                throw e;
            } catch (Exception e) {
                e.printStackTrace();
                throw new Exception("Error " + (userAction.equals(LoginManager.USERACTION_REGISTER) ? "registering new user" : "updating user info ") + " (" + newUserInfo.userid + "), " + e.getMessage());
            }
        }
    };
    AsynchClientTask connectTask = new AsynchClientTask("user logging in", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            UserInfo registeredUserInfo = (UserInfo) hashTable.get("registeredUserInfo");
            try {
                if (userAction.equals(LoginManager.USERACTION_REGISTER)) {
                    try {
                        ClientServerInfo newClientServerInfo = VCellClient.createClientServerInfo(currentClientServerInfo, registeredUserInfo.userid, registeredUserInfo.digestedPassword0);
                        requestManager.connectToServer(currWindowManager, newClientServerInfo);
                    } finally {
                        ConnectionStatus connectionStatus = requestManager.getConnectionStatus();
                        if (connectionStatus.getStatus() != ConnectionStatus.CONNECTED) {
                            PopupGenerator.showErrorDialog(currWindowManager, "Automatic login of New user '" + registeredUserInfo.userid + "' failed.\n" + "Restart VCell and login as '" + registeredUserInfo.userid + "' to use new VCell account.");
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new Exception("Error logging in user " + " (" + registeredUserInfo.userid + "), " + e.getMessage());
            }
        }
    };
    AsynchClientTask useridErrorTask = new AsynchClientTask("re-enter userid...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false, false) {

        @Override
        public void run(final Hashtable<String, Object> hashTable) throws Exception {
            if (hashTable.containsKey(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR)) {
                // retry if requested
                if (hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR) instanceof UseridIDExistsException) {
                    // Exception handled here, suppress ClientTaskDispatcher error dialog.
                    hashTable.remove(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR);
                    UserInfo newUserInfo = (UserInfo) hashTable.get(NEW_USER_INFO_KEY);
                    PopupGenerator.showErrorDialog(currWindowManager, "Login ID '" + newUserInfo.userid + "' cannot be used, enter a different one.");
                    // Use thread to restart registration process again
                    new Thread(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                registrationOperationGUI(requestManager, currWindowManager, currentClientServerInfo, userAction, clientServerManager);
                            } catch (Exception e) {
                                e.printStackTrace();
                                DialogUtils.showErrorDialog(currWindowManager.getComponent(), e.getMessage());
                            }
                        }
                    }).start();
                }
            }
        }
    };
    ClientTaskDispatcher.dispatch(currWindowManager.getComponent(), new Hashtable<String, Object>(), new AsynchClientTask[] { gatherInfoTask, showPanelTask, updateDbTask, connectTask, useridErrorTask }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) UserCancelException(org.vcell.util.UserCancelException) ClientServerInfo(cbit.vcell.client.server.ClientServerInfo) UserInfo(org.vcell.util.document.UserInfo) RegistrationService(org.vcell.service.registration.RegistrationService) UseridIDExistsException(org.vcell.util.UseridIDExistsException) UserCancelException(org.vcell.util.UserCancelException) UserRegistrationOP(cbit.vcell.server.UserRegistrationOP) UseridIDExistsException(org.vcell.util.UseridIDExistsException) ConnectionStatus(cbit.vcell.client.server.ConnectionStatus) RegistrationPanel(cbit.vcell.desktop.RegistrationPanel)

Example 4 with ClientServerInfo

use of cbit.vcell.client.server.ClientServerInfo in project vcell by virtualcell.

the class ClientFactory method createRemoteClientServerManager.

public static ClientServerManager createRemoteClientServerManager(String apihost, Integer apiport, String username, String password) {
    DigestedPassword digestedPassword = new DigestedPassword(password);
    ClientServerInfo csInfo = ClientServerInfo.createRemoteServerInfo(apihost, apiport, username, digestedPassword);
    InteractiveContextDefaultProvider defaultInteractiveContextProvider = new VCellGuiInteractiveContextDefaultProvider();
    ClientServerManager clientServerManager = new ClientServerManager(csInfo, defaultInteractiveContextProvider);
    RequestManagerAdapter requestManager = new RequestManagerAdapter();
    TopLevelWindowManager windowManager = new TopLevelWindowManager(requestManager) {

        @Override
        public Component getComponent() {
            return null;
        }

        @Override
        public String getManagerID() {
            return null;
        }

        @Override
        public boolean isRecyclable() {
            return false;
        }
    };
    InteractiveContext requester = new VCellGuiInteractiveContext(windowManager);
    clientServerManager.connect(requester);
    return clientServerManager;
}
Also used : InteractiveContextDefaultProvider(cbit.vcell.client.server.ClientServerManager.InteractiveContextDefaultProvider) ClientServerManager(cbit.vcell.client.server.ClientServerManager) InteractiveContext(cbit.vcell.client.server.ClientServerManager.InteractiveContext) ClientServerInfo(cbit.vcell.client.server.ClientServerInfo) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword)

Example 5 with ClientServerInfo

use of cbit.vcell.client.server.ClientServerInfo in project vcell by virtualcell.

the class ClientFactory method createLocalClientServerManager.

public static ClientServerManager createLocalClientServerManager(String userid, String password) {
    DigestedPassword digestedPassword = new DigestedPassword(password);
    ClientServerInfo csInfo = ClientServerInfo.createLocalServerInfo(userid, digestedPassword);
    InteractiveContextDefaultProvider defaultInteractiveContextProvider = new VCellGuiInteractiveContextDefaultProvider();
    ClientServerManager clientServerManager = new ClientServerManager(csInfo, defaultInteractiveContextProvider);
    clientServerManager.connect(null);
    return clientServerManager;
}
Also used : InteractiveContextDefaultProvider(cbit.vcell.client.server.ClientServerManager.InteractiveContextDefaultProvider) ClientServerManager(cbit.vcell.client.server.ClientServerManager) ClientServerInfo(cbit.vcell.client.server.ClientServerInfo) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword)

Aggregations

ClientServerInfo (cbit.vcell.client.server.ClientServerInfo)8 ClientServerManager (cbit.vcell.client.server.ClientServerManager)4 DigestedPassword (org.vcell.util.document.UserLoginInfo.DigestedPassword)3 VCellGuiInteractiveContextDefaultProvider (cbit.vcell.client.VCellGuiInteractiveContextDefaultProvider)2 InteractiveContextDefaultProvider (cbit.vcell.client.server.ClientServerManager.InteractiveContextDefaultProvider)2 ConnectionStatus (cbit.vcell.client.server.ConnectionStatus)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 Hashtable (java.util.Hashtable)2 UserCancelException (org.vcell.util.UserCancelException)2 UserLoginInfo (org.vcell.util.document.UserLoginInfo)2 DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)1 VCellClient (cbit.vcell.client.VCellClient)1 VCellClientDataServiceImpl (cbit.vcell.client.data.VCellClientDataServiceImpl)1 DocumentWindow (cbit.vcell.client.desktop.DocumentWindow)1 NetworkProxyPreferences (cbit.vcell.client.desktop.NetworkProxyPreferences)1 BioModelsNetModelInfo (cbit.vcell.client.desktop.biomodel.BioModelsNetModelInfo)1 VCellClientDataService (cbit.vcell.client.pyvcellproxy.VCellClientDataService)1 InteractiveContext (cbit.vcell.client.server.ClientServerManager.InteractiveContext)1 BioModelNode (cbit.vcell.desktop.BioModelNode)1 LoginDelegate (cbit.vcell.desktop.LoginDelegate)1