Search in sources :

Example 46 with GradingFactorDaoException

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

the class ActivityDaoImpl method deleteActivityResultByActivityAndStudentId.

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

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

the class ActivityDaoImpl method addActivity.

@Override
public Activity addActivity(Activity activity, long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        if (activity == 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("Activity's class with id : " + classId + " does not exist");
        if (activity.getTitle() == null)
            throw new GradingFactorDaoException("Activity's title is required");
        if (activity.getTitle().trim().equals(""))
            throw new GradingFactorDaoException("Activity can't have an empty title");
        if (activity.getDate() == null)
            throw new GradingFactorDaoException("Activity's date is required");
        if (activity.getDate().trim().equals(""))
            throw new GradingFactorDaoException("Activity can't have an empty date");
        if (activity.getItemTotal() < 0)
            throw new GradingFactorDaoException("Activity's itemTotal is invalid");
        activity.set_class(_class);
        session.persist(activity);
        session.getTransaction().commit();
        session.close();
        return activity;
    } 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 48 with GradingFactorDaoException

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

the class AssignmentDaoImpl method getAssignmentResultById.

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

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

the class AssignmentDaoImpl method deleteAssignmentResultByAssignmentAndStudentId.

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

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

the class ActivityDaoImpl method getActivityList.

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

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