Search in sources :

Example 16 with Section

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

the class TeacherController method getTeacherAndView.

@RequestMapping(value = "view", method = RequestMethod.GET)
public String getTeacherAndView(@RequestParam("id") long id, ModelMap modelMap) {
    try {
        Teacher teacher = teacherService.getTeacherById(id);
        List<com.remswork.project.alice.model.Class> classList = classService.getClassListByTeacherId(id);
        List<Subject> subjectList = subjectService.getSubjectListByTeacherId(id);
        List<Subject> allSubject = subjectService.getSubjectList();
        List<Section> sectionList = sectionService.getSectionList();
        modelMap.put("teacher", teacher);
        modelMap.put("cclassList", classList);
        modelMap.put("subjectList", subjectList);
        modelMap.put("allSubject", allSubject);
        modelMap.put("sectionList", sectionList);
        return "teacher-view";
    } catch (TeacherException | ClassException | SubjectException | SectionException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Teacher(com.remswork.project.alice.model.Teacher) Section(com.remswork.project.alice.model.Section) Subject(com.remswork.project.alice.model.Subject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Section

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

the class SectionServiceImpl method updateSectionById.

@Override
public Section updateSectionById(long id, Section newSection, long departmentId) throws SectionException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(id);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Builder builder = target.queryParam("departmentId", departmentId).request();
        builder.accept("application/json");
        Response response = builder.put(Entity.json(newSection));
        if (response.getStatus() == 200) {
            return (Section) response.readEntity(Section.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Example 18 with Section

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

the class SectionServiceImpl method addSection.

@Override
public Section addSection(Section Section, long departmentId) throws SectionException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Builder builder = target.queryParam("departmentId", departmentId).request();
        builder.accept("application/json");
        Response response = builder.post(Entity.json(Section));
        if (response.getStatus() == 201) {
            return (Section) response.readEntity(Section.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Example 19 with Section

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

the class SectionServiceImpl method getSectionById.

@Override
public Section getSectionById(long id) throws SectionException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(id);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.request().get();
        if (response.getStatus() == 200) {
            return (Section) response.readEntity(Section.class);
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SectionServiceException(message.getMessage());
        } else
            throw new SectionServiceException("The request might invalid or server is down");
    } catch (SectionServiceException e) {
        throw new SectionException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) SectionServiceException(com.remswork.project.alice.web.service.exception.SectionServiceException)

Example 20 with Section

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

the class StudentResource method addStudent.

@POST
public Response addStudent(Student student) {
    try {
        StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
        SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
        DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
        student = studentService.addStudent(student, sectionId);
        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()));
        }
        return Response.status(Response.Status.CREATED).entity(student).build();
    } catch (StudentException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).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) Section(com.remswork.project.alice.model.Section) SectionResourceLinks(com.remswork.project.alice.resource.links.SectionResourceLinks)

Aggregations

Section (com.remswork.project.alice.model.Section)27 SectionException (com.remswork.project.alice.exception.SectionException)20 Message (com.remswork.project.alice.model.support.Message)15 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)9 SectionResourceLinks (com.remswork.project.alice.resource.links.SectionResourceLinks)9 StudentException (com.remswork.project.alice.exception.StudentException)8 Student (com.remswork.project.alice.model.Student)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 DepartmentException (com.remswork.project.alice.exception.DepartmentException)5 Department (com.remswork.project.alice.model.Department)5 StudentResourceLinks (com.remswork.project.alice.resource.links.StudentResourceLinks)5 SectionServiceException (com.remswork.project.alice.web.service.exception.SectionServiceException)5 Client (javax.ws.rs.client.Client)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5 Session (org.hibernate.Session)5 SectionDaoException (com.remswork.project.alice.dao.exception.SectionDaoException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 ClientBuilder (javax.ws.rs.client.ClientBuilder)3