Search in sources :

Example 1 with ConnectionStatus

use of cbit.vcell.client.server.ConnectionStatus 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 2 with ConnectionStatus

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

the class StatusUpdater method guiToDo.

/**
 * Insert the method's description here.
 * Creation date: (5/19/2004 2:36:54 AM)
 */
protected void guiToDo(java.lang.Object params) {
    // do memory again... usefull on brand new windows
    updateMemory(Runtime.getRuntime().freeMemory(), Runtime.getRuntime().totalMemory());
    // do connection update on demand
    if (params instanceof ConnectionStatus) {
        ConnectionStatus currentConnStatus = (ConnectionStatus) params;
        updateConnectionStatus(currentConnStatus);
        if (currentConnStatus.getStatus() == ConnectionStatus.INITIALIZING) {
            animationDuringInit();
            setDelay(100);
            restart();
        }
    }
}
Also used : ConnectionStatus(cbit.vcell.client.server.ConnectionStatus)

Example 3 with ConnectionStatus

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

the class TopLevelWindowManager method prepareDocumentToLoad.

public void prepareDocumentToLoad(VCDocument doc, boolean bInNewWindow) throws Exception {
    if (doc instanceof BioModel) {
        Simulation[] simulations = ((BioModel) doc).getSimulations();
        ArrayList<VCSimulationIdentifier> simIDs = new ArrayList<VCSimulationIdentifier>();
        for (int i = 0; i < simulations.length; i++) {
            SimulationInfo simulationInfo = simulations[i].getSimulationInfo();
            if (simulationInfo != null) {
                simIDs.add(simulationInfo.getAuthoritativeVCSimulationIdentifier());
            }
        }
        RequestManager rm = getRequestManager();
        ConnectionStatus stat = rm.getConnectionStatus();
        if (stat.getStatus() == ConnectionStatus.CONNECTED) {
            rm.getDocumentManager().preloadSimulationStatus(simIDs.toArray(new VCSimulationIdentifier[0]));
        }
    } else if (doc instanceof MathModel) {
        Geometry geometry = ((MathModel) doc).getMathDescription().getGeometry();
        geometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
        Simulation[] simulations = ((MathModel) doc).getSimulations();
        // VCSimulationIdentifier simIDs[] = new VCSimulationIdentifier[simulations.length];
        ArrayList<VCSimulationIdentifier> simIDs = new ArrayList<>();
        for (int i = 0; i < simulations.length; i++) {
            if (simulations[i].getSimulationInfo() != null) {
                simIDs.add(simulations[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier());
            }
        }
        getRequestManager().getDocumentManager().preloadSimulationStatus(simIDs.toArray(new VCSimulationIdentifier[0]));
    } else if (doc instanceof Geometry) {
        ((Geometry) doc).precomputeAll(new GeometryThumbnailImageFactoryAWT());
    }
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) MathModel(cbit.vcell.mathmodel.MathModel) ArrayList(java.util.ArrayList) Geometry(cbit.vcell.geometry.Geometry) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) ConnectionStatus(cbit.vcell.client.server.ConnectionStatus) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 4 with ConnectionStatus

use of cbit.vcell.client.server.ConnectionStatus 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)

Aggregations

ConnectionStatus (cbit.vcell.client.server.ConnectionStatus)4 ClientServerInfo (cbit.vcell.client.server.ClientServerInfo)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 Hashtable (java.util.Hashtable)2 UserCancelException (org.vcell.util.UserCancelException)2 BioModel (cbit.vcell.biomodel.BioModel)1 LoginDelegate (cbit.vcell.desktop.LoginDelegate)1 LoginManager (cbit.vcell.desktop.LoginManager)1 RegistrationPanel (cbit.vcell.desktop.RegistrationPanel)1 Geometry (cbit.vcell.geometry.Geometry)1 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)1 MathModel (cbit.vcell.mathmodel.MathModel)1 UserRegistrationOP (cbit.vcell.server.UserRegistrationOP)1 Simulation (cbit.vcell.solver.Simulation)1 SimulationInfo (cbit.vcell.solver.SimulationInfo)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 ArrayList (java.util.ArrayList)1 RegistrationService (org.vcell.service.registration.RegistrationService)1 UseridIDExistsException (org.vcell.util.UseridIDExistsException)1 UserInfo (org.vcell.util.document.UserInfo)1