Search in sources :

Example 11 with Subject

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

the class SubjectServiceImpl method getSubjectById.

@Override
public Subject getSubjectById(long id) throws SubjectException {
    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 (Subject) response.readEntity(Subject.class);
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new SubjectServiceException(message.getMessage());
        } else
            throw new SubjectServiceException("The request might invalid or server is down");
    } catch (SubjectServiceException e) {
        throw new SubjectException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) WebTarget(javax.ws.rs.client.WebTarget) SubjectServiceException(com.remswork.project.alice.web.service.exception.SubjectServiceException) Client(javax.ws.rs.client.Client) Subject(com.remswork.project.alice.model.Subject)

Example 12 with Subject

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

the class SubjectServiceImpl method getSubjectListByStudentId.

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

Example 13 with Subject

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

the class SubjectController method updateSubjectById.

@RequestMapping(value = "update", method = RequestMethod.POST)
public String updateSubjectById(@RequestParam("id") long id, @RequestParam("name") String name, @RequestParam("code") String code, @RequestParam("description") String description, @RequestParam("unit") int unit, ModelMap modelMap) {
    try {
        Subject newSubject = new Subject(name, code, description, unit);
        try {
            subjectService.updateSubjectById(id, newSubject);
        } catch (SubjectException e) {
            e.printStackTrace();
        }
        List<Subject> subjectList = subjectService.getSubjectList();
        modelMap.put("subjectList", subjectList);
        return "subject";
    } catch (SubjectException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Subject

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

the class SubjectController method getTeacher.

@RequestMapping(value = "get", method = RequestMethod.POST)
public String getTeacher(@RequestParam("query") String query, ModelMap modelMap) {
    try {
        List<Subject> subjectList = new ArrayList<>();
        Subject subject = null;
        if (!query.trim().isEmpty()) {
            try {
                long id = Long.parseLong(query.trim());
                subject = subjectService.getSubjectById(id);
            } catch (NumberFormatException e) {
                e.printStackTrace();
                subject = null;
            } catch (SubjectException e) {
                e.printStackTrace();
                subject = null;
            }
            if (subject != null)
                subjectList.add(subject);
            else {
                for (Subject d : subjectService.getSubjectList()) {
                    if (d.getName().equals(query.trim())) {
                        subjectList.add(d);
                        continue;
                    }
                    if (d.getCode().equals(query.trim())) {
                        subjectList.add(d);
                        continue;
                    }
                    if (d.getDescription().equals(query.trim())) {
                        subjectList.add(d);
                        continue;
                    }
                }
            }
        }
        if (subjectList.size() < 1) {
            subjectList = subjectService.getSubjectList();
            modelMap.put("responseMessage", "No result found.");
        } else {
            modelMap.put("responseMessage", subjectList.size() + " Result found.");
        }
        modelMap.put("subjectList", subjectList);
        return "subject-table";
    } catch (SubjectException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : ArrayList(java.util.ArrayList) SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Subject

use of com.remswork.project.alice.model.Subject 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)

Aggregations

Subject (com.remswork.project.alice.model.Subject)29 SubjectException (com.remswork.project.alice.exception.SubjectException)23 Message (com.remswork.project.alice.model.support.Message)20 SubjectServiceException (com.remswork.project.alice.web.service.exception.SubjectServiceException)9 Client (javax.ws.rs.client.Client)9 WebTarget (javax.ws.rs.client.WebTarget)9 Response (javax.ws.rs.core.Response)9 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)7 List (java.util.List)6 Teacher (com.remswork.project.alice.model.Teacher)5 ArrayList (java.util.ArrayList)5 AsyncTask (android.os.AsyncTask)4 Gson (com.google.gson.Gson)4 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)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 JSONArray (org.json.JSONArray)4