Search in sources :

Example 6 with SubjectResourceLinks

use of com.remswork.project.alice.resource.links.SubjectResourceLinks 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();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject)

Example 7 with SubjectResourceLinks

use of com.remswork.project.alice.resource.links.SubjectResourceLinks 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();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) Subject(com.remswork.project.alice.model.Subject)

Example 8 with SubjectResourceLinks

use of com.remswork.project.alice.resource.links.SubjectResourceLinks 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();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) List(java.util.List) Subject(com.remswork.project.alice.model.Subject)

Example 9 with SubjectResourceLinks

use of com.remswork.project.alice.resource.links.SubjectResourceLinks 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();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException)

Example 10 with SubjectResourceLinks

use of com.remswork.project.alice.resource.links.SubjectResourceLinks in project classify-system by anverliedoit.

the class SubjectResource method getSubjectListByTeacherId.

@GET
@Path("1")
@Deprecated
public Response getSubjectListByTeacherId(@QueryParam("teacherId") long teacherId) {
    try {
        SubjectResourceLinks resourceLinks = new SubjectResourceLinks(uriInfo);
        List<Subject> subjectList = subjectService.getSubjectListByTeacherId(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();
    }
}
Also used : SubjectResourceLinks(com.remswork.project.alice.resource.links.SubjectResourceLinks) Message(com.remswork.project.alice.model.support.Message) SubjectException(com.remswork.project.alice.exception.SubjectException) List(java.util.List) Subject(com.remswork.project.alice.model.Subject)

Aggregations

Message (com.remswork.project.alice.model.support.Message)19 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)19 TeacherResourceLinks (com.remswork.project.alice.resource.links.TeacherResourceLinks)11 SubjectException (com.remswork.project.alice.exception.SubjectException)8 Subject (com.remswork.project.alice.model.Subject)7 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)6 FormulaResourceLinks (com.remswork.project.alice.resource.links.FormulaResourceLinks)6 ClassException (com.remswork.project.alice.exception.ClassException)5 Formula (com.remswork.project.alice.model.Formula)5 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)5 SectionResourceLinks (com.remswork.project.alice.resource.links.SectionResourceLinks)5 List (java.util.List)5 Class (com.remswork.project.alice.model.Class)4