Search in sources :

Example 11 with Teacher

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

the class TeacherController method getTeacher.

@RequestMapping(value = "get", method = RequestMethod.POST)
public String getTeacher(@RequestParam("query") String query, ModelMap modelMap) {
    try {
        List<Department> departmentList = departmentService.getDepartmentList();
        List<Teacher> teacherList = new ArrayList<>();
        Teacher teacher = null;
        if (!query.trim().isEmpty()) {
            try {
                long id = Long.parseLong(query.trim());
                teacher = teacherService.getTeacherById(id);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                teacher = null;
            } catch (TeacherException e) {
                e.printStackTrace();
                teacher = null;
            }
            if (teacher != null)
                teacherList.add(teacher);
            else {
                for (Teacher t : teacherService.getTeacherList()) {
                    if (t.getFirstName().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                    if (t.getMiddleName().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                    if (t.getLastName().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                    if (t.getEmail().equals(query.trim())) {
                        teacherList.add(t);
                        continue;
                    }
                }
            }
        }
        if (teacherList.size() < 1) {
            teacherList = teacherService.getTeacherList();
            modelMap.put("responseMessage", "No result found.");
        } else {
            modelMap.put("responseMessage", teacherList.size() + " Result found.");
        }
        modelMap.put("teacherList", teacherList);
        modelMap.put("departmentList", departmentList);
        return "fragment/teacher-table";
    } catch (TeacherException | DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Teacher(com.remswork.project.alice.model.Teacher) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Teacher

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

the class TeacherController method addTeacher.

@RequestMapping(value = "add", method = RequestMethod.POST)
public String addTeacher(@RequestParam("firstName") String firstName, @RequestParam("middleName") String middleName, @RequestParam("lastName") String lastName, @RequestParam("email") String email, @RequestParam("departmentId") long departmentId, ModelMap modelMap) {
    try {
        Teacher teacher = new Teacher(firstName, middleName, lastName, email);
        teacherService.addTeacher(teacher, departmentId);
        List<Teacher> teacherList = teacherService.getTeacherList();
        List<Department> departmentList = departmentService.getDepartmentList();
        modelMap.put("teacherList", teacherList);
        modelMap.put("departmentList", departmentList);
        return "teacher";
    } catch (TeacherException | DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) Teacher(com.remswork.project.alice.model.Teacher) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Teacher

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

the class TeacherServiceImpl method addTeacher.

@Deprecated
@Override
public Teacher addTeacher(Teacher teacher) throws TeacherException {
    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.request();
        builder.accept("application/json");
        Response response = builder.post(Entity.json(teacher));
        if (response.getStatus() == 201) {
            return (Teacher) response.readEntity(Teacher.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new TeacherServiceException(message.getMessage());
        } else
            throw new TeacherServiceException("The request might invalid or server is down");
    } catch (TeacherServiceException e) {
        throw new TeacherException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) TeacherServiceException(com.remswork.project.alice.web.service.exception.TeacherServiceException) TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Teacher(com.remswork.project.alice.model.Teacher) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 14 with Teacher

use of com.remswork.project.alice.model.Teacher 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 15 with Teacher

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

the class TeacherServiceImpl method getTeacherList.

@Override
public List<Teacher> getTeacherList() throws TeacherException {
    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());
        Response response = target.request(MediaType.APPLICATION_JSON).get();
        if (response.getStatus() == 200) {
            return (List<Teacher>) response.readEntity(new GenericType<List<Teacher>>() {
            });
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new TeacherServiceException(message.getMessage());
        } else
            throw new TeacherServiceException("The request might invalid or server is down");
    } catch (TeacherServiceException e) {
        throw new TeacherException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) TeacherServiceException(com.remswork.project.alice.web.service.exception.TeacherServiceException) GenericType(javax.ws.rs.core.GenericType) TeacherException(com.remswork.project.alice.exception.TeacherException) Message(com.remswork.project.alice.model.support.Message) Teacher(com.remswork.project.alice.model.Teacher) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Aggregations

Teacher (com.remswork.project.alice.model.Teacher)29 TeacherException (com.remswork.project.alice.exception.TeacherException)14 Message (com.remswork.project.alice.model.support.Message)14 TeacherServiceException (com.remswork.project.alice.web.service.exception.TeacherServiceException)6 Client (javax.ws.rs.client.Client)6 WebTarget (javax.ws.rs.client.WebTarget)6 Response (javax.ws.rs.core.Response)6 Subject (com.remswork.project.alice.model.Subject)5 Gson (com.google.gson.Gson)4 TeacherHelper (com.lieverandiver.thesisproject.helper.TeacherHelper)4 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)4 Department (com.remswork.project.alice.model.Department)4 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)4 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ExecutionException (java.util.concurrent.ExecutionException)4 ClientBuilder (javax.ws.rs.client.ClientBuilder)4