Search in sources :

Example 6 with ScheduleException

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

the class SliderScheduleFragment method setSchedule.

public void setSchedule(final int id) {
    switch(id) {
        case schedule_today_rb:
            new Thread(new Runnable() {

                @Override
                public void run() {
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            txtMsgNoContent.setVisibility(View.INVISIBLE);
                        }
                    });
                    try {
                        final List<Schedule> newSchedules = new ArrayList<>();
                        final TeacherHelper teacherHelper = new TeacherHelper(getContext());
                        if (teacherHelper.loadUser().get() != null) {
                            try {
                                for (Schedule schedule : new ScheduleServiceImpl().getScheduleListByTeacherId(teacherHelper.loadUser().get().getId())) newSchedules.add(schedule);
                            } catch (ScheduleException e) {
                                e.printStackTrace();
                            }
                        }
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                int size = scheduleAdapter.getItemCount();
                                for (int i = 0; i < size; i++) {
                                    if (scheduleList.size() > 0) {
                                        scheduleList.remove(0);
                                        scheduleAdapter.notifyItemRemoved(0);
                                    }
                                }
                                ScheduleHelper scheduleHelper = new ScheduleHelper();
                                int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
                                for (Schedule schedule : newSchedules) {
                                    if (scheduleHelper.dayInNumber(schedule.getDay()) == day) {
                                        scheduleList.add(schedule);
                                        scheduleAdapter.notifyItemRangeInserted(0, scheduleList.size());
                                    }
                                }
                                progressBar.setVisibility(View.INVISIBLE);
                                if (scheduleList.size() < 1)
                                    txtMsgNoContent.setVisibility(View.VISIBLE);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            break;
        case schedule_tomorrow_rb:
            new Thread(new Runnable() {

                @Override
                public void run() {
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            txtMsgNoContent.setVisibility(View.INVISIBLE);
                        }
                    });
                    try {
                        final List<Schedule> newSchedules = new ArrayList<>();
                        final TeacherHelper teacherHelper = new TeacherHelper(getContext());
                        if (teacherHelper.loadUser().get() != null) {
                            try {
                                for (Schedule schedule : new ScheduleServiceImpl().getScheduleListByTeacherId(teacherHelper.loadUser().get().getId())) newSchedules.add(schedule);
                            } catch (ScheduleException e) {
                                e.printStackTrace();
                            }
                        }
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                int size = scheduleAdapter.getItemCount();
                                for (int i = 0; i < size; i++) {
                                    if (scheduleList.size() > 0) {
                                        scheduleList.remove(0);
                                        scheduleAdapter.notifyItemRemoved(0);
                                    }
                                }
                                ScheduleHelper scheduleHelper = new ScheduleHelper();
                                int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) + 1;
                                for (Schedule schedule : newSchedules) {
                                    if (scheduleHelper.dayInNumber(schedule.getDay()) == day) {
                                        scheduleList.add(schedule);
                                        scheduleAdapter.notifyItemRangeInserted(0, scheduleList.size());
                                    }
                                }
                                progressBar.setVisibility(View.INVISIBLE);
                                if (scheduleList.size() < 1)
                                    txtMsgNoContent.setVisibility(View.VISIBLE);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            break;
        default:
            new Thread(new Runnable() {

                @Override
                public void run() {
                    handler.post(new Runnable() {

                        @Override
                        public void run() {
                            progressBar.setVisibility(View.VISIBLE);
                            txtMsgNoContent.setVisibility(View.INVISIBLE);
                        }
                    });
                    try {
                        final List<Schedule> newSchedules = new ArrayList<>();
                        final TeacherHelper teacherHelper = new TeacherHelper(getContext());
                        if (teacherHelper.loadUser().get() != null) {
                            try {
                                for (Schedule schedule : new ScheduleServiceImpl().getScheduleListByTeacherId(teacherHelper.loadUser().get().getId())) newSchedules.add(schedule);
                            } catch (ScheduleException e) {
                                e.printStackTrace();
                            }
                        }
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                int size = scheduleAdapter.getItemCount();
                                for (int i = 0; i < size; i++) {
                                    if (scheduleList.size() > 0) {
                                        scheduleList.remove(0);
                                        scheduleAdapter.notifyItemRemoved(0);
                                    }
                                }
                                for (Schedule schedule : newSchedules) {
                                    scheduleList.add(schedule);
                                    scheduleAdapter.notifyItemRangeInserted(0, scheduleList.size());
                                }
                                progressBar.setVisibility(View.INVISIBLE);
                                if (scheduleList.size() < 1)
                                    txtMsgNoContent.setVisibility(View.VISIBLE);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
            break;
    }
}
Also used : ScheduleServiceImpl(com.remswork.project.alice.service.impl.ScheduleServiceImpl) ScheduleHelper(com.lieverandiver.thesisproject.helper.ScheduleHelper) Schedule(com.remswork.project.alice.model.Schedule) ArrayList(java.util.ArrayList) TeacherHelper(com.lieverandiver.thesisproject.helper.TeacherHelper) ScheduleException(com.remswork.project.alice.exception.ScheduleException) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 7 with ScheduleException

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

the class ScheduleServiceImpl method addSchedule.

@Override
public Schedule addSchedule(Schedule schedule) throws ScheduleException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Builder builder = target.request();
        builder.accept("application/json");
        Response response = builder.post(Entity.json(schedule));
        if (response.getStatus() == 201) {
            return (Schedule) response.readEntity(Schedule.class);
        } else if (response.getStatus() == 400) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ScheduleServiceException(message.getMessage());
        } else
            throw new ScheduleServiceException("The request might invalid or server is down");
    } catch (ScheduleServiceException e) {
        throw new ScheduleException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ScheduleServiceException(com.remswork.project.alice.web.service.exception.ScheduleServiceException) Message(com.remswork.project.alice.model.support.Message) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Schedule(com.remswork.project.alice.model.Schedule) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 8 with ScheduleException

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

the class ScheduleServiceImpl method getScheduleListByTeacherId.

@Override
public Set<Schedule> getScheduleListByTeacherId(long teacherId) throws ScheduleException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.queryParam("teacherId", teacherId).request().get();
        if (response.getStatus() == 200) {
            return (Set<Schedule>) response.readEntity(new GenericType<Set<Schedule>>() {
            });
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ScheduleServiceException(message.getMessage());
        } else
            throw new ScheduleServiceException("The request might invalid or server is down");
    } catch (ScheduleServiceException e) {
        throw new ScheduleException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ScheduleServiceException(com.remswork.project.alice.web.service.exception.ScheduleServiceException) GenericType(javax.ws.rs.core.GenericType) Set(java.util.Set) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 9 with ScheduleException

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

the class ScheduleServiceImpl method getScheduleList.

@Override
public List<Schedule> getScheduleList() throws ScheduleException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.request().get();
        if (response.getStatus() == 200) {
            return (List<Schedule>) response.readEntity(new GenericType<List<Schedule>>() {
            });
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ScheduleServiceException(message.getMessage());
        } else
            throw new ScheduleServiceException("The request might invalid or server is down");
    } catch (ScheduleServiceException e) {
        throw new ScheduleException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ScheduleServiceException(com.remswork.project.alice.web.service.exception.ScheduleServiceException) GenericType(javax.ws.rs.core.GenericType) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

Example 10 with ScheduleException

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

the class ScheduleServiceImpl method getScheduleById.

@Override
public Schedule getScheduleById(long id) throws ScheduleException {
    try {
        StringBuilder uri = new StringBuilder();
        uri.append(targetProperties.getDomain());
        uri.append("/");
        uri.append(targetProperties.getBaseUri());
        uri.append("/");
        uri.append(payload);
        uri.append("/");
        uri.append(id);
        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(uri.toString());
        Response response = target.request().get();
        if (response.getStatus() == 200) {
            return (Schedule) response.readEntity(Schedule.class);
        } else if (response.getStatus() == 404) {
            Message message = (Message) response.readEntity(Message.class);
            throw new ScheduleServiceException(message.getMessage());
        } else
            throw new ScheduleServiceException("The request might invalid or server is down");
    } catch (ScheduleServiceException e) {
        throw new ScheduleException(e.getMessage());
    }
}
Also used : Response(javax.ws.rs.core.Response) ScheduleServiceException(com.remswork.project.alice.web.service.exception.ScheduleServiceException) Message(com.remswork.project.alice.model.support.Message) Schedule(com.remswork.project.alice.model.Schedule) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ScheduleException(com.remswork.project.alice.exception.ScheduleException)

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