Search in sources :

Example 46 with Student

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

the class MyStudentController method importStudents.

@PostMapping("student-import")
public String importStudents(@RequestParam("classId") Long classId, @RequestParam("file") MultipartFile file, ModelMap modelMap) {
    try {
        final Set<Student> students = classService.getStudentList(classId);
        if (!file.isEmpty()) {
            for (Student student : xcellHelperBean.loadFile(xcellHelperBean.convert(file), true)) {
                try {
                    System.out.println("id :" + student.getId());
                    System.out.println("sn :" + student.getStudentNumber());
                    Student s;
                    try {
                        s = studentService.getStudentBySn(student.getStudentNumber());
                        s = classService.addStudentById(classId, s.getId());
                        students.add(s);
                    } catch (Exception e) {
                        e.printStackTrace();
                    // s = studentService.addStudent(student, 112017101);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        if (students != null) {
            modelMap.put("studentList", students);
        } else {
            modelMap.put("studentList", new ArrayList<Student>());
        }
    } catch (Exception e) {
        modelMap.put("studentList", new ArrayList<Student>());
    }
    return "student-list";
}
Also used : ArrayList(java.util.ArrayList) Student(com.remswork.project.alice.model.Student) SectionException(com.remswork.project.alice.exception.SectionException) StudentException(com.remswork.project.alice.exception.StudentException)

Example 47 with Student

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

the class StudentController method addStudent.

@RequestMapping(value = "add", method = RequestMethod.POST)
public String addStudent(@RequestParam("studentNumber") long studentNumber, @RequestParam("firstName") String firstName, @RequestParam("middleName") String middleName, @RequestParam("lastName") String lastName, @RequestParam("gender") String gender, @RequestParam("age") int age, @RequestParam("sectionId") long sectionId, ModelMap modelMap) {
    try {
        Student student = new Student(studentNumber, firstName, lastName, middleName, gender, age, "");
        studentService.addStudent(student, sectionId);
        List<Student> studentList = studentService.getStudentList();
        List<Section> sectionList = sectionService.getSectionList();
        modelMap.put("studentList", studentList);
        modelMap.put("sectionList", sectionList);
        return "student";
    } catch (StudentException | SectionException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) Student(com.remswork.project.alice.model.Student) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 48 with Student

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

the class StudentController method getStudent.

@RequestMapping(value = "get", method = RequestMethod.POST)
public String getStudent(@RequestParam("query") String query, ModelMap modelMap) {
    try {
        List<Section> sectionList = sectionService.getSectionList();
        List<Student> studentList = new ArrayList<>();
        Student student = null;
        if (!query.trim().isEmpty()) {
            try {
                long id = Long.parseLong(query.trim());
                student = studentService.getStudentById(id);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                student = null;
            } catch (StudentException e) {
                e.printStackTrace();
                student = null;
            }
            if (student != null)
                studentList.add(student);
            else {
                for (Student s : studentService.getStudentList()) {
                    if (s.getFirstName().equals(query.trim())) {
                        studentList.add(s);
                        continue;
                    }
                    if (s.getMiddleName().equals(query.trim())) {
                        studentList.add(s);
                        continue;
                    }
                    if (s.getLastName().equals(query.trim())) {
                        studentList.add(s);
                        continue;
                    }
                    try {
                        if (s.getStudentNumber() == Integer.parseInt(query)) {
                            studentList.add(s);
                            continue;
                        }
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        if (studentList.size() < 1) {
            studentList = studentService.getStudentList();
            modelMap.put("responseMessage", "No result found.");
        } else {
            modelMap.put("responseMessage", studentList.size() + " Result found.");
        }
        modelMap.put("studentList", studentList);
        modelMap.put("sectionList", sectionList);
        return "student-table";
    } catch (StudentException | SectionException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : StudentException(com.remswork.project.alice.exception.StudentException) ArrayList(java.util.ArrayList) Student(com.remswork.project.alice.model.Student) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 49 with Student

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

the class ClassServiceImpl method deleteStudentById.

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

Example 50 with Student

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

the class ClassServiceImpl method getStudentById.

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

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