Search in sources :

Example 6 with SubjectException

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

the class SubjectDaoImpl method getSubjectList.

@Override
public List<Subject> getSubjectList() throws SubjectException {
    List<Subject> subjectList = new ArrayList<>();
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Query query = session.createQuery("from Subject");
        for (Object subjectObj : query.list()) subjectList.add((Subject) subjectObj);
        session.getTransaction().commit();
        session.close();
        return subjectList;
    } catch (SubjectDaoException e) {
        session.close();
        throw new SubjectException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) SubjectDaoException(com.remswork.project.alice.dao.exception.SubjectDaoException) ArrayList(java.util.ArrayList) SubjectException(com.remswork.project.alice.exception.SubjectException) Session(org.hibernate.Session)

Example 7 with SubjectException

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

the class SubjectDaoImpl method addSubject.

@Override
public Subject addSubject(Subject subject) throws SubjectException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        if (subject == null)
            throw new SubjectDaoException("You tried to add subject with a null value");
        if (subject.getName() == null)
            throw new SubjectDaoException("SubjectDto's name is required");
        if (subject.getName().trim().equals(""))
            throw new SubjectDaoException("SubjectDto can't have an empty name");
        if (subject.getDescription() == null)
            throw new SubjectDaoException("SubjectDto's description is required");
        if (subject.getDescription().trim().equals(""))
            throw new SubjectDaoException("SubjectDto can't have an empty description");
        if (subject.getCode() == null)
            throw new SubjectDaoException("SubjectDto's code is required");
        if (subject.getCode().trim().equals(""))
            throw new SubjectDaoException("SubjectDto can't have an empty code");
        if (subject.getUnit() == 0)
            throw new SubjectDaoException("SubjectDto's unit is required");
        if (subject.getUnit() < 0)
            throw new SubjectDaoException("SubjectDto's unit is invalid");
        session.persist(subject);
        session.getTransaction().commit();
        session.close();
        return subject;
    } catch (SubjectDaoException e) {
        session.close();
        throw new SubjectException(e.getMessage());
    }
}
Also used : SubjectDaoException(com.remswork.project.alice.dao.exception.SubjectDaoException) SubjectException(com.remswork.project.alice.exception.SubjectException) Session(org.hibernate.Session)

Example 8 with SubjectException

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

the class SubjectDaoImpl method getSubjectListByTeacherIdUnique.

public List<Subject> getSubjectListByTeacherIdUnique(long teacherId) throws SubjectException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Subject> subjectList = new ArrayList<>();
        String hql = "from Class as c join c.subject as s join c.teacher as t where t.id = :teacherId group by s.id";
        Query query = session.createQuery(hql);
        query.setParameter("teacherId", teacherId);
        for (Object list : query.list()) {
            Object[] row = (Object[]) list;
            subjectList.add((Subject) row[1]);
        }
        session.getTransaction().commit();
        session.close();
        return subjectList;
    } catch (SubjectDaoException e) {
        session.close();
        throw new SubjectException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) SubjectDaoException(com.remswork.project.alice.dao.exception.SubjectDaoException) ArrayList(java.util.ArrayList) SubjectException(com.remswork.project.alice.exception.SubjectException) Session(org.hibernate.Session)

Example 9 with SubjectException

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

the class SubjectDaoImpl method getSubjectListByStudentId.

@Override
public List<Subject> getSubjectListByStudentId(long studentId) throws SubjectException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Subject> subjectList = new ArrayList<>();
        String hql = "from Class as c join c.subject as su join c.studentList as st where st.id = :studentId";
        Query query = session.createQuery(hql);
        query.setParameter("studentId", studentId);
        for (Object list : query.list()) {
            Object[] row = (Object[]) list;
            subjectList.add((Subject) row[1]);
        }
        session.getTransaction().commit();
        session.close();
        return subjectList;
    } catch (SubjectDaoException e) {
        session.close();
        throw new SubjectException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) SubjectDaoException(com.remswork.project.alice.dao.exception.SubjectDaoException) ArrayList(java.util.ArrayList) SubjectException(com.remswork.project.alice.exception.SubjectException) Session(org.hibernate.Session)

Example 10 with SubjectException

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

the class SubjectDaoImpl method getSubjectListByTeacherId.

@Override
public List<Subject> getSubjectListByTeacherId(long teacherId) throws SubjectException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        List<Subject> subjectList = new ArrayList<>();
        String hql = "from Class as c join c.subject as s join c.teacher as t where t.id = :teacherId";
        Query query = session.createQuery(hql);
        query.setParameter("teacherId", teacherId);
        for (Object list : query.list()) {
            Object[] row = (Object[]) list;
            subjectList.add((Subject) row[1]);
        }
        session.getTransaction().commit();
        session.close();
        return subjectList;
    } catch (SubjectDaoException e) {
        session.close();
        throw new SubjectException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) SubjectDaoException(com.remswork.project.alice.dao.exception.SubjectDaoException) ArrayList(java.util.ArrayList) SubjectException(com.remswork.project.alice.exception.SubjectException) Session(org.hibernate.Session)

Aggregations

SubjectException (com.remswork.project.alice.exception.SubjectException)44 Message (com.remswork.project.alice.model.support.Message)27 Subject (com.remswork.project.alice.model.Subject)23 AsyncTask (android.os.AsyncTask)10 Gson (com.google.gson.Gson)10 SubjectDaoException (com.remswork.project.alice.dao.exception.SubjectDaoException)10 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 HttpURLConnection (java.net.HttpURLConnection)10 URL (java.net.URL)10 ArrayList (java.util.ArrayList)10 ExecutionException (java.util.concurrent.ExecutionException)10 Session (org.hibernate.Session)10 SubjectServiceException (com.remswork.project.alice.web.service.exception.SubjectServiceException)9 Client (javax.ws.rs.client.Client)9 WebTarget (javax.ws.rs.client.WebTarget)9 Response (javax.ws.rs.core.Response)9 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)8 Query (org.hibernate.Query)7 List (java.util.List)6