use of com.remswork.project.alice.exception.StudentException 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());
}
}
use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.
the class StudentController method addStudent.
@RequestMapping(value = "add", method = RequestMethod.POST)
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("sectionId") long sectionId, ModelMap modelMap) {
try {
Student student = new Student(studentNumber, firstName, lastName, middleName, gender, age, "");
studentService.addStudent(student, sectionId);
List<Student> studentList = studentService.getStudentList();
List<Section> sectionList = sectionService.getSectionList();
modelMap.put("studentList", studentList);
modelMap.put("sectionList", sectionList);
return "student";
} catch (StudentException | SectionException e) {
e.printStackTrace();
return "error";
}
}
use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.
the class StudentController method getStudent.
@RequestMapping(value = "get", method = RequestMethod.POST)
public String getStudent(@RequestParam("query") String query, ModelMap modelMap) {
try {
List<Section> sectionList = sectionService.getSectionList();
List<Student> studentList = new ArrayList<>();
Student student = null;
if (!query.trim().isEmpty()) {
try {
long id = Long.parseLong(query.trim());
student = studentService.getStudentById(id);
} catch (NumberFormatException e) {
e.printStackTrace();
student = null;
} catch (StudentException e) {
e.printStackTrace();
student = null;
}
if (student != null)
studentList.add(student);
else {
for (Student s : studentService.getStudentList()) {
if (s.getFirstName().equals(query.trim())) {
studentList.add(s);
continue;
}
if (s.getMiddleName().equals(query.trim())) {
studentList.add(s);
continue;
}
if (s.getLastName().equals(query.trim())) {
studentList.add(s);
continue;
}
try {
if (s.getStudentNumber() == Integer.parseInt(query)) {
studentList.add(s);
continue;
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
}
}
if (studentList.size() < 1) {
studentList = studentService.getStudentList();
modelMap.put("responseMessage", "No result found.");
} else {
modelMap.put("responseMessage", studentList.size() + " Result found.");
}
modelMap.put("studentList", studentList);
modelMap.put("sectionList", sectionList);
return "student-table";
} catch (StudentException | SectionException e) {
e.printStackTrace();
return "error";
}
}
use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.
the class StudentServiceImpl method deleteStudentById.
@Override
public Student deleteStudentById(long id) 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.request();
builder.accept("application/json");
Response response = builder.delete();
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());
}
}
use of com.remswork.project.alice.exception.StudentException in project classify-system by anverliedoit.
the class StudentServiceImpl method getStudentBySn.
public Student getStudentBySn(long id) throws StudentException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("?sn=");
uri.append(id);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Student) response.readEntity(Student.class);
} 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());
}
}
Aggregations