Search in sources :

Example 1 with SubjectException

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();
    }
}
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 2 with SubjectException

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();
    }
}
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 3 with SubjectException

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();
    }
}
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 4 with SubjectException

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();
    }
}
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 5 with SubjectException

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());
    }
}
Also used : SubjectDaoException(com.remswork.project.alice.dao.exception.SubjectDaoException) SubjectException(com.remswork.project.alice.exception.SubjectException) Session(org.hibernate.Session)

Aggregations

SubjectException (com.remswork.project.alice.exception.SubjectException)44 Message (com.remswork.project.alice.model.support.Message)27 Subject (com.remswork.project.alice.model.Subject)23 AsyncTask (android.os.AsyncTask)10 Gson (com.google.gson.Gson)10 SubjectDaoException (com.remswork.project.alice.dao.exception.SubjectDaoException)10 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 HttpURLConnection (java.net.HttpURLConnection)10 URL (java.net.URL)10 ArrayList (java.util.ArrayList)10 ExecutionException (java.util.concurrent.ExecutionException)10 Session (org.hibernate.Session)10 SubjectServiceException (com.remswork.project.alice.web.service.exception.SubjectServiceException)9 Client (javax.ws.rs.client.Client)9 WebTarget (javax.ws.rs.client.WebTarget)9 Response (javax.ws.rs.core.Response)9 SubjectResourceLinks (com.remswork.project.alice.resource.links.SubjectResourceLinks)8 Query (org.hibernate.Query)7 List (java.util.List)6