use of com.remswork.project.alice.model.support.Message in project classify-system by anverliedoit.
the class StudentResource method getStudentList.
@GET
public Response getStudentList() {
try {
StudentResourceLinks resourceLinks = new StudentResourceLinks(uriInfo);
SectionResourceLinks sectionResourceLinks = new SectionResourceLinks(uriInfo);
DepartmentResourceLinks departmentResourceLinks = new DepartmentResourceLinks(uriInfo);
List<Student> studentList = studentService.getStudentList();
if (sn == null) {
for (Student student : studentList) {
student.addLink(resourceLinks.self(student.getId()));
if (student.getSection() != null) {
Section section = student.getSection();
section.addLink(sectionResourceLinks.self(section.getId()));
if (section.getDepartment() != null)
section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
}
}
GenericEntity<List<Student>> entity = new GenericEntity<List<Student>>(studentList) {
};
return Response.status(Response.Status.OK).entity(entity).build();
} else {
Student student = studentService.getStudentBySN(sn);
if (student.getSection() != null) {
Section section = student.getSection();
section.addLink(sectionResourceLinks.self(section.getId()));
if (section.getDepartment() != null) {
section.getDepartment().addLink(departmentResourceLinks.self(section.getDepartment().getId()));
}
}
return Response.status(Response.Status.OK).entity(student).build();
}
} catch (StudentException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.support.Message in project classify-system by anverliedoit.
the class SubjectResource method deleteSubjectById.
@DELETE
@Path("{subjectId}")
public Response deleteSubjectById(@PathParam("subjectId") long id) {
try {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.deleteSubjectById(id);
subject.addLink(resourceLinks.self(id));
return Response.status(Response.Status.OK).entity(subject).build();
} catch (SubjectException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.model.support.Message in project classify-system by anverliedoit.
the class SubjectResource method getSubject.
@GET
@Path("0")
public Response getSubject(@QueryParam("classId") long classId, @QueryParam("scheduleId") long scheduleId, @QueryParam("teacherId") long teacherId) {
try {
if (classId != 0 && teacherId != 0) {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.getSubjectByClassAndTeacherId(classId, teacherId);
subject.addLink(resourceLinks.self(subject.getId()));
return Response.status(Response.Status.OK).entity(subject).build();
} else if (scheduleId != 0) {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
Subject subject = subjectService.getSubjectByScheduleId(scheduleId);
subject.addLink(resourceLinks.self(subject.getId()));
return Response.status(Response.Status.OK).entity(subject).build();
} else
throw new SubjectException("No subject found");
} catch (SubjectException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.support.Message in project classify-system by anverliedoit.
the class SubjectResource method getSubjectListByTeacherIdUnique.
@GET
@Path("1/unique")
@Deprecated
public Response getSubjectListByTeacherIdUnique(@QueryParam("teacherId") long teacherId) {
try {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
List<Subject> subjectList = subjectService.getSubjectListByTeacherIdUnique(teacherId);
for (Subject subject : subjectList) subject.addLink(resourceLinks.self(subject.getId()));
GenericEntity<List<Subject>> entity = new GenericEntity<List<Subject>>(subjectList) {
};
return Response.status(Response.Status.OK).entity(entity).build();
} catch (SubjectException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.support.Message in project classify-system by anverliedoit.
the class SubjectResource method addSubject.
@POST
public Response addSubject(Subject subject) {
try {
SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
subject = subjectService.addSubject(subject);
subject.addLink(resourceLinks.self(subject.getId()));
return Response.status(Response.Status.CREATED).entity(subject).build();
} catch (SubjectException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
Aggregations