Search in sources :

Example 61 with GradingFactorException

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

the class RecitationDaoImpl method getRecitationResultById.

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

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

the class ProjectDaoImpl method addProject.

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

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

the class ProjectDaoImpl method getProjectListByClassId.

@Override
public List<Project> getProjectListByClassId(long classId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Project> projectList = new ArrayList<>();
        Query query = session.createQuery("from Project where _class.id = :classId");
        query.setParameter("classId", classId);
        for (Object objProject : query.list()) projectList.add((Project) objProject);
        session.getTransaction().commit();
        session.close();
        return projectList;
    } 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 64 with GradingFactorException

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

the class QuizDaoImpl method getQuizResultById.

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

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

the class QuizDaoImpl method getQuizResultByQuizAndStudentId.

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