Example #1
0
  @SuppressWarnings("static-access")
  public String addDatabaseSqlServer(
      String ip,
      String hostname,
      String dbInstance,
      String username,
      String password,
      String dbVendor,
      String dbName) {

    if (dbVendor.toUpperCase().equals("SQLSERVER")) {
      database.setQueryDate("SELECT GETDATE();");
      database.setPort(1433);
      database.setIp(ip);
      database.setHostname(hostname);
      database.setDb_name(dbName);
      database.setUser(username);
      database.setVendor(dbVendor.toUpperCase());
      database.setStatus("NOK");
      database.setTrClass("error");
      database.setInstance(dbInstance);

      try {
        // Encrypting the password
        database.setPass(encodePass.encode(password));
      } catch (Exception e) {
        log.severe("{REST} Error: " + e);
      }

      try {
        log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Adding database: " + hostname);
        if (this.databaseDAO.insert_dataBase(database) == 0) {
          log.info("{REST} DataBase " + database.getHostname() + " was sucessfully registred.");
          return "SUCCESS";
        } else {
          log.info(
              "{REST} DataBase "
                  + database.getHostname()
                  + " was not registred because it already exists.");
          return "DataBase "
              + database.getHostname()
              + " was not registred because it already exists.";
        }
      } catch (Exception e) {
        e.printStackTrace();
        return "FAIL, check logs for details";
      }
    } else {
      log.warning(
          " [ " + userInfo.getLoggedUsername() + " ]{REST} -> This method only allows SqlServer ");
      return "FAIL, check logs for details";
    }
  }
Example #2
0
  @SuppressWarnings("static-access")
  public String addDatabase(
      String ip,
      String hostname,
      String dbInstance,
      String username,
      String password,
      String dbVendor) {

    if (dbVendor.toUpperCase().equals("MYSQL")) {
      database.setQueryDate("SELECT NOW() AS date;");
    }
    if (dbVendor.toUpperCase().equals("ORACLE")) {
      database.setQueryDate("select sysdate from dual");
    }
    if (dbVendor.toUpperCase().equals("SQLSERVER")) {
      database.setQueryDate("SELECT GETDATE();");
    }
    if (dbVendor.toUpperCase().equals("POSTGRESQL")) {
      database.setQueryDate("SELECT now();");
    }
    if (dbVendor.toUpperCase().equals("DB2")) {
      database.setQueryDate(
          "select VARCHAR_FORMAT(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MM:SS') FROM SYSIBM.SYSDUMMY1");
    }

    if (dbVendor.toUpperCase().equals("MYSQL")) {
      database.setPort(3306);
    }
    if (dbVendor.toUpperCase().equals("ORACLE")) {
      database.setPort(1521);
    }
    if (dbVendor.toUpperCase().equals("SQLSERVER")) {
      database.setPort(1433);
    }
    if (dbVendor.toUpperCase().equals("POSTGRESQL")) {
      database.setPort(5432);
    }
    if (dbVendor.toUpperCase().equals("DB2")) {
      database.setPort(50000);
    }

    database.setIp(ip);
    database.setHostname(hostname);
    database.setDb_name(dbInstance);
    database.setUser(username);
    database.setVendor(dbVendor.toUpperCase());
    database.setStatus("NOK");
    database.setTrClass("error");
    database.setInstance(dbInstance);

    try {
      // Encrypting the password
      database.setPass(encodePass.encode(password));
    } catch (Exception e) {
      log.severe("{REST} Error: " + e);
    }

    try {
      log.info(" [ " + userInfo.getLoggedUsername() + " ]{REST} -> Adding database: " + hostname);
      if (this.databaseDAO.insert_dataBase(database) == 0) {
        log.info("{REST} DataBase " + database.getHostname() + " was sucessfully registred.");
        return "SUCCESS";
      } else {
        log.info(
            "{REST} DataBase "
                + database.getHostname()
                + " was not registred because it already exists.");
        return "DataBase "
            + database.getHostname()
            + " was not registred because it already exists.";
      }

    } catch (Exception e) {
      e.printStackTrace();
      return "FAIL, check logs for details";
    }
  }