public class TestConstructor {
  static DAOFactory mysqlFactory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);

  public static void addNewTest(String nameTestVal, int subjectIdValue)
      throws ClassNotFoundException {
    TestDAO newTest = mysqlFactory.getTestDAO();
    newTest.insertTest(nameTestVal, subjectIdValue);
  }

  public static void addNewTestSpecif(int testIdVal, int[] questionIdListVal)
      throws ClassNotFoundException {
    TestSpecifDAO newTestSpec = mysqlFactory.getTestSpecifDAO();
    newTestSpec.insertTestSpecif(testIdVal, questionIdListVal);
  }

  public static int getTestId(String nameTestVal) throws ClassNotFoundException {

    TestDAO tempTest = mysqlFactory.getTestDAO();
    return tempTest.findTest(nameTestVal).getTestId();
  }

  public static List<Question> getQuestion(int subjectIdVal) throws ClassNotFoundException {

    QuestionDAO tempQuestList = mysqlFactory.getQuestionDAO();
    return tempQuestList.selectQuestionTO(subjectIdVal);
  }
}
public class ResultManager {
  static DAOFactory mysqlFactory = DAOFactory.getDAOFactory(DAOFactory.MYSQL);

  public static void addTestResult(int idStudent, int idTest, double result)
      throws ClassNotFoundException {

    ResultDAO setResult = mysqlFactory.getResultDAO();
    setResult.insertResult(idStudent, idTest, result);
  }

  public static List<Result> getAllResults() throws ClassNotFoundException {

    ResultDAO results = mysqlFactory.getResultDAO();
    return results.selectAll();
  }

  public static List<Result> getStudentResults(int idStudent) throws ClassNotFoundException {

    ResultDAO results = mysqlFactory.getResultDAO();
    return results.selectByStudent(idStudent);
  }

  public static String getStudentName(int studentId) throws ClassNotFoundException {
    StudentDAO tempStudent = mysqlFactory.getStudentDAO();
    Student currStudent = tempStudent.getStudentById(studentId);
    String outputLine = currStudent.getLastName() + " " + currStudent.getFirstName();
    return outputLine;
  }

  public static String getTestName(int idTest) throws ClassNotFoundException {
    TestDAO tempTest = mysqlFactory.getTestDAO();
    return tempTest.getTestNameById(idTest);
  }
}
  public static boolean addUser(
      String login,
      String password,
      String lastname,
      String firstname,
      String accesstype,
      String role)
      throws UnsupportedEncodingException, ClassNotFoundException {

    boolean additionResult = false;

    if (role.equals(Resource.getJspParams("param.register.usertype.tutor"))) {
      String currPost = "";
      for (int i = 0; i < 4; i++) {
        if (accesstype.equals(Resource.getJspParams("param.testcreate.avar") + i)) {
          currPost =
              new String(
                  Resource.getJspParams("param.register.accesoryvar" + (i + 1) + ".tutor")
                      .getBytes("ISO-8859-1"),
                  "UTF-8");
        }
      }
      TutorDAO currentTutor = mysqlFactory.getTutorDAO();
      additionResult = currentTutor.insertTutor(lastname, firstname, currPost, login, password);
    } else if (role.equals(Resource.getJspParams("param.register.usertype.student"))) {
      String currGroup = "";
      for (int i = 0; i < 4; i++) {
        if (accesstype.equals(Resource.getJspParams("param.testcreate.avar") + i)) {
          currGroup =
              new String(
                  Resource.getJspParams("param.register.accesoryvar" + (i + 1) + ".student")
                      .getBytes("ISO-8859-1"),
                  "UTF-8");
        }
      }
      StudentDAO currentStudent = mysqlFactory.getStudentDAO();
      additionResult =
          currentStudent.insertStudent(lastname, firstname, currGroup, login, password);
    }
    return additionResult;
  }
 public static String getTestName(int idTest) throws ClassNotFoundException {
   TestDAO tempTest = mysqlFactory.getTestDAO();
   return tempTest.getTestNameById(idTest);
 }
 public static String getStudentName(int studentId) throws ClassNotFoundException {
   StudentDAO tempStudent = mysqlFactory.getStudentDAO();
   Student currStudent = tempStudent.getStudentById(studentId);
   String outputLine = currStudent.getLastName() + " " + currStudent.getFirstName();
   return outputLine;
 }
  public static List<Result> getStudentResults(int idStudent) throws ClassNotFoundException {

    ResultDAO results = mysqlFactory.getResultDAO();
    return results.selectByStudent(idStudent);
  }
  public static List<Result> getAllResults() throws ClassNotFoundException {

    ResultDAO results = mysqlFactory.getResultDAO();
    return results.selectAll();
  }
  public static void addTestResult(int idStudent, int idTest, double result)
      throws ClassNotFoundException {

    ResultDAO setResult = mysqlFactory.getResultDAO();
    setResult.insertResult(idStudent, idTest, result);
  }
  public static List<Question> getQuestion(int subjectIdVal) throws ClassNotFoundException {

    QuestionDAO tempQuestList = mysqlFactory.getQuestionDAO();
    return tempQuestList.selectQuestionTO(subjectIdVal);
  }
  public static int getTestId(String nameTestVal) throws ClassNotFoundException {

    TestDAO tempTest = mysqlFactory.getTestDAO();
    return tempTest.findTest(nameTestVal).getTestId();
  }
 public static void addNewTestSpecif(int testIdVal, int[] questionIdListVal)
     throws ClassNotFoundException {
   TestSpecifDAO newTestSpec = mysqlFactory.getTestSpecifDAO();
   newTestSpec.insertTestSpecif(testIdVal, questionIdListVal);
 }
 public static void addNewTest(String nameTestVal, int subjectIdValue)
     throws ClassNotFoundException {
   TestDAO newTest = mysqlFactory.getTestDAO();
   newTest.insertTest(nameTestVal, subjectIdValue);
 }