Search in sources :

Example 1 with ScheduleException

use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.

the class ScheduleResource method getScheduleById.

@GET
@Path("{scheduleId}")
public Response getScheduleById(@PathParam("scheduleId") long id) {
    try {
        ScheduleResourceLinks resourceLinks = new ScheduleResourceLinks(uriInfo);
        Schedule schedule = scheduleService.getScheduleById(id);
        schedule.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(schedule).build();
    } catch (ScheduleException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) ScheduleResourceLinks(com.remswork.project.alice.resource.links.ScheduleResourceLinks) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 2 with ScheduleException

use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.

the class ScheduleResource method getScheduleList.

@GET
public Response getScheduleList() {
    try {
        ScheduleResourceLinks resourceLinks = new ScheduleResourceLinks(uriInfo);
        List<Schedule> scheduleList = scheduleService.getScheduleList();
        for (Schedule schedule : scheduleList) schedule.addLink(resourceLinks.self(schedule.getId()));
        GenericEntity<List<Schedule>> entity = new GenericEntity<List<Schedule>>(scheduleList) {
        };
        return Response.status(Response.Status.OK).entity(entity).build();
    } catch (ScheduleException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) ScheduleResourceLinks(com.remswork.project.alice.resource.links.ScheduleResourceLinks) List(java.util.List) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 3 with ScheduleException

use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.

the class ScheduleResource method updateScheduleById.

@PUT
@Path("{scheduleId}")
public Response updateScheduleById(@PathParam("scheduleId") long id, Schedule newSchedule) {
    try {
        ScheduleResourceLinks resourceLinks = new ScheduleResourceLinks(uriInfo);
        Schedule schedule = scheduleService.updateScheduleById(id, newSchedule);
        schedule.addLink(resourceLinks.self(id));
        return Response.status(Response.Status.OK).entity(schedule).build();
    } catch (ScheduleException e) {
        e.printStackTrace();
        Message message = new Message(400, "Bad Request", e.getMessage());
        return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
    }
}
Also used : Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) ScheduleResourceLinks(com.remswork.project.alice.resource.links.ScheduleResourceLinks) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 4 with ScheduleException

use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.

the class ScheduleDaoImpl method deleteScheduleById.

@Override
public Schedule deleteScheduleById(long id) throws ScheduleException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Schedule schedule = session.get(Schedule.class, id);
        if (schedule == null)
            throw new ScheduleDaoException("Schedule with id : " + id + " does not exist");
        Query classQuery = session.createQuery("from Class");
        for (Object classObj : classQuery.list()) {
            Class _class = (Class) classObj;
            _class = session.get(Class.class, _class.getId());
            for (Schedule s : _class.getScheduleList()) {
                if (s == null)
                    continue;
                if (s.getId() == id) {
                    _class.getScheduleList().remove(s);
                    break;
                }
            }
        }
        session.delete(schedule);
        session.getTransaction().commit();
        session.close();
        return schedule;
    } catch (ScheduleDaoException e) {
        session.close();
        throw new ScheduleException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) Schedule(com.remswork.project.alice.model.Schedule) Class(com.remswork.project.alice.model.Class) ScheduleException(com.remswork.project.alice.exception.ScheduleException) Session(org.hibernate.Session) ScheduleDaoException(com.remswork.project.alice.dao.exception.ScheduleDaoException)

Example 5 with ScheduleException

use of com.remswork.project.alice.exception.ScheduleException in project classify-system by anverliedoit.

the class ScheduleDaoImpl method getScheduleListByTeacherId.

@Override
public Set<Schedule> getScheduleListByTeacherId(long teacherId) throws ScheduleException {
    Session session = sessionFactory.openSession();
    session.beginTransaction();
    try {
        Set<Schedule> scheduleSet = new HashSet<>();
        String hql = "from Class as c join c.scheduleList as s join c.teacher as t where t.id = :teacherId";
        Query query = session.createQuery(hql);
        query.setParameter("teacherId", teacherId);
        for (Object list : query.list()) {
            Object[] row = (Object[]) list;
            scheduleSet.add((Schedule) row[1]);
        }
        session.getTransaction().commit();
        session.close();
        return scheduleSet;
    } catch (ClassDaoException e) {
        session.close();
        throw new ScheduleException(e.getMessage());
    }
}
Also used : Query(org.hibernate.Query) ClassDaoException(com.remswork.project.alice.dao.exception.ClassDaoException) Schedule(com.remswork.project.alice.model.Schedule) ScheduleException(com.remswork.project.alice.exception.ScheduleException) Session(org.hibernate.Session) HashSet(java.util.HashSet)

Aggregations

ScheduleException (com.remswork.project.alice.exception.ScheduleException)28 Schedule (com.remswork.project.alice.model.Schedule)22 Message (com.remswork.project.alice.model.support.Message)18 AsyncTask (android.os.AsyncTask)6 Gson (com.google.gson.Gson)6 ScheduleResourceLinks (com.remswork.project.alice.resource.links.ScheduleResourceLinks)6 ScheduleServiceException (com.remswork.project.alice.web.service.exception.ScheduleServiceException)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 HttpURLConnection (java.net.HttpURLConnection)6 URL (java.net.URL)6 ExecutionException (java.util.concurrent.ExecutionException)6 Client (javax.ws.rs.client.Client)6 WebTarget (javax.ws.rs.client.WebTarget)6 Response (javax.ws.rs.core.Response)6 Session (org.hibernate.Session)6 ScheduleDaoException (com.remswork.project.alice.dao.exception.ScheduleDaoException)5 ArrayList (java.util.ArrayList)3 ClientBuilder (javax.ws.rs.client.ClientBuilder)3 Builder (javax.ws.rs.client.Invocation.Builder)3