Ejemplo n.º 1
0
  public List getChange() {
    ArrayList change = new ArrayList();
    for (Iterator i = fieldComponents.keySet().iterator(); i.hasNext(); ) {
      String fieldId = (String) i.next();
      Object component = fieldComponents.get(fieldId);
      if (component instanceof ChangeAwareComponent
          && ((ChangeAwareComponent) component).hasChanged()) {
        String stringValue;
        if (component instanceof JTextField) stringValue = ((JTextField) component).getText();
        // hangle other components here
        else continue;

        Field field = Configuration.getFieldFromId(fieldId);
        try {
          Object value = FieldConverter.fromString(stringValue, field.getDisplayType());
          change.add(new FieldChange(field, value));
        } catch (Exception e) {
          Alert.error(e.getMessage());
        }
      }
    }
    return change;
  }
Ejemplo n.º 2
0
  public boolean doLogin(GraphicManager graphicManager) {

    if (Environment.isNoPodServer()) {
      Environment.setNewLook(true);
      log.info("Login POD Server.");
    }
    if (Environment.getStandAlone() || Environment.isNoPodServer()) {
      if (!Environment.isNoPodServer()) {
        Environment.setUser(new DefaultUser());
        log.info("Locale user.");
      }
      return true;
    }
    credentials.put("serverUrl", serverUrl);
    getCredentials();
    Environment.setNewLook(true);

    int badLoginCount = 0;
    while (true) { // until a good login or exit because of too many bad
      //			graphicManager.getFrame().setVisible(true);
      if (login == null || password == null || badLoginCount > 0) {
        URL loginUrl = null;
        if (login == null || password == null) {
          try {
            loginUrl = new URL(serverUrl + "/login");
            System.out.println("trying login at " + serverUrl + "/login");
          } catch (MalformedURLException e) {
          }
        }
        LoginForm form =
            LoginDialog.doLogin(graphicManager.getFrame(), loginUrl); // it's actually a singleton
        if (form.isCancelled()) System.exit(-1);
        if (form.isUseMenus()) Environment.setNewLook(false);

        login = form.getLogin();
        password = form.getPassword();
      }

      if ("_SA".equals(login) || Environment.getStandAlone()) { // for testing purposes!
        Environment.setStandAlone(true);
        Environment.setUser(new DefaultUser());
        break;
      } else {
        credentials.put("login", login);
        credentials.put("password", password);

        SessionFactory.getInstance().setCredentials(credentials);
        try {
          Session session = SessionFactory.getInstance().getSession(false);
          System.out.println("logging in");
          final GraphicManager gm = graphicManager;
          SessionFactory.callNoEx(
              session,
              "login",
              new Class[] {Closure.class},
              new Object[] {
                new Closure() {
                  public void execute(Object arg0) {
                    Map<String, String> env = (Map<String, String>) arg0;
                    if (env != null) {
                      String serverVersion = env.get("serverVersion");
                      checkServerVersion(serverVersion);
                    }
                    if (gm != null) gm.setConnected(true);
                  }
                }
              });
          if (!((Boolean) SessionFactory.callNoEx(session, "isLicensedToRunClient", null, null))
              .booleanValue()) {
            Alert.error(Messages.getString("Error.roleCantRunClient"));
            abort();
            return false;
          }

          //					System.out.println("Application started with args: credentials=" +
          // credentials.get("login") + " name " + session.getUser().getName() + " Roles " +
          // session.getUser().getServerRoles());
          break;
          //			TODO test if login is valid.  If not, reshow login dialog
        } catch (Exception e) {
          if (Session.EXPIRED.equals(e.getMessage())) {
            Alert.error(Messages.getString("Error.accountExpired"));
            abort();
            return false;
          }
          System.out.println("failure " + e);
          badLoginCount++;
          SessionFactory.getInstance().clearSessions();

          if (badLoginCount == NUM_INVALID_LOGINS) {
            Alert.error(Messages.getString("Login.tooManyBad"));
            abort();
            return false;
          } else {
            Alert.error(Messages.getString("Login.error"));
          }
        }
      }
    }
    return true;
  }