Search in sources :

Example 21 with SubjectException

use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.

the class SubjectServiceImpl method getSubjectListByTeacherId.

@Override
public List<Subject> getSubjectListByTeacherId(long teacherId) throws SubjectException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/1");
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.queryParam("teacherId", teacherId).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 22 with SubjectException

use of com.remswork.project.alice.exception.SubjectException 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 23 with SubjectException

use of com.remswork.project.alice.exception.SubjectException 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 24 with SubjectException

use of com.remswork.project.alice.exception.SubjectException 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 25 with SubjectException

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

Aggregations

SubjectException (com.remswork.project.alice.exception.SubjectException)44 Message (com.remswork.project.alice.model.support.Message)27 Subject (com.remswork.project.alice.model.Subject)23 AsyncTask (android.os.AsyncTask)10 Gson (com.google.gson.Gson)10 SubjectDaoException (com.remswork.project.alice.dao.exception.SubjectDaoException)10 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 HttpURLConnection (java.net.HttpURLConnection)10 URL (java.net.URL)10 ArrayList (java.util.ArrayList)10 ExecutionException (java.util.concurrent.ExecutionException)10 Session (org.hibernate.Session)10 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)8 Query (org.hibernate.Query)7 List (java.util.List)6