Search in sources :

Example 46 with GradingFactorException

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

the class RecitationDaoImpl method getRecitationResultByRecitationAndStudentId.

@Override
public RecitationResult getRecitationResultByRecitationAndStudentId(long recitationId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Recitation recitation = session.get(Recitation.class, recitationId);
        Student student = session.get(Student.class, studentId);
        String hql = "from RecitationResult as R where R.recitation.id = :recitationId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("recitationId", recitationId);
        query.setParameter("studentId", studentId);
        if (recitation == null)
            throw new GradingFactorDaoException("Recitation with id : " + recitationId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Recitation's student with id : " + studentId + " does not exist");
        if (query.list().size() < 1)
            throw new GradingFactorDaoException("No RecitationResult found. Try use query param " + "(ex. studentId=[id])");
        RecitationResult result = (RecitationResult) 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 47 with GradingFactorException

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

the class RecitationDaoImpl method addRecitationResult.

@Override
public RecitationResult addRecitationResult(int score, long recitationId, long studentId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Recitation recitation = session.get(Recitation.class, recitationId);
        Student student = session.get(Student.class, studentId);
        RecitationResult result = new RecitationResult();
        String hql = "from RecitationResult as R where R.recitation.id = :recitationId and R.student.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("recitationId", recitationId);
        query.setParameter("studentId", studentId);
        if (recitation == null)
            throw new GradingFactorDaoException("Recitation's recitation with id : " + recitationId + " does not exist");
        if (student == null)
            throw new GradingFactorDaoException("Recitation's student with id : " + studentId + " does not exist");
        if (recitationId < 1)
            throw new GradingFactorDaoException("Query param : recitationId is required");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required");
        if (score < 0 && score > recitation.getItemTotal())
            throw new GradingFactorDaoException("RecitationResult's score is invalid");
        if (query.list().size() > 0)
            throw new GradingFactorDaoException("RecitationResult's  student with id : " + studentId + " already exist");
        result.setScore(score);
        result.setRecitation(recitation);
        result.setStudent(student);
        session.persist(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 48 with GradingFactorException

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

the class ExamDaoImpl method updateExamById.

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

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

the class FormulaDaoImpl method getFormulaList.

@Override
public List<Formula> getFormulaList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Formula> formulaList = new ArrayList<>();
        Query query = session.createQuery("from Formula");
        for (Object objFormula : query.list()) formulaList.add((Formula) objFormula);
        session.getTransaction().commit();
        session.close();
        return formulaList;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Formula(com.remswork.project.alice.model.Formula) 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 50 with GradingFactorException

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

the class GradeDaoImpl method addGrade.

@Override
public Grade addGrade(Grade grade, long classId, long studentId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Student student = session.get(Student.class, studentId);
        Term term = session.get(Term.class, termId);
        if (grade == null)
            throw new GradingFactorDaoException("You tried to add grade with a null value");
        if (grade.getTotalScore() < 0)
            throw new GradingFactorDaoException("Grade's total score is not valid");
        if (grade.getActivityScore() < 0)
            throw new GradingFactorDaoException("Grade's activity score is not valid");
        if (grade.getAssignmentScore() < 0)
            throw new GradingFactorDaoException("Grade's assignment score is not valid");
        if (grade.getAttendanceScore() < 0)
            throw new GradingFactorDaoException("Grade's attendance score is not valid");
        if (grade.getExamScore() < 0)
            throw new GradingFactorDaoException("Grade's exam score is not valid");
        if (grade.getProjectScore() < 0)
            throw new GradingFactorDaoException("Grade's project score is not valid");
        if (grade.getQuizScore() < 0)
            throw new GradingFactorDaoException("Grade's quiz score is not valid");
        if (classId < 1)
            throw new GradingFactorDaoException("Query param : classId is required.");
        if (studentId < 1)
            throw new GradingFactorDaoException("Query param : studentId is required.");
        if (termId < 1)
            throw new GradingFactorDaoException("Query param : termId is required.");
        if (_class == null)
            throw new GradingFactorDaoException("Class with id : " + classId + " doesn't exist.");
        if (student == null)
            throw new GradingFactorDaoException("Student with id : " + studentId + " doesn't exist.");
        if (term == null)
            throw new GradingFactorDaoException("Term with id : " + termId + " doesn't exist.");
        grade.set_class(_class);
        grade.setStudent(student);
        grade.setTerm(term);
        session.persist(grade);
        session.getTransaction().commit();
        session.close();
        return grade;
    } 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) Term(com.remswork.project.alice.model.Term) Student(com.remswork.project.alice.model.Student) 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