Search in sources :

Example 6 with Schedule

use of com.remswork.project.alice.model.Schedule 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 7 with Schedule

use of com.remswork.project.alice.model.Schedule 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 8 with Schedule

use of com.remswork.project.alice.model.Schedule 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 9 with Schedule

use of com.remswork.project.alice.model.Schedule 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)

Example 10 with Schedule

use of com.remswork.project.alice.model.Schedule in project classify-system by anverliedoit.

the class ScheduleAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ScheduleAdapter.ScheduleViewHolder holder, int position) {
    Schedule schedule = scheduleList.get(position);
    holder.setView(schedule, position);
}
Also used : Schedule(com.remswork.project.alice.model.Schedule)

Aggregations

Schedule (com.remswork.project.alice.model.Schedule)36 ScheduleException (com.remswork.project.alice.exception.ScheduleException)22 Message (com.remswork.project.alice.model.support.Message)22 ClassException (com.remswork.project.alice.exception.ClassException)13 Client (javax.ws.rs.client.Client)10 WebTarget (javax.ws.rs.client.WebTarget)10 Response (javax.ws.rs.core.Response)10 ScheduleServiceException (com.remswork.project.alice.web.service.exception.ScheduleServiceException)6 ScheduleResourceLinks (com.remswork.project.alice.resource.links.ScheduleResourceLinks)5 ArrayList (java.util.ArrayList)5 ClientBuilder (javax.ws.rs.client.ClientBuilder)5 Builder (javax.ws.rs.client.Invocation.Builder)5 Session (org.hibernate.Session)5 ScheduleDaoException (com.remswork.project.alice.dao.exception.ScheduleDaoException)4 ClassScheduleListResourceLinks (com.remswork.project.alice.resource.links.ClassScheduleListResourceLinks)4 ClassServiceException (com.remswork.project.alice.web.service.exception.ClassServiceException)4 Set (java.util.Set)4 AsyncTask (android.os.AsyncTask)3 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3