Search in sources :

Example 6 with Term

use of com.remswork.project.alice.model.Term in project classify-system by anverliedoit.

the class TermResource method getTermById.

@GET
@Path("{termId}")
public Response getTermById(@PathParam("termId") long id) {
    try {
        TermResourceLinks resourceLinks = new TermResourceLinks(uriInfo);
        Term term = termService.getTermById(id);
        term.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(term).build();
    } catch (GradingFactorException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).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 7 with Term

use of com.remswork.project.alice.model.Term in project classify-system by anverliedoit.

the class FormulaDaoImpl method updateFormulaById.

@Override
public Formula updateFormulaById(long id, Formula newFormula, long subjectId, long teacherId, long termId) throws GradingFactorException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Formula formula = session.get(Formula.class, id);
        Subject subject = session.get(Subject.class, subjectId);
        Teacher teacher = session.get(Teacher.class, teacherId);
        Term term = session.get(Term.class, termId);
        if (newFormula == null)
            newFormula = new Formula();
        if (formula == null)
            throw new GradingFactorDaoException("Formula with id : " + id + " does not exist");
        if (subject == null && subjectId != 0)
            throw new GradingFactorDaoException("Factor's subject with id : " + subjectId + " does not exist");
        if (teacher == null && teacherId != 0)
            throw new GradingFactorDaoException("Factor's teacher with id : " + teacherId + " does not exist");
        if (term == null && termId != 0)
            throw new GradingFactorDaoException("Factor's term with id : " + termId + " does not exist");
        formula.setActivityPercentage(newFormula.getActivityPercentage());
        formula.setAssignmentPercentage(newFormula.getAssignmentPercentage());
        formula.setAttendancePercentage(newFormula.getAttendancePercentage());
        formula.setExamPercentage(newFormula.getExamPercentage());
        formula.setProjectPercentage(newFormula.getProjectPercentage());
        formula.setQuizPercentage(newFormula.getQuizPercentage());
        formula.setRecitationPercentage(newFormula.getRecitationPercentage());
        if (subjectId > 0) {
            if (subjectId == (formula.getSubject() != null ? formula.getSubject().getId() : 0))
                throw new GradingFactorException("Formula's  subject with id : " + subjectId + " already exist");
            formula.setSubject(subject);
        }
        if (teacherId > 0) {
            if (teacherId == (formula.getTeacher() != null ? formula.getTeacher().getId() : 0))
                throw new GradingFactorException("Formula's  teacher with id : " + teacherId + " already exist");
            formula.setTeacher(teacher);
        }
        if (termId > 0) {
            if (termId == (formula.getTerm() != null ? formula.getTerm().getId() : 0))
                throw new GradingFactorException("Formula's  term with id : " + termId + " already exist");
            formula.setTerm(term);
        }
        session.getTransaction().commit();
        session.close();
        return formula;
    } catch (GradingFactorDaoException e) {
        session.close();
        throw new GradingFactorException(e.getMessage());
    }
}
Also used : Formula(com.remswork.project.alice.model.Formula) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) Teacher(com.remswork.project.alice.model.Teacher) Term(com.remswork.project.alice.model.Term) GradingFactorDaoException(com.remswork.project.alice.dao.exception.GradingFactorDaoException) Subject(com.remswork.project.alice.model.Subject) Session(org.hibernate.Session)

Aggregations

GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)7 Term (com.remswork.project.alice.model.Term)7 Message (com.remswork.project.alice.model.support.Message)5 TermResourceLinks (com.remswork.project.alice.resource.links.TermResourceLinks)4 GradingFactorDaoException (com.remswork.project.alice.dao.exception.GradingFactorDaoException)2 Session (org.hibernate.Session)2 AsyncTask (android.os.AsyncTask)1 Gson (com.google.gson.Gson)1 Class (com.remswork.project.alice.model.Class)1 Formula (com.remswork.project.alice.model.Formula)1 Student (com.remswork.project.alice.model.Student)1 Subject (com.remswork.project.alice.model.Subject)1 Teacher (com.remswork.project.alice.model.Teacher)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1