Search in sources :

Example 1 with Student

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

the class ClassStudentListResource method getStudentById.

@GET
@Path("{studentId}")
public Response getStudentById(@PathParam("classId") long classId, @PathParam("studentId") long id) {
    try {
        ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
        Student student = classService.getStudentById(classId, id);
        student.addLink(resourceLinks.self(classId, id));
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (ClassException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Example 2 with Student

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

the class ClassStudentListResource method getStudentList.

@GET
public Response getStudentList(@PathParam("classId") long classId) {
    try {
        ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
        Set<Student> studentSet = classService.getStudentList(classId);
        for (Student student : studentSet) student.addLink(resourceLinks.self(classId, student.getId()));
        GenericEntity<Set<Student>> entity = new GenericEntity<Set<Student>>(studentSet) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (ClassException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Set(java.util.Set) Message(com.remswork.project.alice.model.support.Message) GenericEntity(javax.ws.rs.core.GenericEntity) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Example 3 with Student

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

the class ClassStudentListResource method deleteStudentById.

@DELETE
@Path("{studentId}")
public Response deleteStudentById(@PathParam("classId") long classId, @PathParam("studentId") long id) {
    try {
        ClassStudentListResourceLinks resourceLinks = new ClassStudentListResourceLinks(uriInfo);
        Student student = classService.deleteStudentById(classId, id);
        student.addLink(resourceLinks.self(classId, id));
        return Response.status(Response.Status.OK).entity(student).build();
    } catch (ClassException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : ClassStudentListResourceLinks(com.remswork.project.alice.resource.links.ClassStudentListResourceLinks) Message(com.remswork.project.alice.model.support.Message) ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student)

Example 4 with Student

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

the class StudentResource method getStudentList.

@GET
public Response getStudentList() {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        List<Student> studentList = studentService.getStudentList();
        if (sn == null) {
            for (Student student : studentList) {
                student.addLink(resourceLinks.self(student.getId()));
                if (student.getSection() != null) {
                    Section section = student.getSection();
                    section.addLink(sectionResourceLinks.self(section.getId()));
                    if (section.getDepartment() != null)
                        section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
                }
            }
            GenericEntity<List<Student>> entity = new GenericEntity<List<Student>>(studentList) {
            };
            return Response.status(Response.Status.OK).entity(entity).build();
        } else {
            Student student = studentService.getStudentBySN(sn);
            if (student.getSection() != null) {
                Section section = student.getSection();
                section.addLink(sectionResourceLinks.self(section.getId()));
                if (section.getDepartment() != null) {
                    section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
                }
            }
            return Response.status(Response.Status.OK).entity(student).build();
        }
    } catch (StudentException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Message(com.remswork.project.alice.model.support.Message) StudentResourceLinks(com.remswork.project.alice.resource.links.StudentResourceLinks) DepartmentResourceLinks(com.remswork.project.alice.resource.links.DepartmentResourceLinks) List(java.util.List) Student(com.remswork.project.alice.model.Student) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Example 5 with Student

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

the class SectionDaoImpl method deleteSectionById.

@Override
public Section deleteSectionById(long id) throws SectionException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Section section = session.get(Section.class, id);
        if (section == null)
            throw new SectionDaoException("Section with id : " + id + " does not exist");
        // to avoid the constraints restriction we meed to remove section from the student that having the section
        Query studentQuery = session.createQuery("from Student");
        for (Object studentObj : studentQuery.list()) {
            Student student = (Student) studentObj;
            if (student.getSection() == null)
                continue;
            if (student.getSection().equals(section) || (student.getSection() != null ? student.getSection().getId() : 0) == section.getId()) {
                student.setSection(null);
            }
        }
        // to avoid the constraints restriction we meed to remove section from the class that having the section
        Query classQuery = session.createQuery("from Class");
        for (Object classObj : classQuery.list()) {
            Class _class = (Class) classObj;
            if (_class.getSection() == null)
                continue;
            if (_class.getSection().equals(section) || (_class.getSection() != null ? _class.getSection().getId() : 0) == section.getId()) {
                _class.setSection(null);
            }
        }
        section.setDepartment(null);
        session.delete(section);
        session.getTransaction().commit();
        session.close();
        return section;
    } catch (SectionDaoException e) {
        session.close();
        throw new SectionException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) Class(com.remswork.project.alice.model.Class) Student(com.remswork.project.alice.model.Student) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionDaoException(com.remswork.project.alice.dao.exception.SectionDaoException) Session(org.hibernate.Session)

Aggregations

Student (com.remswork.project.alice.model.Student)82 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)29 CompoundButton (android.widget.CompoundButton)22 Message (com.remswork.project.alice.model.support.Message)21 Grade (com.remswork.project.alice.model.Grade)20 ArrayList (java.util.ArrayList)19 StudentException (com.remswork.project.alice.exception.StudentException)17 CardView (android.support.v7.widget.CardView)15 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)15 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)15 RecyclerView (android.support.v7.widget.RecyclerView)15 View (android.view.View)15 TextView (android.widget.TextView)15 ClassException (com.remswork.project.alice.exception.ClassException)14 Button (android.widget.Button)13 List (java.util.List)13 ToggleButton (android.widget.ToggleButton)11 Client (javax.ws.rs.client.Client)10 WebTarget (javax.ws.rs.client.WebTarget)10 Response (javax.ws.rs.core.Response)10