Search in sources :

Example 81 with GradingFactorException

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

the class AssignmentDaoImpl method getAssignmentList.

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

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

the class AttendanceDaoImpl method getAttendanceListByStudentId.

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

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

the class AttendanceDaoImpl method updateAttendanceResultByAttendanceAndStudentId.

@Override
public AttendanceResult updateAttendanceResultByAttendanceAndStudentId(int status, long attendanceId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Attendance attendance = session.get(Attendance.class, attendanceId);
        Student student = session.get(Student.class, studentId);
        String hql = "from AttendanceResult as R where R.attendance.id = :attendanceId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("attendanceId", attendanceId);
        query.setParameter("studentId", studentId);
        if (attendance == null)
            throw new GradingFactorDaoException("Attendance's attendance with id : " + attendanceId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Attendance's student with id : " + studentId + " does not exist");
        if (attendanceId < 1)
            throw new GradingFactorDaoException("Query param : attendanceId 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");
        AttendanceResult result = (AttendanceResult) query.list().get(0);
        result.setStatus(status);
        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 84 with GradingFactorException

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

the class AttendanceDaoImpl method deleteAttendanceById.

@Override
public Attendance deleteAttendanceById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        String[] table = new String[1];
        table[0] = AttendanceResult.class.getSimpleName();
        Attendance attendance = session.get(Attendance.class, id);
        if (attendance == null)
            throw new GradingFactorDaoException("Attendance with id : " + id + " does not exist");
        for (String cell : table) {
            String hql = "delete from ".concat(cell).concat(" where attendance.id = :attendanceId");
            Query query = session.createQuery(hql);
            query.setParameter("attendanceId", id);
            query.executeUpdate();
        }
        session.delete(attendance);
        session.getTransaction().commit();
        session.close();
        return attendance;
    } 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 85 with GradingFactorException

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

the class ActivityDaoImpl method updateActivityById.

@Override
public Activity updateActivityById(long id, Activity newActivity, long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Activity activity = session.get(Activity.class, id);
        Class _class = session.get(Class.class, classId);
        Term term = session.get(Term.class, termId);
        if (newActivity == null)
            newActivity = new Activity();
        if (activity == null)
            throw new GradingFactorDaoException("Activity with id : " + id + " does not exist");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Activity's class with id : " + classId + " does not exist");
        if (term == null && termId > 0)
            throw new GradingFactorDaoException("Activity's term with id : " + termId + " does not exist");
        if (!(newActivity.getTitle() != null ? newActivity.getTitle() : "").trim().isEmpty())
            activity.setTitle(newActivity.getTitle());
        if (!(newActivity.getDate() != null ? newActivity.getDate() : "").trim().isEmpty())
            activity.setDate(newActivity.getDate());
        if (classId > 0) {
            if (classId == (activity.get_class() != null ? activity.get_class().getId() : 0))
                throw new GradingFactorDaoException("Activity's  class with id : " + classId + " already exist");
            activity.set_class(_class);
        }
        if (termId > 0) {
            if (termId != (activity.getTerm() != null ? activity.getTerm().getId() : 0))
                activity.setTerm(term);
        }
        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)

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