Search in sources :

Example 21 with GradingFactorDaoException

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

the class ProjectDaoImpl method addProject.

@Override
public Project addProject(Project project, long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        if (project == null)
            throw new GradingFactorDaoException("You tried to add class with a null value");
        if (classId == 0)
            throw new GradingFactorDaoException("Query param : classId is required");
        if (_class == null)
            throw new GradingFactorDaoException("Project's class with id : " + classId + " does not exist");
        if (project.getTitle() == null)
            throw new GradingFactorDaoException("Project's title is required");
        if (project.getTitle().trim().equals(""))
            throw new GradingFactorDaoException("Project can't have an empty title");
        if (project.getDate() == null)
            throw new GradingFactorDaoException("Project's date is required");
        if (project.getDate().trim().equals(""))
            throw new GradingFactorDaoException("Project can't have an empty date");
        if (project.getItemTotal() < 0)
            throw new GradingFactorDaoException("Project's itemTotal is invalid");
        project.set_class(_class);
        session.persist(project);
        session.getTransaction().commit();
        session.close();
        return project;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Class(com.remswork.project.alice.model.Class) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 22 with GradingFactorDaoException

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

the class ProjectDaoImpl method getProjectListByClassId.

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

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

the class QuizDaoImpl method getQuizResultById.

@Override
public QuizResult getQuizResultById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        QuizResult result = session.get(QuizResult.class, id);
        if (result == null)
            throw new GradingFactorDaoException("QuizResult 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)

Example 24 with GradingFactorDaoException

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

the class QuizDaoImpl method getQuizResultByQuizAndStudentId.

@Override
public QuizResult getQuizResultByQuizAndStudentId(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 with id : " + quizId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Quiz's student with id : " + studentId + " does not exist");
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("No QuizResult found. Try use query param " + "(ex. studentId=[id])");
        QuizResult result = (QuizResult) query.list().get(0);
        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 25 with GradingFactorDaoException

use of com.remswork.project.alice.dao.exception.GradingFactorDaoException 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)

Aggregations

GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)104 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)104 Session (org.hibernate.Session)104 Query (org.hibernate.Query)64 ArrayList (java.util.ArrayList)27 Class (com.remswork.project.alice.model.Class)16 Grade (com.remswork.project.alice.model.Grade)7 Formula (com.remswork.project.alice.model.Formula)6 Student (com.remswork.project.alice.model.Student)2 Subject (com.remswork.project.alice.model.Subject)2 Teacher (com.remswork.project.alice.model.Teacher)2 Term (com.remswork.project.alice.model.Term)2