Search in sources :

Example 11 with Attendance

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

the class AttendanceServiceImpl method getAttendanceList.

@Override
public List<Attendance> getAttendanceList() throws GradingFactorException {
    final List<Attendance> attendanceList = new ArrayList<>();
    try {
        return new AsyncTask<String, List<Attendance>, List<Attendance>>() {

            @Override
            protected List<Attendance> doInBackground(String... args) {
                try {
                    String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload);
                    URL url = new URL(link);
                    Gson gson = new Gson();
                    HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
                    httpURLConnection.setRequestMethod("GET");
                    httpURLConnection.setRequestProperty("Content-Type", "application/json");
                    httpURLConnection.setRequestProperty("Accept", "application/json");
                    httpURLConnection.connect();
                    if (httpURLConnection.getResponseCode() == 200) {
                        InputStream inputStream = httpURLConnection.getInputStream();
                        String jsonData = "";
                        int data;
                        while ((data = inputStream.read()) != -1) {
                            jsonData += (char) data;
                        }
                        JSONArray jsonArray = new JSONArray(jsonData);
                        for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
                            attendanceList.add(gson.fromJson(jsonArray.get(ctr).toString(), Attendance.class));
                        }
                        return attendanceList;
                    } else if (httpURLConnection.getResponseCode() == 404) {
                        InputStream inputStream = httpURLConnection.getInputStream();
                        String jsonData = "";
                        int data;
                        while ((data = inputStream.read()) != -1) {
                            jsonData += (char) data;
                        }
                        Message message = gson.fromJson(jsonData, Message.class);
                        Log.i("ServiceTAG", "Service : Attendance");
                        Log.i("ServiceTAG", "Status : " + message.getStatus());
                        Log.i("ServiceTAG", "Type : " + message.getType());
                        Log.i("ServiceTAG", "Message : " + message.getMessage());
                        return attendanceList;
                    } else
                        throw new GradingFactorException("Server Error");
                } catch (GradingFactorException e) {
                    e.printStackTrace();
                    return null;
                } catch (IOException e) {
                    e.printStackTrace();
                    return null;
                } catch (JSONException e) {
                    e.printStackTrace();
                    return null;
                }
            }
        }.execute((String) null).get();
    } catch (InterruptedException e) {
        e.printStackTrace();
        return null;
    } catch (ExecutionException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Attendance(com.remswork.project.alice.model.Attendance) Message(com.remswork.project.alice.model.support.Message) InputStream(java.io.InputStream) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException) ArrayList(java.util.ArrayList) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) JSONException(org.json.JSONException) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with Attendance

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

the class AttendanceResource method getAttendanceById.

@GET
@Path("{attendanceId}")
public Response getAttendanceById(@PathParam("attendanceId") long id) {
    try {
        AttendanceResourceLinks resourceLinks = new AttendanceResourceLinks(uriInfo);
        ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
        Attendance attendance = attendanceService.getAttendanceById(id);
        attendance.addLink(resourceLinks.self(id));
        if (attendance.get_class() != null)
            attendance.get_class().addLink(classResourceLinks.self(attendance.get_class().getId()));
        return Response.status(Response.Status.OK).entity(attendance).build();
    } catch (GradingFactorException e) {
        e.printStackTrace();
        Message message = new Message(404, "Not Found", e.getMessage());
        return Response.status(Response.Status.NOT_FOUND).entity(message).build();
    }
}
Also used : AttendanceResourceLinks(com.remswork.project.alice.resource.links.AttendanceResourceLinks) Attendance(com.remswork.project.alice.model.Attendance) ClassResourceLinks(com.remswork.project.alice.resource.links.ClassResourceLinks) Message(com.remswork.project.alice.model.support.Message) GradingFactorException(com.remswork.project.alice.exception.GradingFactorException)

Aggregations

Attendance (com.remswork.project.alice.model.Attendance)12 GradingFactorException (com.remswork.project.alice.exception.GradingFactorException)11 Message (com.remswork.project.alice.model.support.Message)8 AsyncTask (android.os.AsyncTask)4 Gson (com.google.gson.Gson)4 AttendanceResourceLinks (com.remswork.project.alice.resource.links.AttendanceResourceLinks)4 ClassResourceLinks (com.remswork.project.alice.resource.links.ClassResourceLinks)4 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 JSONArray (org.json.JSONArray)4 JSONException (org.json.JSONException)4 Student (com.remswork.project.alice.model.Student)3 Intent (android.content.Intent)2 Handler (android.os.Handler)2 CardView (android.support.v7.widget.CardView)2 RecyclerView (android.support.v7.widget.RecyclerView)2