Пример #1
0
  // Stuff from database
  // DefaultConstructor
  public CoreCfg() {
    actions = new ArrayList<String>();

    // Read information from WEBXML PARAMS
    core_mysqlHost = (String) FacesUtil.getWebXmlParam("pdaweb.mysqlHost");
    core_mysqlDBPrefix = (String) FacesUtil.getWebXmlParam("pdaweb.mysqlDBPrefix");
    core_mysqlUser = (String) FacesUtil.getWebXmlParam("pdaweb.mysqlUser");
    core_mysqlParams =
        StringUtils.noNull((String) FacesUtil.getWebXmlParam("pdaweb.mysqlParams"))
            .replaceAll("$", "&");
    String tmp = (String) FacesUtil.getWebXmlParam("pdaweb.mysqlPwd");
    tmp = StringUtils.noNull(tmp).trim();
    core_mysqlPasswd = tmp;
    osName = System.getProperty("os.name");

    // Initialize main database it is initialized with the PREFIX database name
    // Then we switch to the current year using setCatalog(dbThisYear);
    startFitxesDB();

    // And constructs the configMap from database
    // This has been updated since now reads info from the PREFIX database
    // and not from year to year
    readDatabaseCfg();

    lastLogins = new ArrayList<String>();

    initializeSGD();
  }
Пример #2
0
  /**
   * updated to read from the new common database Creates the map containing values of the
   * configuration table in db
   */
  public void readDatabaseCfg() {

    // Populate with default values (this is already done in  ICoreData
    //        configTableMap.put("anyIniciCurs", 2012);
    //        configTableMap.put("sgdDBPrefix", "curso");
    //        configTableMap.put("sgdUser", "root");
    //        configTableMap.put("sgdPasswd", "");
    //        configTableMap.put("sgdHost", "localhost");
    //        configTableMap.put("versionDB", "3.1");
    //        configTableMap.put("minVersion", "3.0");
    //        configTableMap.put("maxDiesAntelacio", 15);
    //        configTableMap.put("refreshTime", 360);
    //        configTableMap.put("adminPwd", "");
    //        configTableMap.put("allowWebAdmin", false);
    //        configTableMap.put("prefPwd", "");
    //        configTableMap.put("guardPwd", "");
    //        configTableMap.put("idObservAcumulAL", -1);
    //        configTableMap.put("pdawebSU", "");
    //        configTableMap.put("simbolCastigDimecres", "CD");
    //        configTableMap.put("sgdEnableLogger", false);
    //        configTableMap.put("simbolAmonLleu", "AL");
    //        configTableMap.put("simbolAmonLleuHist", "ALH");
    //        configTableMap.put("simbolAmonGreu", "AG");
    //        configTableMap.put("simbolExpulsio", "EX");
    //        configTableMap.put("hardJustificacio", false);
    //        configTableMap.put("enableRegSystemInfo", false);

    if (getMysql().isClosed()) {
      return;
    } // do nothing if there is no connection

    String SQL = "SELECT property, value, castTo FROM `" + core_mysqlDBPrefix + "`.configuracio";
    try {
      Statement st = getMysql().createStatement();
      ResultSet rs = getMysql().getResultSet(SQL, st);
      while (rs != null && rs.next()) {
        String str = StringUtils.noNull(rs.getString("value")).trim();
        Object obj;
        String type = StringUtils.noNull(rs.getString("castTo")).trim();
        if (type.equalsIgnoreCase("int")) {
          int parsed = Integer.parseInt(str);
          obj = new Integer(parsed);
        } else if (type.equalsIgnoreCase("Boolean")) {
          if (str.equalsIgnoreCase("true")
              || str.equalsIgnoreCase("yes")
              || str.equalsIgnoreCase("y")) {
            obj = true;
          } else {
            obj = false;
          }
        } else {
          obj = str;
        }

        configTableMap.put(rs.getString("property"), obj);
      }
      if (rs != null) {
        rs.close();
        st.close();
      }
    } catch (SQLException ex) {
      Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
    }

    // From now on choose the correct database as default
    if (configTableMap != null && configTableMap.containsKey("anyIniciCurs")) {

      // Create Alias for the most used variables

      coreDB_sgdHost = (String) configTableMap.get("sgdHost");
      coreDB_sgdUser = (String) configTableMap.get("sgdUser");
      coreDB_sgdPasswd = (String) configTableMap.get("sgdPasswd");
      coreDB_sgdParams = (String) configTableMap.get("sgdDBParams");
      coreDB_sgdDB =
          (String) configTableMap.get("sgdDBPrefix") + configTableMap.get("anyIniciCurs");
      core_pwdSU = (String) configTableMap.get("adminPwd");

      core_pwdPREF = (String) configTableMap.get("prefPwd");
      core_pwdGUARD = (String) configTableMap.get("guardPwd");

      int any = (Integer) configTableMap.get("anyIniciCurs");
      core_mysqlDB = core_mysqlDBPrefix + any;

      getMysql().setCatalog(core_mysqlDB);
      anyAcademic = any;
    }
  }