use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.
the class SectionController method addSection.
@RequestMapping(value = "add", method = RequestMethod.POST)
public String addSection(@RequestParam("name") String name, @RequestParam("departmentId") long departmentId, ModelMap modelMap) {
try {
Section section = new Section(name);
sectionService.addSection(section, departmentId);
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";
}
}
use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.
the class DepartmentServiceImpl method addDepartment.
@Override
public Department addDepartment(Department department) 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());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.post(Entity.json(department));
if (response.getStatus() == 201) {
return (Department) response.readEntity(Department.class);
} else if (response.getStatus() == 400) {
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());
}
}
use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.
the class DepartmentServiceImpl method updateDepartmentById.
@Override
public Department updateDepartmentById(long id, Department newDepartment) 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());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.put(Entity.json(newDepartment));
if (response.getStatus() == 200) {
return (Department) response.readEntity(Department.class);
} else if (response.getStatus() == 400) {
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());
}
}
use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.
the class DepartmentServiceImpl method deleteDepartmentById.
@Override
public Department deleteDepartmentById(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());
Builder builder = target.request();
builder.accept("application/json");
Response response = builder.delete();
if (response.getStatus() == 200) {
return (Department) response.readEntity(Department.class);
} else if (response.getStatus() == 400) {
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());
}
}
use of com.remswork.project.alice.exception.DepartmentException in project classify-system by anverliedoit.
the class DepartmentController method updateDepartmentById.
@RequestMapping(value = "update", method = RequestMethod.POST)
public String updateDepartmentById(@RequestParam("id") long id, @RequestParam("name") String name, @RequestParam("description") String description, ModelMap modelMap) {
try {
Department newDepartment = new Department(name, description);
try {
departmentService.updateDepartmentById(id, newDepartment);
} catch (DepartmentException e) {
e.printStackTrace();
}
List<Department> departmentList = departmentService.getDepartmentList();
modelMap.put("departmentList", departmentList);
return "department";
} catch (DepartmentException e) {
e.printStackTrace();
return "error";
}
}
Aggregations