Search in sources :

Example 66 with GradingFactorException

use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.

the class QuizDaoImpl method deleteQuizById.

@Override
public Quiz deleteQuizById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        String[] table = new String[1];
        table[0] = QuizResult.class.getSimpleName();
        Quiz quiz = session.get(Quiz.class, id);
        if (quiz == null)
            throw new GradingFactorDaoException("Quiz with id : " + id + " does not exist");
        for (String cell : table) {
            String hql = "delete from ".concat(cell).concat(" where quiz.id = :quizId");
            Query query = session.createQuery(hql);
            query.setParameter("quizId", id);
            query.executeUpdate();
        }
        session.delete(quiz);
        session.getTransaction().commit();
        session.close();
        return quiz;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 67 with GradingFactorException

use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.

the class ExamDaoImpl method getExamListByStudentId.

@Override
public List<Exam> getExamListByStudentId(long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Student student = session.get(Student.class, studentId);
        List<Exam> examList = new ArrayList<>();
        String hql = "from ExamResult as R join R.exam where R.student.id = :studentId";
        if (student == null)
            throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        for (Object object : query.list()) examList.add((Exam) ((Object[]) object)[1]);
        session.getTransaction().commit();
        session.close();
        return examList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 68 with GradingFactorException

use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.

the class ExamDaoImpl method deleteExamResultByExamAndStudentId.

@Override
public ExamResult deleteExamResultByExamAndStudentId(long examId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Exam exam = session.get(Exam.class, examId);
        Student student = session.get(Student.class, studentId);
        String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("examId", examId);
        query.setParameter("studentId", studentId);
        if (exam == null)
            throw new GradingFactorDaoException("Exam's exam with id : " + examId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
        if (examId < 1)
            throw new GradingFactorDaoException("Query param : examId is required");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required");
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("No result to delete");
        ExamResult result = (ExamResult) query.list().get(0);
        session.delete(result);
        session.getTransaction().commit();
        session.close();
        return result;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 69 with GradingFactorException

use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.

the class ExamDaoImpl method updateExamResultByExamAndStudentId.

@Override
public ExamResult updateExamResultByExamAndStudentId(int score, long examId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Exam exam = session.get(Exam.class, examId);
        Student student = session.get(Student.class, studentId);
        String hql = "from ExamResult as R where R.exam.id = :examId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("examId", examId);
        query.setParameter("studentId", studentId);
        if (exam == null)
            throw new GradingFactorDaoException("Exam's exam with id : " + examId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Exam's student with id : " + studentId + " does not exist");
        if (examId < 1)
            throw new GradingFactorDaoException("Query param : examId is required");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required");
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("No result to delete");
        ExamResult result = (ExamResult) query.list().get(0);
        result.setScore(score);
        session.getTransaction().commit();
        session.close();
        return result;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 70 with GradingFactorException

use of com.remswork.project.alice.exception.GradingFactorException in project classify-system by anverliedoit.

the class ExamDaoImpl method getExamResultById.

@Override
public ExamResult getExamResultById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        ExamResult result = session.get(ExamResult.class, id);
        if (result == null)
            throw new GradingFactorDaoException("ExamResult with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return result;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Aggregations

GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)302 Message (com.remswork.project.alice.model.support.Message)178 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)104 Session (org.hibernate.Session)104 AsyncTask (android.os.AsyncTask)102 Gson (com.google.gson.Gson)102 IOException (java.io.IOException)102 InputStream (java.io.InputStream)102 HttpURLConnection (java.net.HttpURLConnection)102 URL (java.net.URL)102 ExecutionException (java.util.concurrent.ExecutionException)102 ArrayList (java.util.ArrayList)71 Query (org.hibernate.Query)64 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)35 JSONArray (org.json.JSONArray)32 JSONException (org.json.JSONException)32 Grade (com.remswork.project.alice.model.Grade)25 BufferedWriter (java.io.BufferedWriter)21 OutputStream (java.io.OutputStream)21 OutputStreamWriter (java.io.OutputStreamWriter)21