use of com.remswork.project.alice.exception.SubjectException 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.exception.SubjectException 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.exception.SubjectException 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.exception.SubjectException 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();
}
}
use of com.remswork.project.alice.exception.SubjectException in project classify-system by anverliedoit.
the class SubjectDaoImpl method getSubjectById.
@Override
public Subject getSubjectById(long id) throws SubjectException {
Session session = sessionFactory.openSession();
session.beginTransaction();
try {
Subject subject = session.get(Subject.class, id);
if (subject == null)
throw new SubjectDaoException("SubjectDto with id : " + id + " does not exist");
session.getTransaction().commit();
session.close();
return subject;
} catch (SubjectDaoException e) {
session.close();
throw new SubjectException(e.getMessage());
}
}
Aggregations