Search in sources :

Example 41 with Student

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

the class StudentServiceImpl method updateStudentById.

@Override
public Student updateStudentById(long id, Student newStudent, long sectionId) throws StudentException {
    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("sectionId", sectionId).request();
        builder.accept("application/json");
        Response response = builder.put(Entity.json(newStudent));
        if (response.getStatus() == 200) {
            return (Student) response.readEntity(Student.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new StudentServiceException(message.getMessage());
        } else
            throw new StudentServiceException("The request might invalid or server is down");
    } catch (StudentServiceException e) {
        throw new StudentException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) StudentException(com.remswork.project.alice.exception.StudentException) 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) Student(com.remswork.project.alice.model.Student) StudentServiceException(com.remswork.project.alice.web.service.exception.StudentServiceException)

Example 42 with Student

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

the class StudentServiceImpl method addStudent.

@Override
public Student addStudent(Student Student, long sectionId) throws StudentException {
    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("sectionId", sectionId).request();
        builder.accept("application/json");
        Response response = builder.post(Entity.json(Student));
        if (response.getStatus() == 201) {
            return (Student) response.readEntity(Student.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new StudentServiceException(message.getMessage());
        } else
            throw new StudentServiceException("The request might invalid or server is down");
    } catch (StudentServiceException e) {
        throw new StudentException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) StudentException(com.remswork.project.alice.exception.StudentException) 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) Student(com.remswork.project.alice.model.Student) StudentServiceException(com.remswork.project.alice.web.service.exception.StudentServiceException)

Example 43 with Student

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

the class StudentServiceImpl method getStudentList.

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

Example 44 with Student

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

the class ClassController method addClass.

@RequestMapping(value = "add", method = RequestMethod.POST)
public String addClass(@RequestParam("teacherId") long teacherId, @RequestParam("subjectId") long subjectId, @RequestParam("sectionId") long sectionId, @RequestParam("file") MultipartFile file, @RequestParam("scheduleId") long[] scheduleIdList, ModelMap modelMap) {
    try {
        _class = new com.remswork.project.alice.model.Class();
        _class = classService.addClass(_class, teacherId, subjectId, sectionId);
        if (!file.isEmpty()) {
            for (Student student : xcellHelperBean.loadFile(xcellHelperBean.convert(file), true)) {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            // boolean isExist = false;
                            for (Student s : studentService.getStudentList()) {
                                if (s.getStudentNumber() == student.getStudentNumber()) {
                                    classService.addStudentById(_class.getId(), s.getId());
                                    // isExist = true;
                                    break;
                                }
                            }
                        // if (!isExist) {
                        // Student _student = studentService.addStudent(student, 112017101);
                        // classService.addStudentById(_class.getId(), _student.getId());
                        // }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }
        for (long id : scheduleIdList) {
            new Thread(() -> {
                try {
                    classService.addScheduleById(_class.getId(), id);
                } catch (ClassException e) {
                    e.printStackTrace();
                }
            }).start();
        }
        return "redirect:/teacher-detail?teacherId=" + teacherId;
    } catch (Exception e) {
        return "redirect:/teacher-detail?error=true&teacherId=" + teacherId;
    // return "redirect:/teacher/view?error=true&id=" + teacherId;
    }
}
Also used : ClassException(com.remswork.project.alice.exception.ClassException) Student(com.remswork.project.alice.model.Student) ClassException(com.remswork.project.alice.exception.ClassException)

Example 45 with Student

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

the class MyStudentController method addStudent.

@PostMapping("student-add")
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(value = "sectionId", required = false) Long sectionId, ModelMap modelMap) {
    try {
        Student student = new Student(studentNumber, firstName, lastName, middleName, gender, age, "");
        studentService.addStudent(student, 0);
        List<Student> studentList = studentService.getStudentList();
        modelMap.put("studentList", studentList);
        return "students";
    } catch (Exception e) {
        return "students";
    }
}
Also used : Student(com.remswork.project.alice.model.Student) SectionException(com.remswork.project.alice.exception.SectionException) StudentException(com.remswork.project.alice.exception.StudentException)

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