use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.
the class TeacherController method getTeacher.
@RequestMapping(value = "get", method = RequestMethod.POST)
public String getTeacher(@RequestParam("query") String query, ModelMap modelMap) {
try {
List<Department> departmentList = departmentService.getDepartmentList();
List<Teacher> teacherList = new ArrayList<>();
Teacher teacher = null;
if (!query.trim().isEmpty()) {
try {
long id = Long.parseLong(query.trim());
teacher = teacherService.getTeacherById(id);
} catch (NumberFormatException e) {
e.printStackTrace();
teacher = null;
} catch (TeacherException e) {
e.printStackTrace();
teacher = null;
}
if (teacher != null)
teacherList.add(teacher);
else {
for (Teacher t : teacherService.getTeacherList()) {
if (t.getFirstName().equals(query.trim())) {
teacherList.add(t);
continue;
}
if (t.getMiddleName().equals(query.trim())) {
teacherList.add(t);
continue;
}
if (t.getLastName().equals(query.trim())) {
teacherList.add(t);
continue;
}
if (t.getEmail().equals(query.trim())) {
teacherList.add(t);
continue;
}
}
}
}
if (teacherList.size() < 1) {
teacherList = teacherService.getTeacherList();
modelMap.put("responseMessage", "No result found.");
} else {
modelMap.put("responseMessage", teacherList.size() + " Result found.");
}
modelMap.put("teacherList", teacherList);
modelMap.put("departmentList", departmentList);
return "fragment/teacher-table";
} catch (TeacherException | DepartmentException e) {
e.printStackTrace();
return "error";
}
}
use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.
the class TeacherController method addTeacher.
@RequestMapping(value = "add", method = RequestMethod.POST)
public String addTeacher(@RequestParam("firstName") String firstName, @RequestParam("middleName") String middleName, @RequestParam("lastName") String lastName, @RequestParam("email") String email, @RequestParam("departmentId") long departmentId, ModelMap modelMap) {
try {
Teacher teacher = new Teacher(firstName, middleName, lastName, email);
teacherService.addTeacher(teacher, departmentId);
List<Teacher> teacherList = teacherService.getTeacherList();
List<Department> departmentList = departmentService.getDepartmentList();
modelMap.put("teacherList", teacherList);
modelMap.put("departmentList", departmentList);
return "teacher";
} catch (TeacherException | DepartmentException e) {
e.printStackTrace();
return "error";
}
}
use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.
the class TeacherServiceImpl method addTeacher.
@Deprecated
@Override
public Teacher addTeacher(Teacher teacher) throws TeacherException {
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(teacher));
if (response.getStatus() == 201) {
return (Teacher) response.readEntity(Teacher.class);
} else if (response.getStatus() == 400) {
Message message = (Message) response.readEntity(Message.class);
throw new TeacherServiceException(message.getMessage());
} else
throw new TeacherServiceException("The request might invalid or server is down");
} catch (TeacherServiceException e) {
throw new TeacherException(e.getMessage());
}
}
use of com.remswork.project.alice.model.Teacher 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";
}
}
use of com.remswork.project.alice.model.Teacher in project classify-system by anverliedoit.
the class TeacherServiceImpl method getTeacherList.
@Override
public List<Teacher> getTeacherList() throws TeacherException {
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(MediaType.APPLICATION_JSON).get();
if (response.getStatus() == 200) {
return (List<Teacher>) response.readEntity(new GenericType<List<Teacher>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new TeacherServiceException(message.getMessage());
} else
throw new TeacherServiceException("The request might invalid or server is down");
} catch (TeacherServiceException e) {
throw new TeacherException(e.getMessage());
}
}
Aggregations