Search in sources :

Example 76 with GradingFactorException

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

the class AttendanceDaoImpl method updateAttendanceById.

@Override
public Attendance updateAttendanceById(long id, Attendance newAttendance, long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Attendance attendance = session.get(Attendance.class, id);
        Class _class = session.get(Class.class, classId);
        if (newAttendance == null)
            newAttendance = new Attendance();
        if (attendance == null)
            throw new GradingFactorDaoException("Attendance with id : " + id + " does not exist");
        if (_class == null && classId != 0)
            throw new GradingFactorDaoException("Attendance's class with id : " + classId + " does not exist");
        if (!(newAttendance.getTitle() != null ? newAttendance.getTitle() : "").trim().isEmpty())
            attendance.setTitle(newAttendance.getTitle());
        if (!(newAttendance.getDate() != null ? newAttendance.getDate() : "").trim().isEmpty())
            attendance.setDate(newAttendance.getDate());
        if (classId > 0) {
            if (classId == (attendance.get_class() != null ? attendance.get_class().getId() : 0))
                throw new GradingFactorDaoException("Attendance's  class with id : " + classId + " already exist");
            attendance.set_class(_class);
        }
        session.getTransaction().commit();
        session.close();
        return attendance;
    } 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 77 with GradingFactorException

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

the class ActivityDaoImpl method getActivityListByStudentId.

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

Example 78 with GradingFactorException

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

the class ActivityDaoImpl method updateActivityResultByActivityAndStudentId.

@Override
public ActivityResult updateActivityResultByActivityAndStudentId(int score, 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 update");
        ActivityResult result = (ActivityResult) 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 79 with GradingFactorException

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

the class AssignmentDaoImpl method getAssignmentById.

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

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

the class AssignmentDaoImpl method deleteAssignmentById.

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

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