use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassController method addClass.
@RequestMapping(value = "add", method = RequestMethod.POST)
public String addClass(@RequestParam("teacherId") long teacherId, @RequestParam("subjectId") long subjectId, @RequestParam("sectionId") long sectionId, @RequestParam("file") MultipartFile file, @RequestParam("scheduleId") long[] scheduleIdList, ModelMap modelMap) {
try {
_class = new com.remswork.project.alice.model.Class();
_class = classService.addClass(_class, teacherId, subjectId, sectionId);
if (!file.isEmpty()) {
for (Student student : xcellHelperBean.loadFile(xcellHelperBean.convert(file), true)) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// boolean isExist = false;
for (Student s : studentService.getStudentList()) {
if (s.getStudentNumber() == student.getStudentNumber()) {
classService.addStudentById(_class.getId(), s.getId());
// isExist = true;
break;
}
}
// if (!isExist) {
// Student _student = studentService.addStudent(student, 112017101);
// classService.addStudentById(_class.getId(), _student.getId());
// }
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
}
for (long id : scheduleIdList) {
new Thread(() -> {
try {
classService.addScheduleById(_class.getId(), id);
} catch (ClassException e) {
e.printStackTrace();
}
}).start();
}
return "redirect:/teacher-detail?teacherId=" + teacherId;
} catch (Exception e) {
return "redirect:/teacher-detail?error=true&teacherId=" + teacherId;
// return "redirect:/teacher/view?error=true&id=" + teacherId;
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method deleteStudentById.
@Override
public Student deleteStudentById(long classId, long studentId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("student");
uri.append("/");
uri.append(studentId);
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 ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method getClassListBySubjectId.
@Override
public List<Class> getClassListBySubjectId(long subjectId) throws ClassException {
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("subjectId", subjectId).request().get();
if (response.getStatus() == 200) {
return (List<Class>) response.readEntity(new GenericType<List<Class>>() {
});
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method getStudentById.
@Override
public Student getStudentById(long classId, long studentId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("student");
uri.append("/");
uri.append(studentId);
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 ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
use of com.remswork.project.alice.exception.ClassException in project classify-system by anverliedoit.
the class ClassServiceImpl method getScheduleById.
@Override
public Schedule getScheduleById(long classId, long scheduleId) throws ClassException {
try {
StringBuilder uri = new StringBuilder();
uri.append(targetProperties.getDomain());
uri.append("/");
uri.append(targetProperties.getBaseUri());
uri.append("/");
uri.append(payload);
uri.append("/");
uri.append(classId);
uri.append("/");
uri.append("schedule");
uri.append("/");
uri.append(scheduleId);
Client client = ClientBuilder.newClient();
WebTarget target = client.target(uri.toString());
Response response = target.request().get();
if (response.getStatus() == 200) {
return (Schedule) response.readEntity(Schedule.class);
} else if (response.getStatus() == 404) {
Message message = (Message) response.readEntity(Message.class);
throw new ClassServiceException(message.getMessage());
} else
throw new ClassServiceException("The request might invalid or server is down");
} catch (ClassServiceException e) {
throw new ClassException(e.getMessage());
}
}
Aggregations