Search in sources :

Example 41 with GradingFactorException

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

the class TermResource method updateTermById.

@PUT
@Path("{termId}")
public Response updateTermById(@PathParam("termId") long id, Term newTerm) {
    try {
        TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
        Term term = termService.updateTermById(id, newTerm);
        term.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(term).build();
    } catch (GradingFactorException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : TermResourceLinks(com.remswork.project.alice.resource.links.TermResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Term(com.remswork.project.alice.model.Term)

Example 42 with GradingFactorException

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

the class RecitationDaoImpl method getRecitationById.

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

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

the class RecitationDaoImpl method addRecitation.

@Override
public Recitation addRecitation(Recitation recitation, long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Class _class = session.get(Class.class, classId);
        Term term = session.get(Term.class, termId);
        if (recitation == null)
            throw new GradingFactorDaoException("You tried to add class with a null value");
        if (termId < 1)
            throw new GradingFactorDaoException("Query param : termId has an invalid input");
        if (_class == null)
            throw new GradingFactorDaoException("Recitation's class with id : " + classId + " does not exist");
        if (term == null)
            throw new GradingFactorDaoException("Recitation's term with id : " + termId + " does not exist");
        if (recitation.getTitle() == null)
            throw new GradingFactorDaoException("Recitation's title is required");
        if (recitation.getTitle().trim().equals(""))
            throw new GradingFactorDaoException("Recitation can't have an empty title");
        if (recitation.getDate() == null)
            throw new GradingFactorDaoException("Recitation's date is required");
        if (recitation.getDate().trim().equals(""))
            throw new GradingFactorDaoException("Recitation can't have an empty date");
        if (recitation.getItemTotal() < 0)
            throw new GradingFactorDaoException("Recitation's itemTotal is invalid");
        recitation.set_class(_class);
        recitation.setTerm(term);
        session.persist(recitation);
        session.getTransaction().commit();
        session.close();
        return recitation;
    } 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 44 with GradingFactorException

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

the class RecitationDaoImpl method getRecitationList.

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

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

the class RecitationDaoImpl method getRecitationListByClassId.

@Override
public List<Recitation> getRecitationListByClassId(long classId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Recitation> recitationList = new ArrayList<>();
        String hql = "from Recitation where _class.id = :classId and term.id = :termId";
        Query query = session.createQuery(hql);
        query.setParameter("classId", classId);
        query.setParameter("termId", termId);
        for (Object objRecitation : query.list()) recitationList.add((Recitation) objRecitation);
        session.getTransaction().commit();
        session.close();
        return recitationList;
    } 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)

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