Search in sources :

Example 56 with GradingFactorException

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

the class QuizDaoImpl method getQuizListByStudentId.

@Override
public List<Quiz> getQuizListByStudentId(long studentId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Student student = session.get(Student.class, studentId);
        Term term = session.get(Term.class, termId);
        List<Quiz> quizList = new ArrayList<>();
        String hql = "from QuizResult as R join R.quiz as A where R.student.id = :studentId and " + "A.term.id = :termId";
        if (term == null)
            throw new GradingFactorDaoException("Quiz's term with id : " + termId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Quiz's student with id : " + studentId + " does not exist");
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        query.setParameter("termId", termId);
        for (Object object : query.list()) quizList.add((Quiz) ((Object[]) object)[1]);
        session.getTransaction().commit();
        session.close();
        return quizList;
    } 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 57 with GradingFactorException

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

the class QuizDaoImpl method getQuizList.

@Override
public List<Quiz> getQuizList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Quiz> quizList = new ArrayList<>();
        Query query = session.createQuery("from Quiz");
        for (Object objQuiz : query.list()) quizList.add((Quiz) objQuiz);
        session.getTransaction().commit();
        session.close();
        return quizList;
    } 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 58 with GradingFactorException

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

the class QuizDaoImpl method updateQuizResultByQuizAndStudentId.

@Override
public QuizResult updateQuizResultByQuizAndStudentId(int score, long quizId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Quiz quiz = session.get(Quiz.class, quizId);
        Student student = session.get(Student.class, studentId);
        String hql = "from QuizResult as R where R.quiz.id = :quizId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("quizId", quizId);
        query.setParameter("studentId", studentId);
        if (quiz == null)
            throw new GradingFactorDaoException("Quiz's quiz with id : " + quizId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Quiz's student with id : " + studentId + " does not exist");
        if (quizId < 1)
            throw new GradingFactorDaoException("Query param : quizId 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");
        QuizResult result = (QuizResult) 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 59 with GradingFactorException

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

the class QuizDaoImpl method getQuizById.

@Override
public Quiz getQuizById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Quiz quiz = session.get(Quiz.class, id);
        if (quiz == null)
            throw new GradingFactorDaoException("Quiz with id : " + id + " does not exist");
        session.getTransaction().commit();
        session.close();
        return quiz;
    } 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)

Example 60 with GradingFactorException

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

the class QuizDaoImpl method getQuizListByClassId.

@Override
public List<Quiz> getQuizListByClassId(long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Quiz> quizList = new ArrayList<>();
        Query query = session.createQuery("from Quiz where _class.id = :classId");
        query.setParameter("classId", classId);
        for (Object objQuiz : query.list()) quizList.add((Quiz) objQuiz);
        session.getTransaction().commit();
        session.close();
        return quizList;
    } 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)

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