Search in sources :

Example 51 with GradingFactorException

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

the class GradeDaoImpl method getGradeList.

@Override
public List<Grade> getGradeList() throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Grade> gradeList = new ArrayList<>();
        Query query = session.createQuery("from Grade");
        for (Object object : query.list()) gradeList.add((Grade) object);
        session.getTransaction().commit();
        session.close();
        return gradeList;
    } 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) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 52 with GradingFactorException

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

the class GradeDaoImpl method updateGradeById.

@Override
public Grade updateGradeById(long id, Grade newGrade) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Grade grade = session.get(Grade.class, id);
        if (newGrade == null)
            newGrade = new Grade();
        if (grade == null)
            throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
        if (newGrade.getTotalScore() >= 0 && grade.getTotalScore() > 0)
            grade.setTotalScore(newGrade.getTotalScore());
        if (newGrade.getActivityScore() > 0 && grade.getActivityScore() > 0)
            grade.setActivityScore(newGrade.getActivityScore());
        if (newGrade.getAssignmentScore() > 0 && grade.getAssignmentScore() > 0)
            grade.setAssignmentScore(newGrade.getAssignmentScore());
        if (newGrade.getAttendanceScore() > 0 && grade.getAttendanceScore() > 0)
            grade.setAttendanceScore(newGrade.getAttendanceScore());
        if (newGrade.getExamScore() > 0 && grade.getExamScore() > 0)
            grade.setExamScore(newGrade.getExamScore());
        if (newGrade.getProjectScore() > 0 && grade.getProjectScore() > 0)
            grade.setProjectScore(newGrade.getProjectScore());
        if (newGrade.getQuizScore() > 0 && grade.getQuizScore() > 0)
            grade.setQuizScore(newGrade.getQuizScore());
        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) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 53 with GradingFactorException

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

the class GradeDaoImpl method deleteGradeById.

@Override
public Grade deleteGradeById(long id) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Grade grade = session.get(Grade.class, id);
        if (grade == null)
            throw new GradingFactorDaoException("Grade with id : " + id + " doesn't exist.");
        session.delete(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) Grade(com.remswork.project.alice.model.Grade) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Session(org.hibernate.Session)

Example 54 with GradingFactorException

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

the class ProjectDaoImpl method addProjectResult.

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

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

the class ProjectDaoImpl method getProjectResultByProjectAndStudentId.

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

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