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();
}
}
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());
}
}
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());
}
}
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());
}
}
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());
}
}
Aggregations