Search in sources :

Example 11 with DepartmentException

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

the class DepartmentServiceImpl method getDepartmentById.

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

Example 12 with DepartmentException

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

the class DepartmentServiceImpl method getDepartmentList.

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

Example 13 with DepartmentException

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

the class DepartmentController method getTeacher.

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

Example 14 with DepartmentException

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

the class DepartmentController method addDepartment.

@RequestMapping(value = "add", method = RequestMethod.POST)
public String addDepartment(@RequestParam("name") String name, @RequestParam("description") String description, ModelMap modelMap) {
    try {
        Department department = new Department(name, description);
        departmentService.addDepartment(department);
        List<Department> departmentList = departmentService.getDepartmentList();
        modelMap.put("departmentList", departmentList);
        return "department";
    } catch (DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with DepartmentException

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

the class SectionController method updateSectionById.

@RequestMapping(value = "update", method = RequestMethod.POST)
public String updateSectionById(@RequestParam("id") long id, @RequestParam("name") String name, @RequestParam("departmentId") long departmentId, ModelMap modelMap) {
    try {
        Section newSection = new Section(name);
        try {
            sectionService.updateSectionById(id, newSection, departmentId);
        } catch (SectionException e) {
            try {
                e.printStackTrace();
                departmentId = 0;
                sectionService.updateSectionById(id, newSection, departmentId);
            } catch (SectionException e2) {
                e2.printStackTrace();
            }
        }
        List<Section> sectionList = sectionService.getSectionList();
        List<Department> departmentList = departmentService.getDepartmentList();
        modelMap.put("sectionList", sectionList);
        modelMap.put("departmentList", departmentList);
        return "section";
    } catch (SectionException | DepartmentException e) {
        e.printStackTrace();
        return "error";
    }
}
Also used : Department(com.remswork.project.alice.model.Department) DepartmentException(com.remswork.project.alice.exception.DepartmentException) SectionException(com.remswork.project.alice.exception.SectionException) Section(com.remswork.project.alice.model.Section) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DepartmentException (com.remswork.project.alice.exception.DepartmentException)30 Department (com.remswork.project.alice.model.Department)22 Message (com.remswork.project.alice.model.support.Message)15 Session (org.hibernate.Session)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 AsyncTask (android.os.AsyncTask)5 Gson (com.google.gson.Gson)5 DepartmentDaoException (com.remswork.project.alice.dao.exception.DepartmentDaoException)5 SectionException (com.remswork.project.alice.exception.SectionException)5 Section (com.remswork.project.alice.model.Section)5 DepartmentResourceLinks (com.remswork.project.alice.resource.links.DepartmentResourceLinks)5 DepartmentServiceException (com.remswork.project.alice.web.service.exception.DepartmentServiceException)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 ExecutionException (java.util.concurrent.ExecutionException)5 Client (javax.ws.rs.client.Client)5 WebTarget (javax.ws.rs.client.WebTarget)5 Response (javax.ws.rs.core.Response)5